[lkml]   [1996]   [Jun]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: SIOCGIFADDR bug?
Zachary Roger Amsden (amsden+@andrew.cmu.EDU) wrote:
: Excerpts from internet.computing.linux-kernel: 18-Jun-96 Re: SIOCGIFADDR
: bug? by
: >
: > Did you specify disired address family?
: > You program will get hardware ethernet address.
: > If you want internet address, write ifr.ifr_addr.sa_family = AF_INET.
: >
: >
: I meant internet address. I should get the internet address because I
: opened the connection to the net kernel with AF_INET.

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.

 \ /
  Last update: 2005-03-22 13:37    [W:0.020 / U:0.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site