WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: ifconfig source code  (Read 8437 times)

Offline booger

  • Newbie
  • *
  • Posts: 3
ifconfig source code
« on: May 11, 2011, 06: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.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10965
Re: ifconfig source code
« Reply #1 on: May 11, 2011, 07:38:47 AM »
Quote
ls -lh ifconfig
lrwxrwxrwx 1 root root 14 2010-08-26 18:17 ifconfig -> ../bin/busybox
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11243
Re: ifconfig source code
« Reply #2 on: May 11, 2011, 10:23:44 AM »
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?

Offline booger

  • Newbie
  • *
  • Posts: 3
Re: ifconfig source code
« Reply #3 on: May 11, 2011, 10:48:43 AM »
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.


Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: ifconfig source code
« Reply #4 on: May 11, 2011, 11:04:32 AM »
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 :)


Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gutmensch

  • Administrator
  • Hero Member
  • *****
  • Posts: 605
  • I can make it disappear, have no fear!
    • remembrance blog
Re: ifconfig source code
« Reply #5 on: May 11, 2011, 12: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.
If I seem unduly clear to you, you must have misunderstood what I said. (Alan Greenspan)

Offline booger

  • Newbie
  • *
  • Posts: 3
Re: ifconfig source code
« Reply #6 on: May 12, 2011, 08: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.
 */

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11243
Re: ifconfig source code
« Reply #7 on: May 12, 2011, 09:08:54 AM »
Hi booger
There are files under /proc/net/ that contain the information you seek. Try looking in  dev  or  netstat.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: ifconfig source code
« Reply #8 on: May 12, 2011, 09:10:48 AM »
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.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10965
Re: ifconfig source code
« Reply #9 on: May 12, 2011, 10:45:49 AM »
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 */);
The only barriers that can stop you are the ones you create yourself.