Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get number of attached network devices

6 views
Skip to first unread message

kubus3561

unread,
Jan 21, 2005, 3:59:15 AM1/21/05
to
Hello,

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.

Kasper Dupont

unread,
Jan 21, 2005, 4:17:47 AM1/21/05
to
kubus3561 wrote:
>
> 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?

Maybe you can get a bit of inspiration here:

http://www.daimi.au.dk/~kasperd/comp.os.linux.development.faq.html#IP

--
Kasper Dupont

kubus3561

unread,
Jan 21, 2005, 5:12:50 AM1/21/05
to
That helped a lot. It works now. *whoopie*

Thanks for the great help. The solution was almost there, but I
couldn't see it.

A. Martinez

0 new messages