From 5986d8f37153af6d035b25c3d41f1c19c44981aa Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 7 Dec 2022 22:26:31 +0100 Subject: [PATCH] sys/dns: select appropriate address family if AF_UNSPEC --- sys/include/net/dns.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/include/net/dns.h b/sys/include/net/dns.h index f5296895be..bebaf8b62f 100644 --- a/sys/include/net/dns.h +++ b/sys/include/net/dns.h @@ -74,6 +74,15 @@ static inline int dns_query(const char *domain_name, void *addr_out, int family) { int res = -ENOTSUP; + if (family == AF_UNSPEC) { + if (!IS_USED(MODULE_IPV4_ADDR)) { + family = AF_INET6; + } + else if (!IS_USED(MODULE_IPV6_ADDR)) { + family = AF_INET; + } + } + if (res <= 0 && IS_USED(MODULE_GCOAP_DNS)) { res = gcoap_dns_query(domain_name, addr_out, family); }