xref: /freebsd/contrib/ntp/libntp/refnumtoa.c (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*
2  * refnumtoa - return asciized refclock addresses stored in local array space
3  */
4 #include <config.h>
5 #include <stdio.h>
6 
7 #include "ntp_net.h"
8 #include "lib_strbuf.h"
9 #include "ntp_stdlib.h"
10 
11 const char *
12 refnumtoa(
13 	const sockaddr_u *num
14 	)
15 {
16 	u_int32 netnum;
17 	char *buf;
18 	const char *rclock;
19 
20 	if (!ISREFCLOCKADR(num))
21 		return socktoa(num);
22 
23 	LIB_GETBUF(buf);
24 	netnum = SRCADR(num);
25 	rclock = clockname((int)((u_long)netnum >> 8) & 0xff);
26 
27 	if (rclock != NULL)
28 		snprintf(buf, LIB_BUFLENGTH, "%s(%lu)",
29 			 rclock, (u_long)netnum & 0xff);
30 	else
31 		snprintf(buf, LIB_BUFLENGTH, "REFCLK(%lu,%lu)",
32 			 ((u_long)netnum >> 8) & 0xff,
33 			 (u_long)netnum & 0xff);
34 
35 	return buf;
36 }
37