How to read ifconfig in FreeBSD..Help plss

Brooks Davis brooks at one-eyed-alien.net
Tue Nov 14 20:44:26 UTC 2006


[Please don't top-post on FreeBSD mailing lists.]

On Tue, Nov 14, 2006 at 11:36:12AM -0800, subba wrote:
> 
> 
> Thanks Brooks,
> 
> 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.

Since you are writing a C program, just do what ifconfig does
rather than trying to parse it's output.  I.e. copy what you need from
src/sbin/ifconfig/*.c (retaining appropriate license and copyright
statements).

-- Brooks

> 
> Thanks,
> Subba
> 
> 
> Brooks Davis wrote:
> > 
> > On Tue, Nov 14, 2006 at 10:00:18AM -0800, subba wrote:
> >> 
> >> Hi,
> >> 
> >> I have to write console menu set up, where user can change the IP ,
> >> netmask,gateway settings etc.
> >> To Start with i need to read 'ifconfig' and get the 'ip' and 'netmask'
> >> and
> >> store it in a file and read the file to get the output. Can somebody help
> >> me
> >> in reading the IP and others from ifconfig...
> >> I am trying to use
> >> char *cmd[] = { "ifconfig","-a",(char *)0 }
> >> execv("/sbin/ifconfig,cmd);
> >> 
> >> If there is a better solution to have the console set up, I would love to
> >> know it...I'd appreciate your help.
> > 
> > The better solution by far would be to read the source and copy the
> > parts you need into your application rather than trying to parse
> > ifconfig output in C.
> > 
> > -- Brooks
> > 
> >  
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/How-to-read-ifconfig-in-FreeBSD..Help-plss-tf2631184.html#a7344729
> Sent from the freebsd-rc mailing list archive at Nabble.com.
> 
> _______________________________________________
> freebsd-rc at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-rc
> To unsubscribe, send any mail to "freebsd-rc-unsubscribe at freebsd.org"
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-rc/attachments/20061114/8b981e75/attachment.pgp


More information about the freebsd-rc mailing list