Tiny Core Linux

Tiny Core Base => TCB Q&A Forum => Topic started by: booger on May 11, 2011, 09:10:04 AM

Title: ifconfig source code
Post by: booger on May 11, 2011, 09:10:04 AM
i am trying to track down the tinycore ifconfig source code.  i found it in the busybox pile, but i am convinced it is not what is in tinycore's shell because it does not output anything to stdout. i am going to continue my search but i was hoping someone could make it a shorter adventure.  thanks.

bte, please provide the exact path in the download source /tinycorelinux/3.x/release/.

thanks again.
Title: Re: ifconfig source code
Post by: curaga on May 11, 2011, 10:38:47 AM
Quote
ls -lh ifconfig
lrwxrwxrwx 1 root root 14 2010-08-26 18:17 ifconfig -> ../bin/busybox
Title: Re: ifconfig source code
Post by: Rich on May 11, 2011, 01:23:44 PM
Hi booger
Busybox achieves it's small code size by sharing code between it's many commands. Ifconfig may
be using one of them to send text to stdout. Possibly  echo  or  printf?
Title: Re: ifconfig source code
Post by: booger on May 11, 2011, 01:48:43 PM
thanks for the replies.

i am looking for ifconfig.c

i found one in busybox. however it appears to only apply settings e.g. "ifconfig eth0 down" but does note output much. 

i could not find it anywhere else in the source code (kernel, busybox, etc).

i found a freebsd version but it is sufficiently different porting it became a challenge.

Title: Re: ifconfig source code
Post by: bmarkus on May 11, 2011, 02:04:32 PM
Using 'Provides' function in AppBrowser inetutils.tcz extension is listed as one provides ifconfig binary.

Info file of inetconfig.tcz says source code is available at http://www.gnu.org/software/inetutils/

On this page you find download page http://ftp.gnu.org/gnu/inetutils/

Now you have the source code of the original GNU. Takes one minute :)


Title: Re: ifconfig source code
Post by: gutmensch on May 11, 2011, 03:05:56 PM
@booger: It would be more senseful to tell us what you are trying to achieve and we may be able to help you out.

ifconfig does exactly what it's supposed to do, also it *does* print to stdout (ifconfig 1>tmpfile ; cat tmpfile). If you want to see if e.g. "ifconfig eth0 up" was successful, then check return parameter $?. also be sure to run ifconfig -a to get all devices listed, not only the ones with addresses. Right now I honestly can't imagine any output that you would have to hard code yourself, which hasn't already been done by somebody or which cannot be generated without changing the code.
Title: Re: ifconfig source code
Post by: booger on May 12, 2011, 11:49:13 AM
thanks for the answers.

i wanted in c to get the total bytes sent/rcvd on the nics without spawning ifconfig|grep|parse.

fwiw, in http://distro.ibiblio.org/tinycorelinux/3.x/release/src/busybox-1.18.3.tar.bz2 it has /networking/ifconfig.c

which has the comment block below. i looked at code and there is no output.  so i was confused where tinycore got ifconfig from.  more fwiw, as you know one does not have to install inetutils to get ifconfig.

thanks again. the time and help are appreciated.

/* vi: set sw=4 ts=4: */
/* ifconfig
 *
 * Similar to the standard Unix ifconfig, but with only the necessary
 * parts for AF_INET, and without any printing of if info (for now).
 *
 * Bjorn Wesen, Axis Communications AB
 *
 *
 * Authors of the original ifconfig was:
 *              Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
 *
 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
 */
Title: Re: ifconfig source code
Post by: Rich on May 12, 2011, 12:08:54 PM
Hi booger
There are files under /proc/net/ that contain the information you seek. Try looking in  dev  or  netstat.
Title: Re: ifconfig source code
Post by: bmarkus on May 12, 2011, 12:10:48 PM
Hi booger
There are files under /proc/net/ that contain the information you seek. Try looking in  dev  or  netstat.


Studying iptraf source code may help.
Title: Re: ifconfig source code
Post by: curaga on May 12, 2011, 01:45:49 PM
which has the comment block below. i looked at code and there is no output.  so i was confused where tinycore got ifconfig from.  more fwiw, as you know one does not have to install inetutils to get ifconfig.

thanks again. the time and help are appreciated.

/* vi: set sw=4 ts=4: */
/* ifconfig
 *
 * Similar to the standard Unix ifconfig, but with only the necessary
 * parts for AF_INET, and without any printing of if info (for now).
 *
 * Bjorn Wesen, Axis Communications AB
 *
 *
 * Authors of the original ifconfig was:
 *              Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
 *
 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
 */

The comment is wrong, then; I showed above how our ifconfig comes from busybox. Even if it doesn't output directly itself, I find the code fairly easy to follow:
Quote
return display_interfaces(argv[0] /* can be NULL */);