This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
[Bug libc/160] if_nameindex has inconsistent behavior because of __opensock
- From: "v13 at priest dot com" <sourceware-bugzilla at sources dot redhat dot com>
- To: glibc-bugs at sources dot redhat dot com
- Date: 7 Aug 2004 19:31:28 -0000
- Subject: [Bug libc/160] if_nameindex has inconsistent behavior because of __opensock
- References: <20040513235527.160.joshk@triplehelix.org>
- Reply-to: sourceware-bugzilla at sources dot redhat dot com
------- Additional Comments From v13 at priest dot com 2004-08-07 19:31 -------
I've the same problem using 2.6.7
As far as i can see, if_nameindex uses SIOCGIFCONF to get a list of the
interfaces and after that it uses SIOCGIFINDEX for each one of them.
After taking a look in kernel sources I found that the ioctl returns one entry
per interface configuration. Thus, it will return all configured interfaces
(like eth0, eth0:1 etc) but not all interfaces.
To test it just create a program that calls if_nameindex to get a list of all
interfaces (lets say /tmp/i) and do this:
(supposed that loopback has 127.0.0.1 configured):
Run /tmp/i and you'll see loopback interface.
# ifconfig lo 0.0.0.0
Run /tmp/i and you won't see the loopback interface
I believe you can see how that is expected behaviour (if I understand it
correctly) at: /usr/src/linux/net/core/dev.h lines 2003-2005 of 2.6.7 (+imq
patch) kernel where there is:
for (dev = dev_base; dev; dev = dev->next) {
for (i = 0; i < NPROTO; i++) {
if (gifconf_list[i]) {
int done;
if (!pos)
done = gifconf_list[i](dev, NULL, 0);
else
done = gifconf_list[i](dev, pos + total,len - total);
if (done < 0)
return -EFAULT;
total += done;
}
}
}
I believe that interfaces without a configured address will not have a
gifconf_list entry unless their net driver has its own function of reporting
device addresses.
This way it is impossible to discover interfaces like imq0.
On my system, if_nameindex returns lo, eth0, eth0:1 and the netlink interface
returns lo, imq0, imq1, irlan0, eth0, sit0
It seems that the ifconfig (from net-tools) does what if_nameindex wanted to
do by reading /proc/net/dev and then calling the SIOCGIFCONF ioctl and when it
encounters two interfaces which match (it matches eth0 to eth0 *and* to
eth0:1) then it creates a new list entry after the existing one, so it returns
(with ifconfig -a) eth0, eth0:1, imq0, imq1, irlan0, lo, sit0
Hope that helped...
--
http://sources.redhat.com/bugzilla/show_bug.cgi?id=160
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.