コード例 #1
0
ファイル: libntpq.c プロジェクト: pexip/os-ntp
/*****************************************************************************
 *  
 *  ntpq_get_assoc_clocktype
 *
 *  This function returns a clocktype value for a given association number 
 *  (not ID!):
 *
 *  NTP_CLOCKTYPE_UNKNOWN   Unknown clock type
 *  NTP_CLOCKTYPE_BROADCAST Broadcast server
 *  NTP_CLOCKTYPE_LOCAL     Local clock
 *  NTP_CLOCKTYPE_UNICAST   Unicast server
 *  NTP_CLOCKTYPE_MULTICAST Multicast server
 * 
 ****************************************************************************/
int ntpq_get_assoc_clocktype ( associd_t assoc_number )
{
	int type = 0;
	int i, rc = 0;
	sockaddr_u dum_store;
	char value[LENHOSTNAME];
	char resultbuf[1024];

	if ( assoc_number < 0 || assoc_number > numassoc )
		return -1;
	if ( peervar_assoc != assoc_cache[assoc_number].assid ) {
		i = ntpq_read_assoc_peervars(
		    assoc_cache[assoc_number].assid, resultbuf,
		    sizeof(resultbuf));
		if ( i <= 0 )
			return -1;
		rc = ntpq_getvar(resultbuf, i, "dstadr", value,
				 LENHOSTNAME );
	} else {
		rc = ntpq_get_peervar("dstadr",value,LENHOSTNAME);
	}

	if (0 != rc && decodenetnum(value, &dum_store)) {
		type = ntpq_decodeaddrtype(&dum_store);
		return type;
	}
	return -1;
}
コード例 #2
0
ファイル: libntpq.c プロジェクト: jaredmcneill/netbsd-src
/*****************************************************************************
 *  
 *  ntpq_get_assoc_clocktype
 *
 *  This function returns a clocktype value for a given association number 
 *  (not ID!):
 *
 *  NTP_CLOCKTYPE_UNKNOWN   Unknown clock type
 *  NTP_CLOCKTYPE_BROADCAST Broadcast server
 *  NTP_CLOCKTYPE_LOCAL     Local clock
 *  NTP_CLOCKTYPE_UNICAST   Unicast server
 *  NTP_CLOCKTYPE_MULTICAST Multicast server
 * 
 ****************************************************************************/
int
ntpq_get_assoc_clocktype(
	int assoc_index
	)
{
	associd_t	associd;
	int		i;
	int		rc;
	sockaddr_u	dum_store;
	char		dstadr[LENHOSTNAME];
	char		resultbuf[NTPQ_BUFLEN];

	if (assoc_index < 0 || assoc_index >= numassoc)
		return -1;

	associd = assoc_cache[assoc_index].assid;
	if (associd == peervar_assoc) {
		rc = ntpq_get_peervar("dstadr", dstadr, sizeof(dstadr));
	} else {
		i = ntpq_read_assoc_peervars(associd, resultbuf,
					     sizeof(resultbuf));
		if (i <= 0)
			return -1;
		rc = ntpq_getvar(resultbuf, i, "dstadr", dstadr,
				 sizeof(dstadr));
	}

	if (0 != rc && decodenetnum(dstadr, &dum_store))
		return ntpq_decodeaddrtype(&dum_store);

	return -1;
}
コード例 #3
0
ファイル: libntpq.c プロジェクト: pexip/os-ntp
int
ntpq_read_assoc_peervars(
	associd_t associd,
	char *resultbuf,
	int maxsize
	)
{
	const char *datap;
	int res;
	int dsize;
	u_short rstatus;
	l_fp rec;
	l_fp ts;
	char value[NTPQ_BUFLEN];


	res = doquery(CTL_OP_READVAR, associd, 0, 0, NULL, &rstatus,
		      &dsize, &datap);

	if (res != 0)
		return 0;

	get_systime(&ts);

	if (dsize == 0) {
		if (numhosts > 1)
			fprintf(stderr, "server=%s ", currenthost);
		fprintf(stderr,
			"***No information returned for association %d\n",
			associd);
		return 0;
	} else {
		if ( dsize > maxsize ) 
			dsize = maxsize;
		memcpy(resultbuf, datap, dsize);
		resultbuf[dsize] = '\0';
 
		ntpq_getvar(resultbuf, dsize, "rec", value,
			    sizeof(value));

		if (!decodets(value, &rec))
			L_CLR(&rec);

		memcpy(resultbuf, value, maxsize);
		resultbuf[dsize] = '\0';
		dsize = strlen(resultbuf);
	}

	return dsize;
}
コード例 #4
0
size_t
read_ntp_value(
	const char *	variable,
	char *		value,
	size_t		valuesize
	)
{
	size_t	sv_len;
	char	sv_data[NTPQ_BUFLEN];
	
	memset(sv_data, 0, sizeof(sv_data));
	sv_len = ntpq_read_sysvars(sv_data, sizeof(sv_data));

	if (0 == sv_len)
		return 0;
	else
		return ntpq_getvar(sv_data, sv_len, variable, value,
				   valuesize);
}
コード例 #5
0
ファイル: libntpq.c プロジェクト: pexip/os-ntp
/*****************************************************************************
 *  
 *  ntp_get_peervar
 *
 *  This function uses the variable-set which was read by using 
 *  ntp_get_peervars and searches for a variable specified with varname. If 
 *  such a variable exists, it writes its value into
 *  varvalue (maxlen specifies the size of this target buffer).
 *  
 ****************************************************************************
 * Parameters:
 *	varname		char*	requested variable name
 *	varvalue	char*	the buffer where the value should go into
 *	maxlen		int	maximum number of bytes that can be copied to
 *				varvalue
 *
 * Returns:
 *	int		number of bytes copied to varvalue
 * 			- OR - 
 *			0 (zero) if an error occured or the variable could 
 *			not be found
 ****************************************************************************/
int ntpq_get_peervar( const char *varname, char *varvalue, int maxlen)
{
    return ( ntpq_getvar(peervars,peervarlen,varname,varvalue,maxlen) );
}