154359Sroberto/*
254359Sroberto * numtoa - return asciized network numbers store in local array space
354359Sroberto */
4285612Sdelphij#include <config.h>
5285612Sdelphij
6285612Sdelphij#include <sys/types.h>
7285612Sdelphij#ifdef HAVE_NETINET_IN_H
8285612Sdelphij#include <netinet/in.h>		/* ntohl */
9285612Sdelphij#endif
10285612Sdelphij
1154359Sroberto#include <stdio.h>
1254359Sroberto
1354359Sroberto#include "ntp_fp.h"
1454359Sroberto#include "lib_strbuf.h"
1554359Sroberto#include "ntp_stdlib.h"
1654359Sroberto
1754359Srobertochar *
1854359Srobertonumtoa(
1954359Sroberto	u_int32 num
2054359Sroberto	)
2154359Sroberto{
2254359Sroberto	register u_int32 netnum;
2354359Sroberto	register char *buf;
2454359Sroberto
2554359Sroberto	netnum = ntohl(num);
2654359Sroberto	LIB_GETBUF(buf);
27285612Sdelphij	snprintf(buf, LIB_BUFLENGTH, "%lu.%lu.%lu.%lu",
28285612Sdelphij		 ((u_long)netnum >> 24) & 0xff,
29285612Sdelphij		 ((u_long)netnum >> 16) & 0xff,
30285612Sdelphij		 ((u_long)netnum >> 8) & 0xff,
31285612Sdelphij		 (u_long)netnum & 0xff);
3254359Sroberto	return buf;
3354359Sroberto}
34285612Sdelphij
35285612Sdelphij
36285612Sdelphij/* Convert a refid & stratum to a string */
37285612Sdelphijconst char *
38285612Sdelphijrefid_str(
39285612Sdelphij	u_int32	refid,
40285612Sdelphij	int	stratum
41285612Sdelphij	)
42285612Sdelphij{
43285612Sdelphij	char *	text;
44285612Sdelphij	size_t	tlen;
45285612Sdelphij
46285612Sdelphij	if (stratum > 1)
47285612Sdelphij		return numtoa(refid);
48285612Sdelphij
49285612Sdelphij	LIB_GETBUF(text);
50285612Sdelphij	text[0] = '.';
51285612Sdelphij	memcpy(&text[1], &refid, sizeof(refid));
52285612Sdelphij	text[1 + sizeof(refid)] = '\0';
53285612Sdelphij	tlen = strlen(text);
54285612Sdelphij	text[tlen] = '.';
55285612Sdelphij	text[tlen + 1] = '\0';
56285612Sdelphij
57285612Sdelphij	return text;
58285612Sdelphij}
59285612Sdelphij
60