FreeBSD/contrib/ntp/ntpq/ntpq-subs.c
/*
 * reslist - ntpq -c reslist modeled on ntpdc -c reslist.
 */
c reslist modeled on ntpdc -c reslist.
c reslist modeled on ntpdc - c reslist .
static void 
reslist(
	struct parse *	pcmd,
	FILE *		fp
	)
{
	const char addr_fmtu[] =	"addr.%u";
	const char mask_fmtu[] =	"mask.%u";
	const char hits_fmt[] =		"hits.%u";
	const char flags_fmt[] =	"flags.%u";
	const char qdata[] =		"addr_restrictions";
	const int qdata_chars =		COUNTOF(qdata) - 1;
	const char *	datap;
	int		qres;
	size_t		dsize;
	u_short		rstatus;
	char *		tag;
	char *		val;
	int		fields;
	u_int		ui;
	reslist_row	row;
	int		comprende;
	size_t		len;
	qres = doquery(CTL_OP_READ_ORDLIST_A, 0, TRUE, qdata_chars,
		       qdata, &rstatus, &dsize, &datap);
	if (qres)	
		return;
	fprintf(fp,
		"   hits    addr/prefix or addr mask\n"
		"           restrictions\n"
		"==============================================================================\n");
	ZERO(row);
	fields = 0;
	ui = 0;
	while (nextvar(&dsize, &datap, &tag, &val)) {
		if (debug > 1)
			fprintf(stderr, "nextvar gave: %s = %s\n", tag,
				(NULL == val)
				    ? ""
				    : val);
		comprende = FALSE;
		switch(tag[0]) {
		case 'a':
			if (1 == sscanf(tag, addr_fmtu, &ui) &&
			    decodenetnum(val, &row.addr))
				comprende = TRUE;
			break;
		case 'f':
			if (1 == sscanf(tag, flags_fmt, &ui)) {
				if (NULL == val) {
					row.flagstr[0] = '\0';
					comprende = TRUE;
				} else {
					len = strlen(val);
					memcpy(row.flagstr, val, len);
					row.flagstr[len] = '\0';
					comprende = TRUE;
				}
			}
			break;
		case 'h':
			if (1 == sscanf(tag, hits_fmt, &ui) &&
			    1 == sscanf(val, "%lu", &row.hits))
				comprende = TRUE;
			break;
		case 'm':
			if (1 == sscanf(tag, mask_fmtu, &ui) &&
			    decodenetnum(val, &row.mask))
				comprende = TRUE;
			break;
		}
		if (comprende) {
			validate_reslist_idx(fp, ui, &fields, &row);
			another_reslist_field(&fields, &row, fp);
		}
	}
	if (fields != RESLIST_FIELDS)
		fprintf(fp, "Warning: incomplete row with %d (of %d) fields",
			fields, RESLIST_FIELDS);
	fflush(fp);
}
static void reslist ( struct parse * pcmd , FILE * fp ) { const char addr_fmtu [ ] = " " ; const char mask_fmtu [ ] = " " ; const char hits_fmt [ ] = " " ; const char flags_fmt [ ] = " " ; const char qdata [ ] = " " ; const int qdata_chars = COUNTOF ( qdata ) - 1 ; const char * datap ; int qres ; size_t dsize ; u_short rstatus ; char * tag ; char * val ; int fields ; u_int ui ; reslist_row row ; int comprende ; size_t len ; qres = doquery ( CTL_OP_READ_ORDLIST_A , 0 , TRUE , qdata_chars , qdata , & rstatus , & dsize , & datap ) ; if ( qres ) return ; fprintf ( fp , " \n " " \n " " \n " ) ; ZERO ( row ) ; fields = 0 ; ui = 0 ; while ( nextvar ( & dsize , & datap , & tag , & val ) ) { if ( debug > 1 ) fprintf ( stderr , " \n " , tag , ( NULL == val ) ? " " : val ) ; comprende = FALSE ; switch ( tag [ 0 ] ) { case ' ' : if ( 1 == sscanf ( tag , addr_fmtu , & ui ) && decodenetnum ( val , & row . addr ) ) comprende = TRUE ; break ; case ' ' : if ( 1 == sscanf ( tag , flags_fmt , & ui ) ) { if ( NULL == val ) { row . flagstr [ 0 ] = ' \0 ' ; comprende = TRUE ; } else { len = strlen ( val ) ; memcpy ( row . flagstr , val , len ) ; row . flagstr [ len ] = ' \0 ' ; comprende = TRUE ; } } break ; case ' ' : if ( 1 == sscanf ( tag , hits_fmt , & ui ) && 1 == sscanf ( val , " " , & row . hits ) ) comprende = TRUE ; break ; case ' ' : if ( 1 == sscanf ( tag , mask_fmtu , & ui ) && decodenetnum ( val , & row . mask ) ) comprende = TRUE ; break ; } if ( comprende ) { validate_reslist_idx ( fp , ui , & fields , & row ) ; another_reslist_field ( & fields , & row , fp ) ; } } if ( fields != RESLIST_FIELDS ) fprintf ( fp , " " , fields , RESLIST_FIELDS ) ; fflush ( fp ) ; }
reslist - ntpq -c reslist modeled on ntpdc -c reslist.
reslist - ntpq - c reslist modeled on ntpdc - c reslist .
/* message already displayed */ /* '=' x 78 */ /* error out if rows out of order */ /* if the row is complete, print it */