ioctl(SIOCGIFCONF) not returning ethernet interfaces?

     int s = socket(AF_INET, SOCK_DGRAM, 0);  //s returned 6 in this case                 // find the number of interfaces              ifnum = 32;           struct ifconf ifc;           ifc.ifc_len = ifnum * sizeof (struct ifreq);           ifc.ifc_buf = (char*)malloc(ifc.ifc_len);             if (ioctl(s, SIOCGIFCONF, &ifc) < 0)           {                close(s);                         free(ifc.ifc_buf);                return false;           }  


using
struct ifreq* preq = &ifc.ifc_req[0];
struct ifreq* preq = &ifc.ifc_req[1];

etc

I was able to see only the first entry has name "lo0"

the second one's name has a null character and the sa_family etc are not populated.

I am curious this code works fine for Linux. I am making this project for the iphone, emulator build. Is the emulator target giving this result? I guess I would not know unless I make a OS X target and try. Also the debugger have some different variable names than the ones in my code. But I think it's because OS X has a header file that typedef a bunch of this stuff.

My goal is the find the interface of the ethernet card and find things like Mac address.


Thanks in advance.

MacBook Pro, Mac OS X (10.5.7)

Posted on Aug 12, 2009 3:42 PM

Reply
2 replies

Aug 12, 2009 5:26 PM in response to CaIphone

I found out the way I traverse the result is wrong, the sizes are not constant structures. In Linux samples I thought it was constant sized structures.
To traverse the buffer I must skip by
greater one of
sizeof(struct sockaddr);
or
current record's ifr addr.salen;


does anyone know what is the ifr_name to look for on the card.
sa_family should be 2 (AF_INET), but I don't see anything that says "eth0"

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

ioctl(SIOCGIFCONF) not returning ethernet interfaces?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.