Skip to content
Permalink
Browse files

net: lwm2m: remove IP CONFIG checks in lwm2m_parse_peerinfo()

CONFIG_NET_IPV* checks are not needed in lwm2m_parse_peerinfo().
The functions used are always available.  Worse, having these checks
forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really
needed (LwM2M could be using an offloaded IP stack).

Fixes: #17401

Signed-off-by: Michael Scott <mike@foundries.io>
  • Loading branch information...
mike-scott authored and jukkar committed Jul 8, 2019
1 parent 05cc5ae commit 88642ef2ebd6a961ab1e34b671f427459ff51916
Showing with 4 additions and 8 deletions.
  1. +4 −8 subsys/net/lib/lwm2m/lwm2m_engine.c
@@ -4096,30 +4096,26 @@ int lwm2m_parse_peerinfo(char *url, struct sockaddr *addr, bool *use_dtls)
(void)memset(addr, 0, sizeof(*addr));

/* try and set IP address directly */
ret = -EINVAL;

#if defined(CONFIG_NET_IPV6)
addr->sa_family = AF_INET6;
ret = net_addr_pton(AF_INET6, url + off,
&((struct sockaddr_in6 *)addr)->sin6_addr);
#endif /* CONFIG_NET_IPV6 */

#if defined(CONFIG_NET_IPV4)
/* Try to parse again using AF_INET */
if (ret < 0) {
addr->sa_family = AF_INET;
ret = net_addr_pton(AF_INET, url + off,
&((struct sockaddr_in *)addr)->sin_addr);
}
#endif /* CONFIG_NET_IPV4 */

if (ret < 0) {
#if defined(CONFIG_DNS_RESOLVER)
#if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4)
hints.ai_family = AF_UNSPEC;
#elif defined(CONFIG_NET_IPV6)
hints.ai_family = AF_INET6;
#else
#elif defined(CONFIG_NET_IPV4)
hints.ai_family = AF_INET;
#else
hints.ai_family = AF_UNSPEC;
#endif /* defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4) */
hints.ai_socktype = SOCK_DGRAM;
ret = getaddrinfo(url + off, NULL, &hints, &res);

0 comments on commit 88642ef

Please sign in to comment.
You can’t perform that action at this time.