xref: /freebsd/contrib/ntp/libntp/refnumtoa.c (revision f5f40dd63bc7acbb5312b26ac1ea1103c12352a6)
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 "ntp_stdlib.h"
9 
10 const char *
11 refnumtoa(
12 	const sockaddr_u *num
13 	)
14 {
15 	u_int32 netnum;
16 	char *buf;
17 	const char *rclock;
18 
19 	if (!ISREFCLOCKADR(num))
20 		return socktoa(num);
21 
22 	LIB_GETBUF(buf);
23 	netnum = SRCADR(num);
24 	rclock = clockname((int)((u_long)netnum >> 8) & 0xff);
25 
26 	if (rclock != NULL)
27 		snprintf(buf, LIB_BUFLENGTH, "%s(%lu)",
28 			 rclock, (u_long)netnum & 0xff);
29 	else
30 		snprintf(buf, LIB_BUFLENGTH, "REFCLK(%lu,%lu)",
31 			 ((u_long)netnum >> 8) & 0xff,
32 			 (u_long)netnum & 0xff);
33 
34 	return buf;
35 }
36