154359Sroberto/*
254359Sroberto * numtoa - return asciized network numbers store in local array space
354359Sroberto */
4290000Sglebius#include <config.h>
5290000Sglebius
6290000Sglebius#include <sys/types.h>
7290000Sglebius#ifdef HAVE_NETINET_IN_H
8290000Sglebius#include <netinet/in.h>		/* ntohl */
9290000Sglebius#endif
10290000Sglebius
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);
27290000Sglebius	snprintf(buf, LIB_BUFLENGTH, "%lu.%lu.%lu.%lu",
28290000Sglebius		 ((u_long)netnum >> 24) & 0xff,
29290000Sglebius		 ((u_long)netnum >> 16) & 0xff,
30290000Sglebius		 ((u_long)netnum >> 8) & 0xff,
31290000Sglebius		 (u_long)netnum & 0xff);
3254359Sroberto	return buf;
3354359Sroberto}
34290000Sglebius
35290000Sglebius
36290000Sglebius/* Convert a refid & stratum to a string */
37290000Sglebiusconst char *
38290000Sglebiusrefid_str(
39290000Sglebius	u_int32	refid,
40290000Sglebius	int	stratum
41290000Sglebius	)
42290000Sglebius{
43290000Sglebius	char *	text;
44290000Sglebius	size_t	tlen;
45290000Sglebius
46290000Sglebius	if (stratum > 1)
47290000Sglebius		return numtoa(refid);
48290000Sglebius
49290000Sglebius	LIB_GETBUF(text);
50290000Sglebius	text[0] = '.';
51290000Sglebius	memcpy(&text[1], &refid, sizeof(refid));
52290000Sglebius	text[1 + sizeof(refid)] = '\0';
53290000Sglebius	tlen = strlen(text);
54290000Sglebius	text[tlen] = '.';
55290000Sglebius	text[tlen + 1] = '\0';
56290000Sglebius
57290000Sglebius	return text;
58290000Sglebius}
59290000Sglebius
60