I'm trying to get the number of attached network devices by calling
ioctl. I found SIOCGIFCOUNT as argument for this function. In
<bits/ioctls.h> there's following entry:
#define SIOCGIFCOUNT 0x8938 /* get number of devices */
I think that should work, but ioctl always returns 0.
my code is as follows:
int number = 0;
int ret = 0;
ret = ioctl(fd, SIOCGIFCOUNT, &number);
okay, I tried to use SIOCGIFCONF as argument to ioctl and the following
code:
struct ifconf ifc;
ioctl(fd, SIOCGIFCONF, &ifc);
ifc.ifc_len contains now 64. Is that the correct number of interfaces
or is there any other way to get the number of network devices? I don't
want to get that information through the /proc filesystem or by parsing
the output produced by ifconfig, which would make my program really
dependant on the output formats of that methods.
Thanks in advance for anyone that answers this question.
Maybe you can get a bit of inspiration here:
http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#IP
--
Kasper Dupont
Thanks for the great help. The solution was almost there, but I
couldn't see it.
A. Martinez