Skip to content
Permalink
Browse files

net: getaddrinfo: Query both IPv4 and IPv6 if family is AF_UNSPEC

We must query both IPv4 and IPv6 addresses if the hints parameter
is NULL i.e., user does not supply hints or if family is set to
AF_UNSPEC.

Fixes #16453

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Jun 12, 2019
1 parent 05cd342 commit 19806a2c1b617158a1c429a4576bd61369507c65
Showing with 22 additions and 1 deletion.
  1. +22 −1 subsys/net/lib/sockets/getaddrinfo.c
@@ -105,7 +105,7 @@ static int exec_query(const char *host, int family,
{
enum dns_query_type qtype = DNS_QUERY_TYPE_A;

if (IS_ENABLED(CONFIG_NET_IPV6) && family != AF_INET) {
if (IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6) {
qtype = DNS_QUERY_TYPE_AAAA;
}

@@ -205,6 +205,7 @@ int z_impl_z_zsock_getaddrinfo_internal(const char *host, const char *service,
/* Link entries in advance */
ai_state.ai_arr[0].ai_next = &ai_state.ai_arr[1];

/* If the family is AF_UNSPEC, then we query IPv4 address first */
ret = exec_query(host, family, &ai_state);
if (ret == 0) {
/* If the DNS query for reason fails so that the
@@ -226,6 +227,26 @@ int z_impl_z_zsock_getaddrinfo_internal(const char *host, const char *service,
st1 = DNS_EAI_SYSTEM;
}

/* If family is AF_UNSPEC, the IPv4 query has been already done
* so we can do IPv6 query next if IPv6 is enabled in the config.
*/
if (family == AF_UNSPEC && IS_ENABLED(CONFIG_NET_IPV6)) {
ret = exec_query(host, AF_INET6, &ai_state);
if (ret == 0) {
int ret = k_sem_take(&ai_state.sem,

This comment has been minimized.

Copy link
@DevNaga

DevNaga Jun 20, 2019

will this not shadow the ret ?(which seem to have been already defined above.)

This comment has been minimized.

Copy link
@jukkar

jukkar Jun 24, 2019

Author Member

yes, the inner most ret declaration seems to be useless but does no harm either. If you want, please send a patch that removes that.

CONFIG_NET_SOCKETS_DNS_TIMEOUT +
K_MSEC(100));
if (ret == -EAGAIN) {
return DNS_EAI_AGAIN;
}

st2 = ai_state.status;
} else {
errno = -ret;
st2 = DNS_EAI_SYSTEM;
}
}

if (ai_state.idx > 0) {
ai_addr = &ai_state.ai_arr[ai_state.idx - 1]._ai_addr;
net_sin(ai_addr)->sin_port = htons(port);

0 comments on commit 19806a2

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