Date: Thu, 16 Nov 2006 11:30:32 +0300 From: Yar Tikhiy <yar@comp.chem.msu.su> To: subba <subba@t8design.com> Cc: freebsd-rc@freebsd.org Subject: Re: How to read ifconfig in FreeBSD..Help plss Message-ID: <20061116083032.GA37133@comp.chem.msu.su> In-Reply-To: <7344729.post@talk.nabble.com> References: <7342892.post@talk.nabble.com> <20061114181204.GA51226@lor.one-eyed-alien.net> <7344729.post@talk.nabble.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061116083032.GA37133>