xref: /freebsd/contrib/ntp/libntp/refnumtoa.c (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
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 	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