From: Juergen Perlinger Date: Thu, 30 May 2019 08:53:25 +0000 (+0200) Subject: [Bug 3533] ntpdc peer_info ipv6 issues X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90ea03f06767e7e94ddc0626f337bba5e5608658;p=thirdparty%2Fntp.git [Bug 3533] ntpdc peer_info ipv6 issues bk: 5cef9a059WjKj-3gC2e-F9nGWzokvA --- diff --git a/ChangeLog b/ChangeLog index 9ff845c81..2a50e0db9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +--- +* [Bug 3533] ntpdc peer_info ipv6 issues + - applied patch by Gerry Garvey + --- (4.2.8p13) 2019/03/07 Released by Harlan Stenn diff --git a/ntpd/ntp_request.c b/ntpd/ntp_request.c index 53585088a..b770862e0 100644 --- a/ntpd/ntp_request.c +++ b/ntpd/ntp_request.c @@ -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) diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index c54596e32..57e7e791f 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -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; diff --git a/ntpdc/ntpdc_ops.c b/ntpdc/ntpdc_ops.c index 3b50916e7..680cbe06c 100644 --- a/ntpdc/ntpdc_ops.c +++ b/ntpdc/ntpdc_ops.c @@ -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--; }