Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Dec 1994 15:27:53 +1100 (EST)
From:      David Dawes <dawes@physics.su.oz.au>
To:        wpaul@skynet.ctr.columbia.edu (Wankle Rotary Engine)
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: ifconfig -a
Message-ID:  <199412300427.AA26566@physics.su.OZ.AU>
In-Reply-To: <199412300024.TAA03220@skynet.ctr.columbia.edu> from "Wankle Rotary Engine" at Dec 29, 94 07:24:16 pm

next in thread | previous in thread | raw e-mail | index | archive | help
>There's one strange thing I discovered while implimenting the -a option:
>I used SIOCGIFCONF to figure out what interfaces are present in the system,
>but for some reason the active interfaces turn up twice. That is, without
>a little bit of extra fiddling, ed0 and lo0 (from the output above) would
>occur twice. With SIOCGIFCONF you get back an array with a member for each
>configured interface, but there seem to be two members for ed0 and lo0.
>If, for example, I assign a dummy address to sl0, then sl0 pops up twice
>as well. I found a quick though inelegant test to jump over the extra
>entries, but I'm confused as to why SIOCGIFCONF behaves this way.

You get an entry for each configured address type an interface has.
All have an AF_LINK entry.  Those with an IP address also have an
AF_INET entry (the sa.family field).

>Oh, I have a question for those who might know: the data returned by
>ioctl(sock,SIOCGIFCONF,&ifconf) needs to be placed in a buffer, and you
>have to allocate enough space to hold the data for all interfaces. I
>arbitrarily assumed that there wouldn't be more than 20 interfaces, thus
>the buffer space allocated is (20 * struct ifreq). That's a silly thing
>to assume though... anybody know what the official maximum number of
>interfaces is? Is there a MAXINTERFACES defined somewhere?

Also keep in mind that the length of the returned data can be longer than
sizeof(struct ifreq) because of the variable size of the sockaddr entry.
The size of the sockaddr is given in its sa_len field.

David



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199412300427.AA26566>