From 1cd39d813fba064316240e7325ddeb2a09202dff Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 20 Jan 2021 15:50:33 +0800 Subject: [PATCH] net/dev: check the available address further check the available address further to avoid obtain unusable device Change-Id: Icdd91cf0c4cb158f00a49f74d054425c2aeacd14 Signed-off-by: chao.an --- net/netdev/netdev_findbyaddr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/netdev/netdev_findbyaddr.c b/net/netdev/netdev_findbyaddr.c index a2a174b9f67..64c0c6a5501 100644 --- a/net/netdev/netdev_findbyaddr.c +++ b/net/netdev/netdev_findbyaddr.c @@ -89,7 +89,8 @@ FAR struct net_driver_s *netdev_findby_lipv4addr(in_addr_t lipaddr) { /* Is the interface in the "up" state? */ - if ((dev->d_flags & IFF_UP) != 0) + if ((dev->d_flags & IFF_UP) != 0 && + !net_ipv4addr_cmp(dev->d_ipaddr, INADDR_ANY)) { /* Yes.. check for an address match (under the netmask) */ @@ -140,7 +141,8 @@ FAR struct net_driver_s *netdev_findby_lipv6addr(const net_ipv6addr_t lipaddr) { /* Is the interface in the "up" state? */ - if ((dev->d_flags & IFF_UP) != 0) + if ((dev->d_flags & IFF_UP) != 0 && + !net_ipv6addr_cmp(dev->d_ipv6addr, g_ipv6_unspecaddr)) { /* Yes.. check for an address match (under the netmask) */