LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Albert Cahalan <albert@users.sf.net>
To: linux-kernel mailing list <linux-kernel@vger.kernel.org>
Cc: viro@parcelfarce.linux.theplanet.co.uk, joshk@triplehelix.org
Subject: Re: consistent ioctl for getting all net interfaces?
Date: 23 May 2004 08:35:17 -0400	[thread overview]
Message-ID: <1085315717.955.920.camel@cube> (raw)

Viro cluelessly writes:
On Sat, May 22, 2004 at 09:28:28PM -0700, Joshua Kwan wrote:
 
>> I'm interested in not having to parse /proc/net/dev to get
>> a list of all available (not necessarily even up) interfaces
>> on the system. I investigated the ioctl SIOCGIFCONF, but it
>> seems to behave differently on 2.4 and 2.6 series kernels,
>> e.g. sometimes it won't return all interfaces.
>>
>> Is there some end-all ioctl that does what I want, or am
>> I forever doomed to process /proc/net/dev (in C, no less..)?
>
> ASCII is tough, let's go shopping?
>
>  char name[17];
>  FILE *in = fopen("/proc/net/dev", "r");
>  if (!in)
>   die("can't open");
>  fscanf(in, "%*[^\n]\n%*[^\n]");  /* skip two lines */
>  while (fscanf(in, " %16[^:]:%*[^\n]", name) == 1)
>   do_whatever_you_want(name);
>
> That you are calling "forever doomed"?  Wimp...

What makes you think you got that right? Do you have a
specification for the grammar? Let's look at an example
of /proc/net/dev, and I'll use my extensive /proc-parsing
experience to count your errors. Here is a sample:

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  eth0:3077476015 33231846    0    0    0     0          0         0 101565261  774586    0    0    0     0       0          0
    lo:    1360      24    0    0    0     0          0         0     1360      24    0    0    0     0       0          0
  tap0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  eth1:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  eth2:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

Excuse me while I vomit.

Let's start with the device names. Users can change
them at will, and some driver authors aren't normal.
So, in C notation, a name could be "x1: 1 2 3\n".

It doesn't even need to that evil to screw up your
wimpy parser. A simple "av6:3" would do nicely.
Think it won't happen? Sorry, but it does and will.
This is the nature of /proc crap.

Now we get to format changes. Don't you think the
above is kind of ugly? I sure do. I'm not crazy
enough to touch the formatting, but that readable
ASCII is a temptation for many. Just look at the
history of /proc/cpuinfo, which long ago looked a
bit more like the above in terms of ':' placement.
Also, it's foolish to rely on that leading space.

Here is what my data might look like in a few years:

Iface |   Receive                                                |  Transmit
name  |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
eth0  :3077476015 33231846    0    0    0     0          0         0 101565261  774586    0    0    0     0       0          0
lo    :    1360      24    0    0    0     0          0         0     1360      24    0    0    0     0       0          0
tap0  :       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
eth1  :       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
eth2  :       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

Subtle, isn't it? Your parser broke.

(then there is performance, or lack of it...)



             reply	other threads:[~2004-05-23 14:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-23 12:35 Albert Cahalan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-05-23  4:28 Joshua Kwan
2004-05-23  5:35 ` viro
2004-05-23  5:57   ` Joshua Kwan
2004-05-23  6:05     ` viro
2004-05-23 15:20 ` Tigran Aivazian
2004-05-23 15:25   ` Tigran Aivazian
2004-05-23 15:29   ` Joshua Kwan
2004-05-30 20:25 ` Olaf Hering

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1085315717.955.920.camel@cube \
    --to=albert@users.sf.net \
    --cc=joshk@triplehelix.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    --subject='Re: consistent ioctl for getting all net interfaces?' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).