diff --git a/src/core/netif.c b/src/core/netif.c index 6fc7f5ee..a3b91de0 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -1327,22 +1327,13 @@ netif_name_to_index(const char *name) char * netif_index_to_name(u8_t idx, char *name) { - struct netif *curif = netif_list; - u8_t num; - if (idx == 0) { - return NULL; /* indexes start at 1 */ - } - num = netif_index_to_num(idx); + struct netif *netif = netif_get_by_index(idx); - /* find netif from num */ - while (curif != NULL) { - if (curif->num == num) { - name[0] = curif->name[0]; - name[1] = curif->name[1]; - lwip_itoa(&name[2], NETIF_NAMESIZE - 2, num); - return name; - } - curif = curif->next; + if (netif != NULL) { + name[0] = netif->name[0]; + name[1] = netif->name[1]; + lwip_itoa(&name[2], NETIF_NAMESIZE - 2, netif_index_to_num(idx)); + return name; } return NULL; } @@ -1351,16 +1342,16 @@ netif_index_to_name(u8_t idx, char *name) * @ingroup netif * Return the interface for the netif index * -* @param index index of netif to find +* @param idx index of netif to find */ struct netif* -netif_get_by_index(u8_t index) +netif_get_by_index(u8_t idx) { struct netif* netif; - if (index != NETIF_NO_INDEX) { + if (idx != NETIF_NO_INDEX) { for (netif = netif_list; netif != NULL; netif = netif->next) { - if (index == netif_get_index(netif)) { + if (idx == netif_get_index(netif)) { return netif; /* found! */ } } diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 4792a12c..7ad3a592 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -499,7 +499,7 @@ err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t u8_t netif_name_to_index(const char *name); char * netif_index_to_name(u8_t idx, char *name); -struct netif* netif_get_by_index(u8_t index); +struct netif* netif_get_by_index(u8_t idx); /* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 */ #define netif_get_index(netif) ((netif)->num + 1)