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