Alas, it is not case. :-)
: I found out a
: very strange thing about this bug?. If I call SIOCGIFADDR twice, I get
: the correct address. I'll have to double check the address I was
: getting the first time and see if it matches the ethernet (not internet)
: address. I could be wrong, but I heard that you don't even need to call
: SIOCGIFADDR twice, just call it after any other IOCTL call and it will
: work. Strange, huh?
Looks strange like almost any obscure bug, but the explanation is always simple
as tomatoes :-)
When you call SIOCGIFADDR with ifr.ifr_addr.sa_family == 0 (AF_UNSPEC),
it fills ifr with hardware ethernet address and set ifr.ifr_addr.sa_family
to ARPHRD_ETHER (=1). Any other SIOCGIF*ADDR fills it with correct value
(AF_INET). Apparently you forgot to clear ifr before calling SIOCGIFADDR
second time (another error 8)), so that you occasionally get correct answer.
Note that double SIOCGIFADDR "works" only because Linux does not
support (yet!) multiple address families per device. Be ready that
your powerful "technique" of getting addresses will stop to work
at any moment. :-)
Alexey Kuznetsov.