Accessing ifunit/ifaddr_byindex

Brooks Davis brooks at one-eyed-alien.net
Thu Mar 17 09:07:47 PST 2005


On Thu, Mar 17, 2005 at 02:15:31PM +0100, Patrik Arlos wrote:
> Hi,
> 
> I'm writing a small program that tries to read out some parameters from a
> ifnet structure. The code used ifunit() to obtain the ifnet structure for
> the interface in question and later on it used ifaddr_byindex. The code
> compiles nicely, but fails miserably to link, with undefined references to
> the two mentioned functions. I've googled quite a lot (but obviously at the
> wrong places), but can't find what library to include.  I've included the
> code below, the compile command used is the following; 'gcc -o ifList.bsd
> -lpcap ifList.c'. The system is a FreeBSD-5.3-Release (?). 
> 
> If there are any other ways of finding the hw address and MTU for an
> Interface please let me know.

ifunit() and ifaddr_byindex() are both kernel functions and may not
be used in userland.  In fact, no program should access struct ifnet
directly from userland (though a few badly behaved ones do).  To get the
MTU, check the code if ifconfig that does it.  It's not all that hard,
though ifconfig obfuscates the process a fair bit.

-- Brooks

-- 
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-net/attachments/20050317/5cd3b39c/attachment.bin


More information about the freebsd-net mailing list