📄 ntpq_ops.c
字号:
return; } res = doquerylist(varlist, CTL_OP_WRITEVAR, associd, 1, &rstatus, &dsize, &datap); if (res != 0) return; if (numhosts > 1) (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) (void) fprintf(fp, "done! (no data returned)\n"); else { (void) fprintf(fp,"assID=%d ",associd); printvars(dsize, datap, (int)rstatus, (associd != 0) ? TYPE_PEER : TYPE_SYS, fp); } return;}/* * readvar - send a read variables request with the specified variables */static voidreadvar( struct parse *pcmd, FILE *fp ){ int associd; struct varlist tmplist[MAXLIST]; /* HMS: uval? */ if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0) associd = 0; else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) return; memset((char *)tmplist, 0, sizeof(tmplist)); if (pcmd->nargs >= 2) doaddvlist(tmplist, pcmd->argval[1].string); (void) dolist(tmplist, associd, CTL_OP_READVAR, (associd == 0) ? TYPE_SYS : TYPE_PEER, fp); doclearvlist(tmplist);}/* * writevar - send a write variables request with the specified variables */static voidwritevar( struct parse *pcmd, FILE *fp ){ char *datap; int res; int associd; int dsize; u_short rstatus; struct varlist tmplist[MAXLIST]; /* HMS: uval? */ if (pcmd->argval[0].uval == 0) associd = 0; else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) return; memset((char *)tmplist, 0, sizeof(tmplist)); doaddvlist(tmplist, pcmd->argval[1].string); res = doquerylist(tmplist, CTL_OP_WRITEVAR, associd, 1, &rstatus, &dsize, &datap); doclearvlist(tmplist); if (res != 0) return; if (numhosts > 1) (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) (void) fprintf(fp, "done! (no data returned)\n"); else { (void) fprintf(fp,"assID=%d ",associd); printvars(dsize, datap, (int)rstatus, (associd != 0) ? TYPE_PEER : TYPE_SYS, fp); } return;}/* * clocklist - send a clock variables request with the variables on the list */static voidclocklist( struct parse *pcmd, FILE *fp ){ int associd; /* HMS: uval? */ if (pcmd->nargs == 0) { associd = 0; } else { if (pcmd->argval[0].uval == 0) associd = 0; else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) return; } (void) dolist(varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);}/* * clockvar - send a clock variables request with the specified variables */static voidclockvar( struct parse *pcmd, FILE *fp ){ int associd; struct varlist tmplist[MAXLIST]; /* HMS: uval? */ if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0) associd = 0; else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) return; memset((char *)tmplist, 0, sizeof(tmplist)); if (pcmd->nargs >= 2) doaddvlist(tmplist, pcmd->argval[1].string); (void) dolist(tmplist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp); doclearvlist(tmplist);}/* * findassidrange - verify a range of association ID's */static intfindassidrange( u_int32 assid1, u_int32 assid2, int *from, int *to ){ register int i; int f, t; if (assid1 == 0 || assid1 > 65535) { (void) fprintf(stderr, "***Invalid association ID %lu specified\n", (u_long)assid1); return 0; } if (assid2 == 0 || assid2 > 65535) { (void) fprintf(stderr, "***Invalid association ID %lu specified\n", (u_long)assid2); return 0; } f = t = -1; for (i = 0; i < numassoc; i++) { if (assoc_cache[i].assid == assid1) { f = i; if (t != -1) break; } if (assoc_cache[i].assid == assid2) { t = i; if (f != -1) break; } } if (f == -1 || t == -1) { (void) fprintf(stderr, "***Association ID %lu not found in list\n", (f == -1) ? (u_long)assid1 : (u_long)assid2); return 0; } if (f < t) { *from = f; *to = t; } else { *from = t; *to = f; } return 1;}/* * mreadlist - send a read variables request for multiple associations */static voidmreadlist( struct parse *pcmd, FILE *fp ){ int i; int from; int to; /* HMS: uval? */ if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval, &from, &to)) return; for (i = from; i <= to; i++) { if (i != from) (void) fprintf(fp, "\n"); if (!dolist(varlist, (int)assoc_cache[i].assid, CTL_OP_READVAR, TYPE_PEER, fp)) return; } return;}/* * mreadvar - send a read variables request for multiple associations */static voidmreadvar( struct parse *pcmd, FILE *fp ){ int i; int from; int to; struct varlist tmplist[MAXLIST]; /* HMS: uval? */ if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval, &from, &to)) return; memset((char *)tmplist, 0, sizeof(tmplist)); if (pcmd->nargs >= 3) doaddvlist(tmplist, pcmd->argval[2].string); for (i = from; i <= to; i++) { if (i != from) (void) fprintf(fp, "\n"); if (!dolist(varlist, (int)assoc_cache[i].assid, CTL_OP_READVAR, TYPE_PEER, fp)) break; } doclearvlist(tmplist); return;}/* * dogetassoc - query the host for its list of associations */static intdogetassoc( FILE *fp ){ u_short *datap; int res; int dsize; u_short rstatus; res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus, &dsize, (char **)&datap); if (res != 0) return 0; if (dsize == 0) { if (numhosts > 1) (void) fprintf(fp, "server=%s ", currenthost); (void) fprintf(fp, "No association ID's returned\n"); return 0; } if (dsize & 0x3) { if (numhosts > 1) (void) fprintf(stderr, "server=%s ", currenthost); (void) fprintf(stderr, "***Server returned %d octets, should be multiple of 4\n", dsize); return 0; } numassoc = 0; while (dsize > 0) { assoc_cache[numassoc].assid = ntohs(*datap); datap++; assoc_cache[numassoc].status = ntohs(*datap); datap++; if (++numassoc >= MAXASSOC) break; dsize -= sizeof(u_short) + sizeof(u_short); } sortassoc(); return 1;}/* * printassoc - print the current list of associations */static voidprintassoc( int showall, FILE *fp ){ register char *bp; int i; u_char statval; int event; u_long event_count; const char *conf; const char *reach; const char *auth; const char *condition = ""; const char *last_event; const char *cnt; char buf[128]; if (numassoc == 0) { (void) fprintf(fp, "No association ID's in list\n"); return; } /* * Output a header */ (void) fprintf(fp, "\nind assID status conf reach auth condition last_event cnt\n"); (void) fprintf(fp, "===========================================================\n"); for (i = 0; i < numassoc; i++) { statval = (u_char) CTL_PEER_STATVAL(assoc_cache[i].status); if (!showall && !(statval & (CTL_PST_CONFIG|CTL_PST_REACH))) continue; event = CTL_PEER_EVENT(assoc_cache[i].status); event_count = CTL_PEER_NEVNT(assoc_cache[i].status); if (statval & CTL_PST_CONFIG) conf = "yes"; else conf = "no"; if (statval & CTL_PST_REACH || 1) { reach = "yes"; if (statval & CTL_PST_AUTHENABLE) { if (statval & CTL_PST_AUTHENTIC) auth = "ok "; else auth = "bad"; } else auth = "none"; if (pktversion > NTP_OLDVERSION) switch (statval & 0x7) { case CTL_PST_SEL_REJECT: condition = "reject"; break; case CTL_PST_SEL_SANE: condition = "falsetick"; break; case CTL_PST_SEL_CORRECT: condition = "excess"; break; case CTL_PST_SEL_SELCAND: condition = "outlyer"; break; case CTL_PST_SEL_SYNCCAND: condition = "candidat"; break; case CTL_PST_SEL_DISTSYSPEER: condition = "selected"; break; case CTL_PST_SEL_SYSPEER: condition = "sys.peer"; break; case CTL_PST_SEL_PPS: condition = "pps.peer"; break; } else switch (statval & 0x3) { case OLD_CTL_PST_SEL_REJECT: if (!(statval & OLD_CTL_PST_SANE)) condition = "insane"; else if (!(statval & OLD_CTL_PST_DISP)) condition = "hi_disp"; else condition = ""; break; case OLD_CTL_PST_SEL_SELCAND: condition = "sel_cand"; break; case OLD_CTL_PST_SEL_SYNCCAND: condition = "sync_cand"; break; case OLD_CTL_PST_SEL_SYSPEER: condition = "sys_peer"; break; } } else { reach = "no"; auth = condition = ""; } switch (PEER_EVENT|event) { case EVNT_PEERIPERR: last_event = "IP error"; break; case EVNT_PEERAUTH: last_event = "auth fail"; break; case EVNT_UNREACH: last_event = "lost reach"; break; case EVNT_REACH: last_event = "reachable"; break; case EVNT_PEERCLOCK: last_event = "clock expt"; break;#if 0 case EVNT_PEERSTRAT: last_event = "stratum chg"; break;#endif default: last_event = ""; break; } if (event_count != 0) cnt = uinttoa(event_count); else cnt = ""; (void) sprintf(buf, "%3d %5u %04x %3.3s %4s %4.4s %9.9s %11s %2s", i+1, assoc_cache[i].assid, assoc_cache[i].status, conf, reach, auth, condition, last_event, cnt); bp = &buf[strlen(buf)]; while (bp > buf && *(bp-1) == ' ') *(--bp) = '\0'; (void) fprintf(fp, "%s\n", buf); }}/* * associations - get, record and print a list of associations *//*ARGSUSED*/static voidassociations( struct parse *pcmd, FILE *fp ){ if (dogetassoc(fp)) printassoc(0, fp);}/* * lassociations - get, record and print a long list of associations *//*ARGSUSED*/static voidlassociations( struct parse *pcmd, FILE *fp ){ if (dogetassoc(fp)) printassoc(1, fp);}/* * passociations - print the association list *//*ARGSUSED*/static voidpassociations( struct parse *pcmd, FILE *fp ){ printassoc(0, fp);}/* * lpassociations - print the long association list *//*ARGSUSED*/static voidlpassociations( struct parse *pcmd, FILE *fp ){ printassoc(1, fp);}#ifdef UNUSED/* * radiostatus - print the radio status returned by the server *//*ARGSUSED*/static voidradiostatus( struct parse *pcmd, FILE *fp ){ char *datap; int res; int dsize; u_short rstatus; res = doquery(CTL_OP_READCLOCK, 0, 0, 0, (char *)0, &rstatus, &dsize, &datap); if (res != 0) return; if (numhosts > 1) (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) { (void) fprintf(fp, "No radio status string returned\n"); return; } asciize(dsize, datap, fp);}#endif /* UNUSED *//* * pstatus - print peer status returned by the server */static voidpstatus( struct parse *pcmd, FILE *fp ){ char *datap; int res; int associd; int dsize; u_short rstatus; /* HMS: uval? */ if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) return; res = doquery(CTL_OP_READSTAT, associd, 0, 0, (char *)0, &rstatus, &dsize, &datap); if (res != 0) return; if (numhosts > 1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -