How to read ifconfig in FreeBSD..Help plss

Yar Tikhiy yar at comp.chem.msu.su
Thu Nov 16 08:30:43 UTC 2006


On Tue, Nov 14, 2006 at 11:36:12AM -0800, subba wrote:
> 
> I am not sure about 'to read the source and copy the parts into your
> application'. Can you please elaborate?. When you said reading the source,
> does it mean that pipe the 'ifconfig' to a file and read that file ... like
>  % ifconfig > somefile.txt
> and read somefile.txt and get the ip, netmask and others.?
> If this is the case, how can i pipe(C program) when the user logs in...i.e
> when the user logs in, console menu should be displayed with current
> IP,netmask etc. I am not sure if i am in the right direction. I'd appreciate
> your help.

You're lucky this time:  In fact you don't need to read the source
files of ifconfig, or to know what they are in the first place, to
be able to obtain the network interface configuration from a C
program. ;-)

There is a handy function in the FreeBSD C library named getifaddrs()
that will extract the data from the kernel and put it in a list of
simple structures.  Using it is much easier than parsing output
from ifconfig.  Just see the getifaddrs(3) manpage.

However, note that this mailing list is inappropriate for such a
discussion.  Please post your further questions on this topic to
freebsd-questions.

-- 
Yar


More information about the freebsd-rc mailing list