FreeBSD/contrib/ntp/ntpq/ntpq-subs.c
/*
 * dogetassoc - query the host for its list of associations
 */
query the host for its list of associations
query the host for its list of associations
int
dogetassoc(
	FILE *fp
	)
{
	const char *datap;
	const u_short *pus;
	int res;
	size_t dsize;
	u_short rstatus;
	res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus,
			  &dsize, &datap);
	if (res != 0)
		return 0;
	if (dsize == 0) {
		if (numhosts > 1)
			fprintf(fp, "server=%s ", currenthost);
		fprintf(fp, "No association ID's returned\n");
		return 0;
	}
	if (dsize & 0x3) {
		if (numhosts > 1)
			fprintf(stderr, "server=%s ", currenthost);
		fprintf(stderr,
			"***Server returned %zu octets, should be multiple of 4\n",
			dsize);
		return 0;
	}
	numassoc = 0;
	while (dsize > 0) {
		if (numassoc >= assoc_cache_slots) {
			grow_assoc_cache();
		}
		pus = (const void *)datap;
		assoc_cache[numassoc].assid = ntohs(*pus);
		datap += sizeof(*pus);
		pus = (const void *)datap;
		assoc_cache[numassoc].status = ntohs(*pus);
		datap += sizeof(*pus);
		dsize -= 2 * sizeof(*pus);
		if (debug) {
			fprintf(stderr, "[%u] ",
				assoc_cache[numassoc].assid);
		}
		numassoc++;
	}
	if (debug) {
		fprintf(stderr, "\n%d associations total\n", numassoc);
	}
	sortassoc();
	return 1;
}
int dogetassoc ( FILE * fp ) { const char * datap ; const u_short * pus ; int res ; size_t dsize ; u_short rstatus ; res = doquery ( CTL_OP_READSTAT , 0 , 0 , 0 , ( char * ) 0 , & rstatus , & dsize , & datap ) ; if ( res != 0 ) return 0 ; if ( dsize == 0 ) { if ( numhosts > 1 ) fprintf ( fp , " " , currenthost ) ; fprintf ( fp , " \n " ) ; return 0 ; } if ( dsize & 0x3 ) { if ( numhosts > 1 ) fprintf ( stderr , " " , currenthost ) ; fprintf ( stderr , " \n " , dsize ) ; return 0 ; } numassoc = 0 ; while ( dsize > 0 ) { if ( numassoc >= assoc_cache_slots ) { grow_assoc_cache ( ) ; } pus = ( const void * ) datap ; assoc_cache [ numassoc ] . assid = ntohs ( * pus ) ; datap += sizeof ( * pus ) ; pus = ( const void * ) datap ; assoc_cache [ numassoc ] . status = ntohs ( * pus ) ; datap += sizeof ( * pus ) ; dsize -= 2 * sizeof ( * pus ) ; if ( debug ) { fprintf ( stderr , " " , assoc_cache [ numassoc ] . assid ) ; } numassoc ++ ; } if ( debug ) { fprintf ( stderr , " \n \n " , numassoc ) ; } sortassoc ( ) ; return 1 ; }
dogetassoc - query the host for its list of associations
dogetassoc - query the host for its list of associations