Add eth_get_dev_by_index
authorAndy Fleming <afleming@freescale.com>
Wed, 11 Feb 2009 21:07:24 +0000 (15:07 -0600)
committerAndy Fleming <afleming@freescale.com>
Tue, 17 Feb 2009 00:05:53 +0000 (18:05 -0600)
This allows code to iterate through the ethernet devices

Signed-off-by: Andy Fleming <afleming@freescale.com>
net/eth.c

index b7ef09f4479b0619b3b79c50d953abb606950247..ec2ef1a365fc7547598613dd7a4d11c06da5b312 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -80,6 +80,28 @@ struct eth_device *eth_get_dev_by_name(char *devname)
        return target_dev;
 }
 
+struct eth_device *eth_get_dev_by_index(int index)
+{
+       struct eth_device *dev, *target_dev;
+       int idx = 0;
+
+       if (!eth_devices)
+               return NULL;
+
+       dev = eth_devices;
+       target_dev = NULL;
+       do {
+               if (idx == index) {
+                       target_dev = dev;
+                       break;
+               }
+               dev = dev->next;
+               idx++;
+       } while (dev != eth_devices);
+
+       return target_dev;
+}
+
 int eth_get_dev_index (void)
 {
        struct eth_device *dev;