
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD plagnioj@jcrosoft.com --- include/net.h | 1 + net/eth.c | 17 +++++------------ 2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/net.h b/include/net.h index 4a03717..2a8a12d 100644 --- a/include/net.h +++ b/include/net.h @@ -93,6 +93,7 @@ enum eth_state_t { };
struct eth_device { + int index; char name[NAMESIZE]; unsigned char enetaddr[6]; int iobase; diff --git a/net/eth.c b/net/eth.c index 42f74da..2316a22 100644 --- a/net/eth.c +++ b/net/eth.c @@ -83,6 +83,7 @@ static unsigned int eth_rcv_current = 0, eth_rcv_last = 0; #endif
static struct eth_device *eth_devices, *eth_current; +static int nb_eth_devices = 0;
struct eth_device *eth_get_dev(void) { @@ -133,22 +134,12 @@ struct eth_device *eth_get_dev_by_index(int index)
int eth_get_dev_index (void) { - struct eth_device *dev; - int num = 0; - if (!eth_devices) { return (-1); }
- for (dev = eth_devices; dev; dev = dev->next) { - if (dev == eth_current) - break; - ++num; - } - - if (dev) { - return (num); - } + if (eth_current) + return eth_current->index;
return (0); } @@ -172,6 +163,8 @@ int eth_register(struct eth_device* dev) d->next = dev; }
+ dev->index = nb_eth_devices; + nb_eth_devices++; dev->state = ETH_STATE_INIT; dev->next = eth_devices;