]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add -4 and -6 options to set address family when resolving names
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 13 Oct 2009 11:10:28 +0000 (13:10 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 13 Oct 2009 14:15:49 +0000 (16:15 +0200)
client.c
main.c
nameserv.c
nameserv.h

index 4059fe3f7251e6c0f2f005ed8cd185b27074cdcf..cce46cac29ee9c1e7d78ff66b9af350d79709fbe 100644 (file)
--- a/client.c
+++ b/client.c
@@ -2619,11 +2619,17 @@ main(int argc, char **argv)
       }
     } else if (!strcmp(*argv, "-n")) {
       no_dns = 1;
+    } else if (!strcmp(*argv, "-4")) {
+      DNS_SetAddressFamily(IPADDR_INET4);
+      hostname = "127.0.0.1";
+    } else if (!strcmp(*argv, "-6")) {
+      DNS_SetAddressFamily(IPADDR_INET6);
+      hostname = "::1";
     } else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
       printf("chronyc (chrony) version %s\n", PROGRAM_VERSION_STRING);
       exit(0);
     } else if (!strncmp(*argv, "-", 1)) {
-      fprintf(stderr, "Usage : %s [-h <hostname>] [-p <port-number>] [-n] [command]\n", progname);
+      fprintf(stderr, "Usage : %s [-h <hostname>] [-p <port-number>] [-n] [-4|-6] [command]\n", progname);
       exit(1);
     } else {
       break; /* And process remainder of line as a command */
diff --git a/main.c b/main.c
index 17c1b8b1b52aef340cab5fc7cc200e6b7e7b3f24..2a322a6dabbbe05457ac84d01f3adf9f8952d5f8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -61,6 +61,7 @@
 #include "refclock.h"
 #include "clientlog.h"
 #include "broadcast.h"
+#include "nameserv.h"
 
 /* ================================================== */
 
@@ -268,6 +269,10 @@ int main
       exit(0);
     } else if (!strcmp("-d", *argv)) {
       debug = 1;
+    } else if (!strcmp("-4", *argv)) {
+      DNS_SetAddressFamily(IPADDR_INET4);
+    } else if (!strcmp("-6", *argv)) {
+      DNS_SetAddressFamily(IPADDR_INET6);
     } else {
       LOG(LOGS_WARN, LOGF_Main, "Unrecognized command line option [%s]", *argv);
     }
index d5874d6755fbad52671e1e9f76378ce348ccccf2..d39659366bb28ff2904b89f31a3eb5f4b07618db 100644 (file)
 #define MAXRETRIES 10
 static unsigned int retries = 0;
 
+static int address_family = IPADDR_UNSPEC;
+
+void
+DNS_SetAddressFamily(int family)
+{
+  address_family = family;
+}
+
 int 
 DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry)
 {
@@ -80,6 +88,8 @@ try_again:
         break;
 #endif
     }
+    if (result && address_family != IPADDR_UNSPEC && address_family != addr->family)
+      result = 0;
   }
 
   freeaddrinfo(res);
index 1451b9bf48362811df6b62951425de086ebf4006..0d282f3709821b7ba28bb4bcbba8bf860737d70c 100644 (file)
@@ -34,6 +34,9 @@
 
 #include "addressing.h"
 
+/* Resolve names only to selected address family */
+extern void DNS_SetAddressFamily(int family);
+
 extern int DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry);
 
 extern void DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len);