]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nameserv: set hints for getaddrinfo() according to -4/-6 option
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Oct 2017 09:03:11 +0000 (11:03 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 4 Oct 2017 09:20:10 +0000 (11:20 +0200)
Avoid sending unnecessary DNS requests when the -4/-6 option is
specified.

nameserv.c

index b5899e7af026bacbfd2007d88121357657ad18b9..1cb96086721c4d5bc4e92315de94e7ceec556349 100644 (file)
@@ -53,7 +53,19 @@ DNS_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
   max_addrs = MIN(max_addrs, DNS_MAX_ADDRESSES);
 
   memset(&hints, 0, sizeof (hints));
-  hints.ai_family = AF_UNSPEC;
+
+  switch (address_family) {
+    case IPADDR_INET4:
+      hints.ai_family = AF_INET;
+      break;
+#ifdef FEAT_IPV6
+    case IPADDR_INET6:
+      hints.ai_family = AF_INET6;
+      break;
+#endif
+    default:
+      hints.ai_family = AF_UNSPEC;
+  }
   hints.ai_socktype = SOCK_STREAM;
 
   result = getaddrinfo(name, NULL, &hints, &res);