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)