Merge pull request #4386 from xiangxistu/master

[fix] the wrong 'ifconfig' information for multi-network interface
This commit is contained in:
Bernard Xiong 2021-02-26 00:20:08 +08:00 committed by GitHub
commit f09592297a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -77,6 +77,14 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
netdev->status_callback = RT_NULL;
netdev->addr_callback = RT_NULL;
if(rt_strlen(name) > RT_NAME_MAX)
{
char netdev_name[RT_NAME_MAX + 1] = {0};
rt_strncpy(netdev_name, name, RT_NAME_MAX);
LOG_E("netdev name[%s] length is so long that have been cut into [%s].", name, netdev_name);
}
/* fill network interface device */
rt_strncpy(netdev->name, name, RT_NAME_MAX);
netdev->user_data = user_data;
@ -260,7 +268,7 @@ struct netdev *netdev_get_by_name(const char *name)
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
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);
return netdev;