]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
client: don't override hostname with -4 or -6 after -h
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 16 May 2014 11:21:49 +0000 (13:21 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 16 May 2014 16:51:06 +0000 (18:51 +0200)
client.c

index afae699f8bab14de063a6e058080dc5657acf328..83128b2da99fcc2211c02dc7fd65e2fbb127cc97 100644 (file)
--- a/client.c
+++ b/client.c
@@ -2729,9 +2729,9 @@ main(int argc, char **argv)
 {
   char *line;
   const char *progname = argv[0];
-  const char *hostname = "127.0.0.1";
+  const char *hostname = NULL;
   const char *conf_file = DEFAULT_CONF_FILE;
-  int quit = 0, ret = 1, multi = 0, auto_auth = 0, short_timeout = 1;
+  int quit = 0, ret = 1, multi = 0, auto_auth = 0, family = IPADDR_UNSPEC;
   int port = DEFAULT_CANDM_PORT;
 
   /* Parse command line options */
@@ -2741,7 +2741,6 @@ main(int argc, char **argv)
       if (*argv) {
         hostname = *argv;
       }
-      short_timeout = 0;
     } else if (!strcmp(*argv, "-p")) {
       ++argv, --argc;
       if (*argv) {
@@ -2759,11 +2758,9 @@ 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";
+      family = IPADDR_INET4;
     } else if (!strcmp(*argv, "-6")) {
-      DNS_SetAddressFamily(IPADDR_INET6);
-      hostname = "::1";
+      family = IPADDR_INET6;
     } else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
       printf("chronyc (chrony) version %s\n", CHRONY_VERSION);
       exit(0);
@@ -2775,12 +2772,6 @@ main(int argc, char **argv)
     }
   }
 
-  if (short_timeout) {
-#ifdef FEAT_ASYNCDNS
-    initial_timeout /= 10;
-#endif
-  }
-
   if (isatty(0) && isatty(1) && isatty(2)) {
     on_terminal = 1;
   }
@@ -2796,6 +2787,15 @@ main(int argc, char **argv)
     return 1;
   }
   
+  DNS_SetAddressFamily(family);
+
+  if (!hostname) {
+    hostname = family == IPADDR_INET6 ? "::1" : "127.0.0.1";
+#ifdef FEAT_ASYNCDNS
+    initial_timeout /= 10;
+#endif
+  }
+
   open_io(hostname, port);
 
   if (auto_auth) {