ioctl(sock, SIOCGIFHWADDR, &ifr) fails with 1.7
Matthias Andree
matthias.andree@gmx.de
Thu Jun 18 15:34:00 GMT 2009
Am 15.06.2009, 11:22 Uhr, schrieb Frédéric Bron <frederic.bron@m4x.org>:
>> To fix your application, call either
>>
>> Â struct ifconf ifc;
>> Â ifc.ifc_len = sizeof (struct ifreq) * 32;
>> Â ifc.ifc_buf = malloc (ifc.ifc_len);
>> Â if (ioctl (fd, SIOCGIFCONF, &ifc))
>> Â Â /* Resize ifc_buf and retry */
>> Â else
>> Â Â {
>> Â Â Â struct ifreq *ifr = ifc.ifc_req;
>> Â Â Â struct ifreq ifr2;
>> Â Â Â for (int i = 0; i < ifc.ifc_len; i += sizeof (struct ifreq), ++ifr)
>> Â Â Â Â if (!ioctl (fd, SIOCGIFADDR, &ifr2))
>> Â Â Â Â Â /* Print result for that interface */
>> Â Â }
>
> Thanks, this works half! No need of ifr2, ifr is enough.
> I saw the name change: 1.5 gives eth0, eth1, eth2, lo and 1.7 gives
> {821C54BE-...}...
Careful - this isn't portable to newer BSDs, as there ifc_len may exceed
sizeof(struct ifreq).
getifaddrs() is probably the more portable solution here.
--
Matthias Andree
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list