154359Sroberto/*
254359Sroberto * numtoa - return asciized network numbers store in local array space
354359Sroberto */
4280849Scy#include <config.h>
5280849Scy
6280849Scy#include <sys/types.h>
7280849Scy#ifdef HAVE_NETINET_IN_H
8280849Scy#include <netinet/in.h>		/* ntohl */
9280849Scy#endif
10280849Scy
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);
27280849Scy	snprintf(buf, LIB_BUFLENGTH, "%lu.%lu.%lu.%lu",
28280849Scy		 ((u_long)netnum >> 24) & 0xff,
29280849Scy		 ((u_long)netnum >> 16) & 0xff,
30280849Scy		 ((u_long)netnum >> 8) & 0xff,
31280849Scy		 (u_long)netnum & 0xff);
3254359Sroberto	return buf;
3354359Sroberto}
34280849Scy
35280849Scy
36280849Scy/* Convert a refid & stratum to a string */
37280849Scyconst char *
38280849Scyrefid_str(
39280849Scy	u_int32	refid,
40280849Scy	int	stratum
41280849Scy	)
42280849Scy{
43280849Scy	char *	text;
44280849Scy	size_t	tlen;
45280849Scy
46280849Scy	if (stratum > 1)
47280849Scy		return numtoa(refid);
48280849Scy
49280849Scy	LIB_GETBUF(text);
50280849Scy	text[0] = '.';
51280849Scy	memcpy(&text[1], &refid, sizeof(refid));
52280849Scy	text[1 + sizeof(refid)] = '\0';
53280849Scy	tlen = strlen(text);
54280849Scy	text[tlen] = '.';
55280849Scy	text[tlen + 1] = '\0';
56280849Scy
57280849Scy	return text;
58280849Scy}
59280849Scy
60