]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Ensure that DNS lookups on IPv6-absent systems only look up IPv4 addresses
authorDanny Mayer <mayer@ntp.org>
Fri, 29 Oct 2004 00:49:19 +0000 (20:49 -0400)
committerDanny Mayer <mayer@ntp.org>
Fri, 29 Oct 2004 00:49:19 +0000 (20:49 -0400)
bk: 4181938fa-OJGJkv85yAZKQGeC3qyw

ntpd/ntp_config.c
ntpd/ntp_intres.c

index 49fa569dffde64eeccbcd6622a439fc24c96a4dd..97192a18fa99566b72f2387b63eaf35e2ffe09a5 100644 (file)
@@ -19,6 +19,8 @@
 #include "ntp_stdlib.h"
 #include "ntp_config.h"
 #include "ntp_cmdargs.h"
+#include <isc/boolean.h>
+#include <isc/net.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -2110,6 +2112,11 @@ getnetnum(
            hints.ai_family = addr->ss_family;
        else
            hints.ai_family = AF_UNSPEC;
+       /*
+        * If we don't have an IPv6 stack, just look up IPv4 addresses
+        */
+       if (isc_net_probeipv6() != ISC_TRUE)
+               hints.ai_family = AF_INET;
 
        hints.ai_socktype = SOCK_DGRAM;
 #ifdef DEBUG
index b2f22b8e0759fe4855180c47242a1981d92b80c4..a48843b37ea1c9b6539bfb649a04e1abf661dfde 100644 (file)
@@ -41,6 +41,9 @@
 # include <sys/param.h>                /* MAXHOSTNAMELEN (often) */
 #endif
 
+#include <isc/boolean.h>
+#include <isc/net.h>
+
 #define        STREQ(a, b)     (*(a) == *(b) && strcmp((a), (b)) == 0)
 
 /*
@@ -451,6 +454,7 @@ findhostaddr(
        )
 {
        struct addrinfo *addr;
+       struct addrinfo hints;
        int error;
 
        checkparent();          /* make sure our guy is still running */
@@ -472,7 +476,16 @@ findhostaddr(
                        msyslog(LOG_INFO, "findhostaddr: Resolving <%s>",
                                entry->ce_name);
 #endif /* DEBUG */
-               error = getaddrinfo(entry->ce_name, NULL, NULL, &addr);
+
+               memset(&hints, 0, sizeof(hints));
+               hints.ai_family = AF_UNSPEC;
+               /*
+                * If the IPv6 stack is not available look only for IPv4 addresses
+                */
+               if (isc_net_probeipv6() == ISC_FALSE)
+                       hints.ai_family = AF_INET;
+
+               error = getaddrinfo(entry->ce_name, NULL, &hints, &addr);
                if (error == 0) {
                        entry->peer_store = *((struct sockaddr_storage*)(addr->ai_addr));
                        if (entry->peer_store.ss_family == AF_INET) {
@@ -538,6 +551,13 @@ openntp(void)
 
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_UNSPEC;
+
+       /*
+        * If the IPv6 stack is not available look only for IPv4 addresses
+        */
+       if (isc_net_probeipv6() == ISC_FALSE)
+               hints.ai_family = AF_INET;
+
        hints.ai_socktype = SOCK_DGRAM;
        if (getaddrinfo(NULL, "ntp", &hints, &addrResult)!=0) {
                msyslog(LOG_ERR, "getaddrinfo failed: %m");