From: Juergen Perlinger Date: Thu, 10 Oct 2019 13:13:25 +0000 (+0200) Subject: [Bug 3619] Honour drefid setting in cooked mode and sysinfo X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d83384a16b48b0193060e708bc74c4a47e3f6e0f;p=thirdparty%2Fntp.git [Bug 3619] Honour drefid setting in cooked mode and sysinfo bk: 5d9f2e75wx87OArm7L77ISir7gJVcA --- diff --git a/ChangeLog b/ChangeLog index dab3e21b5..d5a490cdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * [Sec 3610] process_control() should bail earlier on short packets. stenn@ - Reported by Philippe Antoine +* [Bug 3619] Honour drefid setting in cooked mode and sysinfo + - applied patch by Gerry Garvey * [Bug 3615] accelerate refclock startup * [Bug 3613] Propagate noselect to mobilized pool servers - Reported by Martin Burnicki diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 406710bdf..ecb1428bc 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -3746,6 +3746,7 @@ collect_display_vdc( int match; u_long ul; int vtype; + sockaddr_u sau; ZERO(vl); for (pvdc = table; pvdc->tag != NULL; pvdc++) { @@ -3806,6 +3807,7 @@ collect_display_vdc( } } /* fallthru */ + case NTP_REFID: /* fallthru */ case NTP_MODE: /* fallthru */ case NTP_2BIT: pvdc->v.str = estrdup(val); @@ -3880,6 +3882,21 @@ collect_display_vdc( leapbits[ul & 0x3]); break; + case NTP_REFID: + if (!decodenetnum(pvdc->v.str, &sau)) { + fprintf(fp, "%s %s\n", pvdc->display, /* Text fmt */ + pvdc->v.str); + } else if (drefid == REFID_IPV4) { + fprintf(fp, "%s %s\n", pvdc->display, /* IPv4 fmt */ + stoa(&sau)); + } else { + fprintf (fp, "%s 0x%08x\n", pvdc->display, /* Hex / hash */ + ntohl(addr2refid(&sau))); + } + free(pvdc->v.str); + pvdc->v.str = NULL; + break; + default: xprintf(stderr, "unexpected vdc type %d for %s\n", pvdc->type, pvdc->tag); @@ -3939,7 +3956,7 @@ sysinfo( VDC_INIT("precision", "log2 precision: ", NTP_STR), VDC_INIT("rootdelay", "root delay: ", NTP_STR), VDC_INIT("rootdisp", "root dispersion: ", NTP_STR), - VDC_INIT("refid", "reference ID: ", NTP_STR), + VDC_INIT("refid", "reference ID: ", NTP_REFID), VDC_INIT("reftime", "reference time: ", NTP_LFP), VDC_INIT("sys_jitter", "system jitter: ", NTP_STR), VDC_INIT("clk_jitter", "clock jitter: ", NTP_STR), diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 0bf849864..0382c0f94 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -3675,11 +3675,18 @@ cookedprint( refid_buf[i] = (isprint(str[i]) ? str[i] : '?'); refid_buf[i] = 0; /* Null terminator */ output(fp, name, refid_buf); - } else if (ISREFCLOCKADR(&hval)) - output(fp, name, - refnumtoa(&hval)); - else - output(fp, name, stoa(&hval)); + } else if (ISREFCLOCKADR(&hval)) { + output(fp, name, refnumtoa(&hval)); + } else { + if (drefid == REFID_IPV4) { + output(fp, name, stoa(&hval)); + } else { + char refid_buf[12]; + snprintf (refid_buf, sizeof(refid_buf), + "0x%08x", ntohl(addr2refid(&hval))); + output(fp, name, refid_buf); + } + } } else if (strlen(value) <= 4) { output(fp, name, value); } else { diff --git a/ntpq/ntpq.h b/ntpq/ntpq.h index 1f0291531..53f76387a 100644 --- a/ntpq/ntpq.h +++ b/ntpq/ntpq.h @@ -64,6 +64,7 @@ #define NTP_LFP 0x7 /* NTP timestamp */ #define NTP_MODE 0x8 /* peer mode */ #define NTP_2BIT 0x9 /* leap bits */ +#define NTP_REFID 0xA /* RefID */ /* * Arguments are returned in a union