]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/resolve/resolved-dns-question.c
resolved: if ipv6 is off patch hostname→address query with unspec family to ipv4
[thirdparty/systemd.git] / src / resolve / resolved-dns-question.c
index 8f5ebb4590d38330652da23c06d023205ffb1fbc..5754c851117b9220fed470e9ec20bed0455fb8cf 100644 (file)
@@ -4,6 +4,7 @@
 #include "dns-domain.h"
 #include "dns-type.h"
 #include "resolved-dns-question.h"
+#include "socket-util.h"
 
 DnsQuestion *dns_question_new(size_t n) {
         DnsQuestion *q;
@@ -330,6 +331,11 @@ int dns_question_new_address(DnsQuestion **ret, int family, const char *name, bo
         if (!IN_SET(family, AF_INET, AF_INET6, AF_UNSPEC))
                 return -EAFNOSUPPORT;
 
+        /* If IPv6 is off and the request has an unspecified lookup family, restrict it automatically to
+         * IPv4. */
+        if (family == AF_UNSPEC && !socket_ipv6_is_enabled())
+                family = AF_INET;
+
         if (convert_idna) {
                 r = dns_name_apply_idna(name, &buf);
                 if (r < 0)