简体   繁体   中英

How to get IP addresses of all interfaces on OS X using C

I am porting code from linux to OS X where I am getting these errors:

src/proxy_linux.c:784: error: 'SIOCGIFHWADDR' undeclared (first use in this function)
src/proxy_linux.c:784: error: (Each undeclared identifier is reported only once
src/proxy_linux.c:784: error: for each function it appears in.)
src/proxy_linux.c:788: error: 'struct ifreq' has no member named 'ifr_hwaddr'

I am using Mac OS X 10.7.5 (11G63) ) as development system.

SIOCGIFHWADDR is not supported on OS X and I am not able to find any credible source which can list out the ip addresses and MAC addresses of all interfaces. The only one I found on apple developer site uses "IOKit", which is also not backward compatible. Any help in this regard will be appreciated

If Sandbox or App Store is not involved you can parse the output of ifconfig -a yourself and extract the addresses. If so, well, you are out of luck as Apple won't allow this for privacy reasons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM