FreeBSD/contrib/ntp/ntpq/ntpq-subs.c
/*
 * printassoc - print the current list of associations
 */
print the current list of associations
print the current list of associations
static void
printassoc(
	int showall,
	FILE *fp
	)
{
	register char *bp;
	u_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;
	char buf[128];
	if (numassoc == 0) {
		(void) fprintf(fp, "No association ID's in list\n");
		return;
	}
	(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_BCAST) {
			reach = "none";
			if (statval & CTL_PST_AUTHENABLE)
				auth = "yes";
			else
				auth = "none";
		} else {
			if (statval & CTL_PST_REACH)
				reach = "yes";
			else
				reach = "no";
			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 = "outlier";
				break;
			case CTL_PST_SEL_SYNCCAND:
				condition = "candidate";
				break;
			case CTL_PST_SEL_EXCESS:
				condition = "backup";
				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;
			}
		}
		switch (PEER_EVENT|event) {
		case PEVNT_MOBIL:
			last_event = "mobilize";
			break;
		case PEVNT_DEMOBIL:
			last_event = "demobilize";
			break;
		case PEVNT_REACH:
			last_event = "reachable";
			break;
		case PEVNT_UNREACH:
			last_event = "unreachable";
			break;
		case PEVNT_RESTART:
			last_event = "restart";
			break;
		case PEVNT_REPLY:
			last_event = "no_reply";
			break;
		case PEVNT_RATE:
			last_event = "rate_exceeded";
			break;
		case PEVNT_DENY:
			last_event = "access_denied";
			break;
		case PEVNT_ARMED:
			last_event = "leap_armed";
			break;
		case PEVNT_NEWPEER:
			last_event = "sys_peer";
			break;
		case PEVNT_CLOCK:
			last_event = "clock_alarm";
			break;
		default:
			last_event = "";
			break;
		}
		snprintf(buf, sizeof(buf),
			 "%3d %5u  %04x   %3.3s  %4s  %4.4s %9.9s %11s %2lu",
			 i + 1, assoc_cache[i].assid,
			 assoc_cache[i].status, conf, reach, auth,
			 condition, last_event, event_count);
		bp = buf + strlen(buf);
		while (bp > buf && ' ' == bp[-1])
			--bp;
		bp[0] = '\0';
		fprintf(fp, "%s\n", buf);
	}
}
static void printassoc ( int showall , FILE * fp ) { register char * bp ; u_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 ; char buf [ 128 ] ; if ( numassoc == 0 ) { ( void ) fprintf ( fp , " \n " ) ; return ; } ( void ) fprintf ( fp , " \n \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 = " " ; else conf = " " ; if ( statval & CTL_PST_BCAST ) { reach = " " ; if ( statval & CTL_PST_AUTHENABLE ) auth = " " ; else auth = " " ; } else { if ( statval & CTL_PST_REACH ) reach = " " ; else reach = " " ; if ( statval & CTL_PST_AUTHENABLE ) { if ( statval & CTL_PST_AUTHENTIC ) auth = " " ; else auth = " " ; } else { auth = " " ; } } if ( pktversion > NTP_OLDVERSION ) { switch ( statval & 0x7 ) { case CTL_PST_SEL_REJECT : condition = " " ; break ; case CTL_PST_SEL_SANE : condition = " " ; break ; case CTL_PST_SEL_CORRECT : condition = " " ; break ; case CTL_PST_SEL_SELCAND : condition = " " ; break ; case CTL_PST_SEL_SYNCCAND : condition = " " ; break ; case CTL_PST_SEL_EXCESS : condition = " " ; break ; case CTL_PST_SEL_SYSPEER : condition = " " ; break ; case CTL_PST_SEL_PPS : condition = " " ; break ; } } else { switch ( statval & 0x3 ) { case OLD_CTL_PST_SEL_REJECT : if ( ! ( statval & OLD_CTL_PST_SANE ) ) condition = " " ; else if ( ! ( statval & OLD_CTL_PST_DISP ) ) condition = " " ; else condition = " " ; break ; case OLD_CTL_PST_SEL_SELCAND : condition = " " ; break ; case OLD_CTL_PST_SEL_SYNCCAND : condition = " " ; break ; case OLD_CTL_PST_SEL_SYSPEER : condition = " " ; break ; } } switch ( PEER_EVENT | event ) { case PEVNT_MOBIL : last_event = " " ; break ; case PEVNT_DEMOBIL : last_event = " " ; break ; case PEVNT_REACH : last_event = " " ; break ; case PEVNT_UNREACH : last_event = " " ; break ; case PEVNT_RESTART : last_event = " " ; break ; case PEVNT_REPLY : last_event = " " ; break ; case PEVNT_RATE : last_event = " " ; break ; case PEVNT_DENY : last_event = " " ; break ; case PEVNT_ARMED : last_event = " " ; break ; case PEVNT_NEWPEER : last_event = " " ; break ; case PEVNT_CLOCK : last_event = " " ; break ; default : last_event = " " ; break ; } snprintf ( buf , sizeof ( buf ) , " " , i + 1 , assoc_cache [ i ] . assid , assoc_cache [ i ] . status , conf , reach , auth , condition , last_event , event_count ) ; bp = buf + strlen ( buf ) ; while ( bp > buf && ' ' == bp [ -1 ] ) -- bp ; bp [ 0 ] = ' \0 ' ; fprintf ( fp , " \n " , buf ) ; } }
printassoc - print the current list of associations
printassoc - print the current list of associations
/*
	 * Output a header
	 */