LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* consistent ioctl for getting all net interfaces?
@ 2004-05-23  4:28 Joshua Kwan
  2004-05-23  5:35 ` viro
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Joshua Kwan @ 2004-05-23  4:28 UTC (permalink / raw)
  To: linux-kernel

Hi,

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..)?

Please CC me on replies, I don't read this list very often any more.

Thanks,

-- 
Joshua Kwan



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: consistent ioctl for getting all net interfaces?
@ 2004-05-23 12:35 Albert Cahalan
  0 siblings, 0 replies; 9+ messages in thread
From: Albert Cahalan @ 2004-05-23 12:35 UTC (permalink / raw)
  To: linux-kernel mailing list; +Cc: viro, joshk

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...)



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-05-30 20:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-23  4:28 consistent ioctl for getting all net interfaces? 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
2004-05-23 12:35 Albert Cahalan

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).