aboutsummaryrefslogtreecommitdiff
path: root/ntpq/ntpq-subs.c
diff options
context:
space:
mode:
Diffstat (limited to 'ntpq/ntpq-subs.c')
-rw-r--r--ntpq/ntpq-subs.c59
1 files changed, 35 insertions, 24 deletions
diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c
index acc175d197de..8495e2059ef6 100644
--- a/ntpq/ntpq-subs.c
+++ b/ntpq/ntpq-subs.c
@@ -446,6 +446,7 @@ doaddvlist(
len = strlen(vars);
while (nextvar(&len, &vars, &name, &value)) {
+ INSIST(name && value);
vl = findlistvar(vlist, name);
if (NULL == vl) {
fprintf(stderr, "Variable list full\n");
@@ -481,6 +482,7 @@ dormvlist(
len = strlen(vars);
while (nextvar(&len, &vars, &name, &value)) {
+ INSIST(name && value);
vl = findlistvar(vlist, name);
if (vl == 0 || vl->name == 0) {
(void) fprintf(stderr, "Variable `%s' not found\n",
@@ -1153,7 +1155,7 @@ printassoc(
* Output a header
*/
(void) fprintf(fp,
- "\nind assid status conf reach auth condition last_event cnt\n");
+ "ind assid status conf reach auth condition last_event cnt\n");
(void) fprintf(fp,
"===========================================================\n");
for (i = 0; i < numassoc; i++) {
@@ -1475,31 +1477,36 @@ prettyinterval(
}
if (diff <= 2048) {
- snprintf(buf, cb, "%ld", diff);
+ snprintf(buf, cb, "%u", (unsigned int)diff);
return buf;
}
diff = (diff + 29) / 60;
if (diff <= 300) {
- snprintf(buf, cb, "%ldm", diff);
+ snprintf(buf, cb, "%um", (unsigned int)diff);
return buf;
}
diff = (diff + 29) / 60;
if (diff <= 96) {
- snprintf(buf, cb, "%ldh", diff);
+ snprintf(buf, cb, "%uh", (unsigned int)diff);
return buf;
}
diff = (diff + 11) / 24;
if (diff <= 999) {
- snprintf(buf, cb, "%ldd", diff);
+ snprintf(buf, cb, "%ud", (unsigned int)diff);
return buf;
}
/* years are only approximated... */
diff = (long)floor(diff / 365.25 + 0.5);
- snprintf(buf, cb, "%ldy", diff);
+ if (diff <= 999) {
+ snprintf(buf, cb, "%uy", (unsigned int)diff);
+ return buf;
+ }
+ /* Ok, this amounts to infinity... */
+ strlcpy(buf, "INF", cb);
return buf;
}
@@ -1638,10 +1645,14 @@ doprintpeers(
l_fp rec;
l_fp ts;
u_long poll_sec;
+ u_long flash = 0;
char type = '?';
- char whenbuf[8], pollbuf[8];
char clock_name[LENHOSTNAME];
-
+ char whenbuf[12], pollbuf[12];
+ /* [Bug 3482] formally whenbuf & pollbuf should be able to hold
+ * a full signed int. Not that we would use that much string
+ * data for it...
+ */
get_systime(&ts);
have_srchost = FALSE;
@@ -1657,6 +1668,7 @@ doprintpeers(
ZERO(estdisp);
while (nextvar(&datalen, &data, &name, &value)) {
+ INSIST(name && value);
if (!strcmp("srcadr", name) ||
!strcmp("peeradr", name)) {
if (!decodenetnum(value, &srcadr))
@@ -1771,6 +1783,8 @@ doprintpeers(
} else if (!strcmp("reftime", name)) {
if (!decodets(value, &reftime))
L_CLR(&reftime);
+ } else if (!strcmp("flash", name)) {
+ decodeuint(value, &flash);
} else {
// fprintf(stderr, "UNRECOGNIZED name=%s ", name);
}
@@ -1850,7 +1864,9 @@ doprintpeers(
+ 1 + 15 + 1, "");
else
fprintf(fp, "%c%-15.15s ", c, clock_name);
- if (!have_da_rid) {
+ if ((flash & TEST12) && (pvl != opeervarlist)) {
+ drlen = fprintf(fp, "(loop)");
+ } else if (!have_da_rid) {
drlen = 0;
} else {
drlen = strlen(dstadr_refid);
@@ -2381,7 +2397,7 @@ fetch_nonce(
return FALSE;
}
chars = rsize - (sizeof(nonce_eq) - 1);
- if (chars >= (int)cb_nonce)
+ if (chars >= cb_nonce)
return FALSE;
memcpy(nonce, rdata + sizeof(nonce_eq) - 1, chars);
nonce[chars] = '\0';
@@ -2647,6 +2663,7 @@ collect_mru_list(
have_addr_older = FALSE;
have_last_older = FALSE;
while (!qres && nextvar(&rsize, &rdata, &tag, &val)) {
+ INSIST(tag && val);
if (debug > 1)
fprintf(stderr, "nextvar gave: %s = %s\n",
tag, val);
@@ -3391,11 +3408,9 @@ ifstats(
fields = 0;
ui = 0;
while (nextvar(&dsize, &datap, &tag, &val)) {
+ INSIST(tag && val);
if (debug > 1)
- fprintf(stderr, "nextvar gave: %s = %s\n", tag,
- (NULL == val)
- ? ""
- : val);
+ fprintf(stderr, "nextvar gave: %s = %s\n", tag, val);
comprende = FALSE;
switch(tag[0]) {
@@ -3407,7 +3422,7 @@ ifstats(
case 'b':
if (1 == sscanf(tag, bcast_fmt, &ui) &&
- (NULL == val ||
+ ('\0' == *val ||
decodenetnum(val, &row.bcast)))
comprende = TRUE;
break;
@@ -3433,7 +3448,6 @@ ifstats(
case 'n':
if (1 == sscanf(tag, name_fmt, &ui)) {
/* strip quotes */
- INSIST(val);
len = strlen(val);
if (len >= 2 &&
len - 2 < sizeof(row.name)) {
@@ -3607,11 +3621,9 @@ reslist(
fields = 0;
ui = 0;
while (nextvar(&dsize, &datap, &tag, &val)) {
+ INSIST(tag && val);
if (debug > 1)
- fprintf(stderr, "nextvar gave: %s = %s\n", tag,
- (NULL == val)
- ? ""
- : val);
+ fprintf(stderr, "nextvar gave: %s = %s\n", tag, val);
comprende = FALSE;
switch(tag[0]) {
@@ -3718,8 +3730,7 @@ collect_display_vdc(
* the retrieved values.
*/
while (nextvar(&rsize, &rdata, &tag, &val)) {
- if (NULL == val)
- continue;
+ INSIST(tag && val);
n = 0;
for (pvdc = table; pvdc->tag != NULL; pvdc++) {
len = strlen(pvdc->tag);
@@ -3944,9 +3955,9 @@ monstats(
)
{
static vdc monstats_vdc[] = {
- VDC_INIT("mru_enabled", "enabled: ", NTP_STR),
+ VDC_INIT("mru_enabled", "enabled: ", NTP_STR),
VDC_INIT("mru_depth", "addresses: ", NTP_STR),
- VDC_INIT("mru_deepest", "peak addresses: ", NTP_STR),
+ VDC_INIT("mru_deepest", "peak addresses: ", NTP_STR),
VDC_INIT("mru_maxdepth", "maximum addresses: ", NTP_STR),
VDC_INIT("mru_mindepth", "reclaim above count:", NTP_STR),
VDC_INIT("mru_maxage", "reclaim older than: ", NTP_STR),