From a353602aa9cc50ed958df11af35e3972101b5f40 Mon Sep 17 00:00:00 2001 From: Roland Takacs Date: Thu, 22 Jun 2017 09:06:04 +0200 Subject: [PATCH] Do not search net device when all-zeros address is used. --- net/socket/getsockname.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/net/socket/getsockname.c b/net/socket/getsockname.c index e19d48b45c..8942a90c0b 100644 --- a/net/socket/getsockname.c +++ b/net/socket/getsockname.c @@ -153,6 +153,17 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, * a single network device and only the network device knows the IP address. */ + if (lipaddr == 0) + { +#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) + outaddr->sin_family = AF_INET; + outaddr->sin_addr.s_addr = 0; + *addrlen = sizeof(struct sockaddr_in); +#endif + + return OK; + } + net_lock(); #ifdef CONFIG_NETDEV_MULTINIC @@ -160,7 +171,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, * NOTE: listening sockets have no ripaddr. Work around is to use the * lipaddr when ripaddr is not available. */ -` + if (ripaddr == 0) { ripaddr = lipaddr; @@ -284,6 +295,17 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, * a single network device and only the network device knows the IP address. */ + if (net_ipv6addr_cmp(lipaddr, g_ipv6_allzeroaddr)) + { +#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK) + outaddr->sin6_family = AF_INET6; + memcpy(outaddr->sin6_addr.in6_u.u6_addr8, g_ipv6_allzeroaddr, 16); + *addrlen = sizeof(struct sockaddr_in6); +#endif + + return OK; + } + net_lock(); #ifdef CONFIG_NETDEV_MULTINIC