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