title: How to Get a List of Ethernet Devices
body: <p>I want to get a list of the ethernet device on a system using a C program.  In my system below, I would like to get a listing of eth0-9, and if possible some associated properties (e.g. MAC addr, max speed supported). </p>
  
  <pre><code># ip link show | grep " eth"
  3: eth0: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  4: eth1: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
  5: eth2: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  6: eth3: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  7: eth4: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  8: eth5: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  14: eth6: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  15: eth7: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  16: eth8: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  17: eth9: &lt;BROADCAST,MULTICAST&gt; mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
  </code></pre>
  
  <p>Searching the net, I found code samples similar to below:</p>
  
  <pre><code>char          buf[1024];
  struct ifconf ifc;
  int           sck;
  
  /* Get a socket handle. */
  sck = socket(AF_INET, SOCK_DGRAM, 0);
  
  /* Query available interfaces. */
  ifc.ifc_len = sizeof(buf);
  ifc.ifc_buf = buf;
  ioctl(sck, SIOCGIFCONF, &amp;ifc);
  </code></pre>
  
  <p>However, the above code only retrieves the list of eth devices for which and IP address is assigned.  I want to get the full list of eth devices whether an IP addr is assigned to it or not.</p>
  
  <p>I also came across the following function in glibc:</p>
  
  <p>struct if_nameindex *if_nameindex(void);</p>
  
  <p>However, the above function returns only the eth device index and name (as in ethX), which is pretty limited info.</p>
  
  <p>Is there other/better options.</p>
  
  <p>To be clear in my objective, I want to get the list of eth devices from the system, and only pick the eth devices that are 10G ports.</p>
  
  <p>Thank you,
  Ahmed.</p>