<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Enumerating Network Interfaces on Linux</title>
	<atom:link href="http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html</link>
	<description>Maker of Finest Quality Digital Things</description>
	<lastBuildDate>Wed, 20 Apr 2011 06:42:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: Prashant</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-18613</link>
		<dc:creator>Prashant</dc:creator>
		<pubDate>Sun, 10 Apr 2011 07:00:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-18613</guid>
		<description>Hi,
Is it possible to get additional info like name, description and vendor of an ethernet adapter?

Cheers
Prashant</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Is it possible to get additional info like name, description and vendor of an ethernet adapter?</p>
<p>Cheers<br />
Prashant</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: little_helper</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-18231</link>
		<dc:creator>little_helper</dc:creator>
		<pubDate>Wed, 23 Mar 2011 04:07:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-18231</guid>
		<description>Hello,

Just a quick thread bump as I encountered this site while trying to do similar thing. The glibc function getifaddrs() seems to be the ideal solution to use. It&#039;s not POSIX but it originated from BSD and seems to be implemented on Linux, hence reasonably cross-platform. Good luck!</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>Just a quick thread bump as I encountered this site while trying to do similar thing. The glibc function getifaddrs() seems to be the ideal solution to use. It&#8217;s not POSIX but it originated from BSD and seems to be implemented on Linux, hence reasonably cross-platform. Good luck!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dark_age</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-15929</link>
		<dc:creator>dark_age</dc:creator>
		<pubDate>Fri, 29 Oct 2010 14:15:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-15929</guid>
		<description>Hello
Thank you for giving this example, it may be useful to be.
Thank you people for improvements.

If I may, I&#039;d like to give another way to get such kind of info: beside &quot;ifconfig -a&quot; , &quot;/proc/net/dev&quot; and ioctl, there are NETLINK sockets.
I don&#039;t know how different it is from ioctl, but it seems interesting, many information can be gathered using that kind of IPC, and it seems to work either on request/response or async &quot;events&quot;/msg schemes.
A overview can be found here : http://www.linuxjournal.com/article/7356.
Some example at the end of the man page : http://linux.die.net/man/7/netlink</description>
		<content:encoded><![CDATA[<p>Hello<br />
Thank you for giving this example, it may be useful to be.<br />
Thank you people for improvements.</p>
<p>If I may, I&#8217;d like to give another way to get such kind of info: beside &#8220;ifconfig -a&#8221; , &#8220;/proc/net/dev&#8221; and ioctl, there are NETLINK sockets.<br />
I don&#8217;t know how different it is from ioctl, but it seems interesting, many information can be gathered using that kind of IPC, and it seems to work either on request/response or async &#8220;events&#8221;/msg schemes.<br />
A overview can be found here : <a href="http://www.linuxjournal.com/article/7356" rel="nofollow">http://www.linuxjournal.com/article/7356</a>.<br />
Some example at the end of the man page : <a href="http://linux.die.net/man/7/netlink" rel="nofollow">http://linux.die.net/man/7/netlink</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-15368</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Wed, 15 Sep 2010 17:38:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-15368</guid>
		<description>Looks like there were characters your blog doesn&#039;t like in my last comment:

After the if(ioctl(sck, SIOCGIFHWADDR, item) &lt; 0) { ... } block

                printf(&quot;, MAC %02x:%02x:%02x:%02x:%02x:%02x&quot;,
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[0],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[1],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[2],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[3],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[4],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[5]);</description>
		<content:encoded><![CDATA[<p>Looks like there were characters your blog doesn&#8217;t like in my last comment:</p>
<p>After the if(ioctl(sck, SIOCGIFHWADDR, item) &lt; 0) { &#8230; } block</p>
<p>                printf(&#8220;, MAC %02x:%02x:%02x:%02x:%02x:%02x&#8221;,<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[0],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[1],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[2],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[3],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[4],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[5]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-15367</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Wed, 15 Sep 2010 17:35:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-15367</guid>
		<description>Hi Eric,

Great example!

To get your program to print the MAC address, add the following after the if(ioctl(sck, SIOCGIFHWADDR, item) ifr_hwaddr.sa_data)[0],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[1],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[2],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[3],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[4],
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[5]);</description>
		<content:encoded><![CDATA[<p>Hi Eric,</p>
<p>Great example!</p>
<p>To get your program to print the MAC address, add the following after the if(ioctl(sck, SIOCGIFHWADDR, item) ifr_hwaddr.sa_data)[0],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[1],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[2],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[3],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[4],<br />
                        (int)((unsigned char *)item-&gt;ifr_hwaddr.sa_data)[5]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jackson</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14983</link>
		<dc:creator>Jackson</dc:creator>
		<pubDate>Sat, 07 Aug 2010 02:00:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14983</guid>
		<description>Very cool :)

Is there a possibility to combine comment #11 and your code so that we can get all interfaces and their associated addresses if they exist?</description>
		<content:encoded><![CDATA[<p>Very cool :)</p>
<p>Is there a possibility to combine comment #11 and your code so that we can get all interfaces and their associated addresses if they exist?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14389</link>
		<dc:creator>adam</dc:creator>
		<pubDate>Sun, 17 Jan 2010 22:05:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14389</guid>
		<description>Thanks Eric, it just so happens I was thinking about broadcast addresses today. I&#039;ve added your code to the example in the article.</description>
		<content:encoded><![CDATA[<p>Thanks Eric, it just so happens I was thinking about broadcast addresses today. I&#8217;ve added your code to the example in the article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14388</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Fri, 15 Jan 2010 16:56:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14388</guid>
		<description>Hi,
Great sample, thanks! Thought some of you might be interested in how to get broadcast address:
    if (ioctl(sock, SIOCGIFBRDADDR, &amp;ifr[nInterface]) &gt;= 0)   // rectify with &#039;item&#039; as above, as this chunk of code comes from my application
    	strcpy(szBroadcast, inet_ntoa(((struct sockaddr_in *)&amp;ifr[nInterface].ifr_broadaddr)-&gt;sin_addr));
So, to reply the  previous question: to get the subnet mask, I guess you&#039;d use the same ioctl call, passing SIOCGIFNETMASK as 2nd argument.
One note: some data returned by ioctl in the buffer (3rd argument) are part of a union, so one ioctl call might overwrite data of a previous call. So, make sure you retrieve the data you need, straight after each ioctl call
Cheers,
Eric</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Great sample, thanks! Thought some of you might be interested in how to get broadcast address:<br />
    if (ioctl(sock, SIOCGIFBRDADDR, &amp;ifr[nInterface]) &gt;= 0)   // rectify with &#8216;item&#8217; as above, as this chunk of code comes from my application<br />
    	strcpy(szBroadcast, inet_ntoa(((struct sockaddr_in *)&amp;ifr[nInterface].ifr_broadaddr)-&gt;sin_addr));<br />
So, to reply the  previous question: to get the subnet mask, I guess you&#8217;d use the same ioctl call, passing SIOCGIFNETMASK as 2nd argument.<br />
One note: some data returned by ioctl in the buffer (3rd argument) are part of a union, so one ioctl call might overwrite data of a previous call. So, make sure you retrieve the data you need, straight after each ioctl call<br />
Cheers,<br />
Eric</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lieven</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14313</link>
		<dc:creator>Lieven</dc:creator>
		<pubDate>Mon, 11 May 2009 19:09:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14313</guid>
		<description>Hi,

Is there a quick way, with these or similar methods to obtain the subnet mask of these interfaces ?

Thanks.
Lieven</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Is there a quick way, with these or similar methods to obtain the subnet mask of these interfaces ?</p>
<p>Thanks.<br />
Lieven</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Risi</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14256</link>
		<dc:creator>Adam Risi</dc:creator>
		<pubDate>Tue, 17 Feb 2009 06:05:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14256</guid>
		<description>Hi all,
I have written a fix for this code to allow it to use IPv6 interfaces, and to eliminate the segfault bug some users were experiencing. The new source can be found at &lt;a href=&quot;http://www.adamrisi.com/?p=84&quot; rel=&quot;nofollow&quot;&gt;my website&lt;/a&gt;.

HTH,
Adam Risi</description>
		<content:encoded><![CDATA[<p>Hi all,<br />
I have written a fix for this code to allow it to use IPv6 interfaces, and to eliminate the segfault bug some users were experiencing. The new source can be found at <a href="http://www.adamrisi.com/?p=84" rel="nofollow">my website</a>.</p>
<p>HTH,<br />
Adam Risi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prameeth Sreesha</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14161</link>
		<dc:creator>Prameeth Sreesha</dc:creator>
		<pubDate>Wed, 05 Nov 2008 06:42:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14161</guid>
		<description>In response to:
===========================================
Comment by Yiannis Tsiouris — 27 November 2007 @ 1:15 am

I have Arch Linux and the compiler i use is gcc 4.2.2. And this is the output:

[yiannis@main Programs]$ gcc -o interface interface.c
[yiannis@main Programs]$ ./interface
Segmentation fault
============================================

I came across the same problem too.. In my case, it was the query for the MAC Address field for a loopback device, that was the culprit. In the code, the lines below:

printf(&quot;%s: IP %s\n&quot;,
                       item-&gt;ifr_name,
                       inet_ntoa(((struct sockaddr_in *)&amp;item-&gt;ifr_addr)-&gt;sin_addr));


printf(&quot;, MAC %s\\n&quot;, ether_ntoa((struct ether_addr *)item-&gt;ifr_hwaddr.sa_data));

were the culprits in causing the segfaults. Since loopback device does not have a MAC value associated, it might have led to ifr_hwaddr being NULL. So the access to the sa_data might have led to the Segfault. I still need to go through the 2 structures though.

Commenting the above 2 printf&#039;s and just printing item-&gt;ifr_name works fine.

Regards,
Prameeth</description>
		<content:encoded><![CDATA[<p>In response to:<br />
===========================================<br />
Comment by Yiannis Tsiouris — 27 November 2007 @ 1:15 am</p>
<p>I have Arch Linux and the compiler i use is gcc 4.2.2. And this is the output:</p>
<p>[yiannis@main Programs]$ gcc -o interface interface.c<br />
[yiannis@main Programs]$ ./interface<br />
Segmentation fault<br />
============================================</p>
<p>I came across the same problem too.. In my case, it was the query for the MAC Address field for a loopback device, that was the culprit. In the code, the lines below:</p>
<p>printf(&#8220;%s: IP %s\n&#8221;,<br />
                       item-&gt;ifr_name,<br />
                       inet_ntoa(((struct sockaddr_in *)&amp;item-&gt;ifr_addr)-&gt;sin_addr));</p>
<p>printf(&#8220;, MAC %s\\n&#8221;, ether_ntoa((struct ether_addr *)item-&gt;ifr_hwaddr.sa_data));</p>
<p>were the culprits in causing the segfaults. Since loopback device does not have a MAC value associated, it might have led to ifr_hwaddr being NULL. So the access to the sa_data might have led to the Segfault. I still need to go through the 2 structures though.</p>
<p>Commenting the above 2 printf&#8217;s and just printing item-&gt;ifr_name works fine.</p>
<p>Regards,<br />
Prameeth</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erb</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14094</link>
		<dc:creator>Erb</dc:creator>
		<pubDate>Wed, 27 Aug 2008 16:55:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14094</guid>
		<description>Hmm that comment got messed up.  Should be
#include &lt;arpa/inet.h&gt;</description>
		<content:encoded><![CDATA[<p>Hmm that comment got messed up.  Should be<br />
#include &lt;arpa/inet.h&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erb</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14093</link>
		<dc:creator>Erb</dc:creator>
		<pubDate>Wed, 27 Aug 2008 16:54:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14093</guid>
		<description>to fix the seg fault, try #include 

also, that first printf should have a \n</description>
		<content:encoded><![CDATA[<p>to fix the seg fault, try #include </p>
<p>also, that first printf should have a \n</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14072</link>
		<dc:creator>adam</dc:creator>
		<pubDate>Sat, 26 Jul 2008 12:08:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14072</guid>
		<description>Try the code mentioned in comment #11 above.</description>
		<content:encoded><![CDATA[<p>Try the code mentioned in comment #11 above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elessedil</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14071</link>
		<dc:creator>Elessedil</dc:creator>
		<pubDate>Fri, 25 Jul 2008 15:56:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14071</guid>
		<description>just figured that out. if no ip is assigned the interfaces are not found.
is there a possibility to get the list of interfaces even if they are not connected?</description>
		<content:encoded><![CDATA[<p>just figured that out. if no ip is assigned the interfaces are not found.<br />
is there a possibility to get the list of interfaces even if they are not connected?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elessedil</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14070</link>
		<dc:creator>Elessedil</dc:creator>
		<pubDate>Fri, 25 Jul 2008 15:49:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14070</guid>
		<description>Hello Adam,

i tried your code but unfortunately only the loopback interface is found, though the other two are up.
If you got an idea what could be the problem, please let me know.

thank you</description>
		<content:encoded><![CDATA[<p>Hello Adam,</p>
<p>i tried your code but unfortunately only the loopback interface is found, though the other two are up.<br />
If you got an idea what could be the problem, please let me know.</p>
<p>thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14046</link>
		<dc:creator>adam</dc:creator>
		<pubDate>Sun, 29 Jun 2008 11:43:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14046</guid>
		<description>Thanks for spotting that ccspro!</description>
		<content:encoded><![CDATA[<p>Thanks for spotting that ccspro!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ccspro</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-14045</link>
		<dc:creator>ccspro</dc:creator>
		<pubDate>Sun, 29 Jun 2008 05:44:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-14045</guid>
		<description>the above example has a typo:
		colon = strchr (ame, &#039;:&#039;);
should be:
		colon = strchr (name, &#039;:&#039;);

It will compile.</description>
		<content:encoded><![CDATA[<p>the above example has a typo:<br />
		colon = strchr (ame, &#8216;:&#8217;);<br />
should be:<br />
		colon = strchr (name, &#8216;:&#8217;);</p>
<p>It will compile.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-13984</link>
		<dc:creator>adam</dc:creator>
		<pubDate>Mon, 31 Mar 2008 11:29:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-13984</guid>
		<description>Yes it does only list the interfaces that are up.

Unfortunately, I don&#039;t think you can find every interface via the ioctl method so /proc/net/dev is probably your best bet for what you want.

/proc/net/dev is not so hard to parse. Here&#039;s some code which can do it - at least on Debian. I don&#039;t know if the format of the file is different on other distros:

&lt;pre&gt;/* listif.c - List all known interfaces on a Linux System */

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

main()
{
	char line[512];
	char *colon;
	char *name;
	FILE *fp;

	if(0 == (fp = fopen(&quot;/proc/net/dev&quot;, &quot;r&quot;)))
		return 1;
	
	while(0 != (name = fgets(line, 512, fp)))
	{
		while(isspace(name[0])) /* Trim leading whitespace */
			name++;

		colon = strchr (ame, &#039;:&#039;);
		if(colon)
		{
			*colon = 0;
			printf(&quot;%s:\n&quot;, name);
		}
	}

	fclose(fp);
	return 0;
}
&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Yes it does only list the interfaces that are up.</p>
<p>Unfortunately, I don&#8217;t think you can find every interface via the ioctl method so /proc/net/dev is probably your best bet for what you want.</p>
<p>/proc/net/dev is not so hard to parse. Here&#8217;s some code which can do it &#8211; at least on Debian. I don&#8217;t know if the format of the file is different on other distros:</p>
<pre>/* listif.c - List all known interfaces on a Linux System */

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

main()
{
	char line[512];
	char *colon;
	char *name;
	FILE *fp;

	if(0 == (fp = fopen("/proc/net/dev", "r")))
		return 1;

	while(0 != (name = fgets(line, 512, fp)))
	{
		while(isspace(name[0])) /* Trim leading whitespace */
			name++;

		colon = strchr (ame, ':');
		if(colon)
		{
			*colon = 0;
			printf("%s:\n", name);
		}
	}

	fclose(fp);
	return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michel Onoff</title>
		<link>http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html/comment-page-1#comment-13982</link>
		<dc:creator>Michel Onoff</dc:creator>
		<pubDate>Mon, 31 Mar 2008 08:39:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.html#comment-13982</guid>
		<description>This code shows only the *running* interfaces.

To get infos about *all* interfaces, I know of no other way than to read the file /proc/net/dev which, unfortunately, is not quite parse-friendly.</description>
		<content:encoded><![CDATA[<p>This code shows only the *running* interfaces.</p>
<p>To get infos about *all* interfaces, I know of no other way than to read the file /proc/net/dev which, unfortunately, is not quite parse-friendly.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

