]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3533] ntpdc peer_info ipv6 issues
authorJuergen Perlinger <perlinger@ntp.org>
Thu, 30 May 2019 08:53:25 +0000 (10:53 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Thu, 30 May 2019 08:53:25 +0000 (10:53 +0200)
bk: 5cef9a059WjKj-3gC2e-F9nGWzokvA

ChangeLog
ntpd/ntp_request.c
ntpdc/ntpdc.c
ntpdc/ntpdc_ops.c

index 9ff845c81028eeecbd72fd587d28555bc5f781e5..2a50e0db94648b8d2fefb9107c2f96ff1b45430b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3533] ntpdc peer_info ipv6 issues <perlinger@ntp.org>
+  - applied patch by Gerry Garvey
+
 ---
 (4.2.8p13) 2019/03/07 Released by Harlan Stenn <stenn@ntp.org>
 
index 53585088a67f6392989a69d46c2fc91ce0de7970..b770862e092ddef16d2779b39c3294573f7125ff 100644 (file)
@@ -841,7 +841,7 @@ peer_info (
                pp = findexistingpeer(&addr, NULL, NULL, -1, 0, NULL);
                if (NULL == pp)
                        continue;
-               if (IS_IPV6(srcadr)) {
+               if (IS_IPV6(&pp->srcadr)) {
                        if (pp->dstadr)
                                ip->dstadr6 =
                                    (MDF_BCAST == pp->cast_flags)
index c54596e32f9476a06007cf16cf35f96c5545edfa..57e7e791fe282c883a611ba3fcf342deb0a7bd04 100644 (file)
@@ -176,8 +176,8 @@ static      l_fp delay_time;                                /* delay time */
 static char currenthost[LENHOSTNAME];                  /* current host name */
 int showhostnames = 1;                                 /* show host names by default */
 
-static int ai_fam_templ;                               /* address family */
-static int ai_fam_default;                             /* default address family */
+static int ai_fam_templ = AF_UNSPEC;           /* address family */
+static int ai_fam_default = AF_UNSPEC; /* default address family */
 static SOCKET sockfd;                                  /* fd socket is opened on */
 static int havehost = 0;                               /* set to 1 when host open */
 int s_port = 0;
@@ -312,11 +312,11 @@ ntpdcmain(
        }
 
        if (HAVE_OPT(IPV4))
-               ai_fam_templ = AF_INET;
+               ai_fam_default = AF_INET;
        else if (HAVE_OPT(IPV6))
-               ai_fam_templ = AF_INET6;
-       else
-               ai_fam_templ = ai_fam_default;
+               ai_fam_default = AF_INET6;
+
+       ai_fam_templ = ai_fam_default;
 
        if (HAVE_OPT(COMMAND)) {
                int             cmdct = STACKCT_OPT( COMMAND );
@@ -1401,7 +1401,7 @@ getarg(
                        ai_fam_templ = AF_INET;
                        return -1;
                }
-               if (!getnetnum(str, &(argp->netnum), (char *)0, 0)) {
+               if (!getnetnum(str, &(argp->netnum), (char *)0, ai_fam_templ)) {
                        return 0;
                }
                break;
@@ -1467,6 +1467,7 @@ getnetnum(
        struct addrinfo hints, *ai = NULL;
 
        ZERO(hints);
+       hints.ai_family = af;
        hints.ai_flags = AI_CANONNAME;
 #ifdef AI_ADDRCONFIG
        hints.ai_flags |= AI_ADDRCONFIG;
index 3b50916e7f8a873d8b7cedd65a96727b56c0965e..680cbe06cafaf15e207ede5d178c159d70b8df17 100644 (file)
@@ -382,9 +382,16 @@ again:
                if ((pcmd->nargs == 0) ||
                    ((pcmd->argval->ival == 6) && (plist->v6_flag != 0)) ||
                    ((pcmd->argval->ival == 4) && (plist->v6_flag == 0)))
-                       (void) fprintf(fp, "%-9s %s\n",
-                               modetoa(plist->hmode),
-                               nntohost(&paddr));
+               {
+                       const char *strhost = nntohost(&paddr);
+                       const char *straddr = stoa(&paddr);
+                       (void) fprintf(fp, "%-12s %s",
+                               modetoa(plist->hmode), strhost);
+                       if (strcmp(strhost,straddr))
+                               (void) fprintf(fp, " (%s)\n", straddr);
+                       else
+                               (void) fprintf(fp, "\n");
+               }
                plist++;
                items--;
        }