lkml.org 
[lkml]   [2004]   [May]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: consistent ioctl for getting all net interfaces?
On Sat, May 22, 2004 at 09:28:28PM -0700, Joshua Kwan wrote:
> 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..)?

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...
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:03    [W:1.019 / U:0.208 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site