[fix] the wrong 'ifconfig' information for multi-network interface
This commit is contained in:
parent
aaf4696c87
commit
7a2ae46ecf
|
@ -45,6 +45,7 @@ struct netdev *netdev_default;
|
||||||
int netdev_register(struct netdev *netdev, const char *name, void *user_data)
|
int netdev_register(struct netdev *netdev, const char *name, void *user_data)
|
||||||
{
|
{
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
|
uint8_t name_len;
|
||||||
uint16_t flags_mask;
|
uint16_t flags_mask;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
@ -77,8 +78,21 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
|
||||||
netdev->status_callback = RT_NULL;
|
netdev->status_callback = RT_NULL;
|
||||||
netdev->addr_callback = RT_NULL;
|
netdev->addr_callback = RT_NULL;
|
||||||
|
|
||||||
|
if(rt_strlen(name) > RT_NAME_MAX)
|
||||||
|
{
|
||||||
|
char netdev_name[RT_NAME_MAX + 1] = {0};
|
||||||
|
|
||||||
|
name_len = RT_NAME_MAX;
|
||||||
|
rt_strncpy(netdev_name, name, name_len);
|
||||||
|
LOG_E("netdev name[%s] length is so long that have been cut into [%s].", name, netdev_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
name_len = rt_strlen(name);
|
||||||
|
}
|
||||||
|
|
||||||
/* fill network interface device */
|
/* fill network interface device */
|
||||||
rt_strncpy(netdev->name, name, RT_NAME_MAX);
|
rt_strncpy(netdev->name, name, name_len);
|
||||||
netdev->user_data = user_data;
|
netdev->user_data = user_data;
|
||||||
|
|
||||||
/* initialize current network interface device single list */
|
/* initialize current network interface device single list */
|
||||||
|
@ -260,7 +274,7 @@ struct netdev *netdev_get_by_name(const char *name)
|
||||||
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
|
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
|
||||||
{
|
{
|
||||||
netdev = rt_slist_entry(node, struct netdev, list);
|
netdev = rt_slist_entry(node, struct netdev, list);
|
||||||
if (netdev && (rt_strncmp(netdev->name, name, RT_NAME_MAX) == 0))
|
if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(netdev->name) < RT_NAME_MAX ? rt_strlen(netdev->name) : RT_NAME_MAX) == 0))
|
||||||
{
|
{
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
return netdev;
|
return netdev;
|
||||||
|
|
Loading…
Reference in New Issue