Skip to content

Commit 9103403

Browse files
junqingzouioannisg
authored andcommitted
net: lwm2m: support NET_SOCKETS_OFFLOAD in peer parsing
The LwM2M implementation for DNS resolving has checks which configure hints based on whether IPv4 or IPv6 are enabled. Neither of them need enabled if using NET_SOCKETS_OFFLOAD, which then causes an error to be returned to due to "hints.ai_family" not being set. Also the offload API need to know when to free the allocated "struct addrinfo" instead of calling free() generically, thus let's use the freeaddrinfo() API for sockets which will call into the offload API if needed. Fixes: zephyrproject-rtos#18765 Signed-off-by: Jun Qing Zou <[email protected]>
1 parent 5ac014a commit 9103403

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4209,6 +4209,8 @@ int lwm2m_parse_peerinfo(char *url, struct sockaddr *addr, bool *use_dtls)
42094209
u16_t off, len;
42104210
u8_t tmp;
42114211

4212+
LOG_DBG("Parse url: %s", log_strdup(url));
4213+
42124214
http_parser_url_init(&parser);
42134215
ret = http_parser_parse_url(url, strlen(url), 0, &parser);
42144216
if (ret < 0) {
@@ -4268,6 +4270,9 @@ int lwm2m_parse_peerinfo(char *url, struct sockaddr *addr, bool *use_dtls)
42684270
hints.ai_family = AF_INET6;
42694271
#elif defined(CONFIG_NET_IPV4)
42704272
hints.ai_family = AF_INET;
4273+
#elif defined(CONFIG_NET_SOCKETS_OFFLOAD)
4274+
memset(&hints, 0, sizeof(hints));
4275+
hints.ai_family = AF_INET;
42714276
#else
42724277
hints.ai_family = AF_UNSPEC;
42734278
#endif /* defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4) */
@@ -4282,7 +4287,7 @@ int lwm2m_parse_peerinfo(char *url, struct sockaddr *addr, bool *use_dtls)
42824287

42834288
memcpy(addr, res->ai_addr, sizeof(*addr));
42844289
addr->sa_family = res->ai_family;
4285-
free(res);
4290+
freeaddrinfo(res);
42864291
#else
42874292
goto cleanup;
42884293
#endif /* CONFIG_DNS_RESOLVER */

0 commit comments

Comments
 (0)