mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-26 03:16:18 +00:00
Fix netif_find() function for many netifs (should use atoi) and move it to the bottom of the file where similar functions are located
This commit is contained in:
parent
400c41ffd9
commit
45f3c28eb2
@ -51,6 +51,7 @@
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* atoi */
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
@ -471,37 +472,6 @@ netif_remove(struct netif *netif)
|
||||
LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup netif
|
||||
* Find a network interface by searching for its name
|
||||
*
|
||||
* @param name the name of the netif (like netif->name) plus concatenated number
|
||||
* in ascii representation (e.g. 'en0')
|
||||
*/
|
||||
struct netif *
|
||||
netif_find(const char *name)
|
||||
{
|
||||
struct netif *netif;
|
||||
u8_t num;
|
||||
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
num = (u8_t)(name[2] - '0');
|
||||
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (num == netif->num &&
|
||||
name[0] == netif->name[0] &&
|
||||
name[1] == netif->name[1]) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
|
||||
return netif;
|
||||
}
|
||||
}
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if LWIP_IPV4
|
||||
/**
|
||||
* @ingroup netif_ip4
|
||||
@ -1359,3 +1329,34 @@ netif_get_by_index(u8_t idx)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup netif
|
||||
* Find a network interface by searching for its name
|
||||
*
|
||||
* @param name the name of the netif (like netif->name) plus concatenated number
|
||||
* in ascii representation (e.g. 'en0')
|
||||
*/
|
||||
struct netif *
|
||||
netif_find(const char *name)
|
||||
{
|
||||
struct netif *netif;
|
||||
u8_t num;
|
||||
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
num = (u8_t)atoi(&name[2]);
|
||||
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (num == netif->num &&
|
||||
name[0] == netif->name[0] &&
|
||||
name[1] == netif->name[1]) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
|
||||
return netif;
|
||||
}
|
||||
}
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user