xref: /freebsd/contrib/ntp/libntp/refnumtoa.c (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1 /*
2  * refnumtoa - return asciized refclock addresses stored in local array space
3  */
4 #include <stdio.h>
5 
6 #include "ntp_fp.h"
7 #include "lib_strbuf.h"
8 #include "ntp_stdlib.h"
9 
10 char *
11 refnumtoa(
12 	struct sockaddr_storage* num
13 	)
14 {
15 	register u_int32 netnum;
16 	register char *buf;
17 	register const char *rclock;
18 
19 	LIB_GETBUF(buf);
20 
21 	if(num->ss_family == AF_INET) {
22 		netnum = ntohl(((struct sockaddr_in*)num)->sin_addr.s_addr);
23 		rclock = clockname((int)((u_long)netnum >> 8) & 0xff);
24 
25 		if (rclock != NULL)
26 		    (void)sprintf(buf, "%s(%lu)", rclock, (u_long)netnum & 0xff);
27 		else
28 	    	(void)sprintf(buf, "REFCLK(%lu,%lu)",
29 				  ((u_long)netnum >> 8) & 0xff, (u_long)netnum & 0xff);
30 
31 	}
32 	else {
33 		(void)sprintf(buf, "refclock address type not implemented yet, use IPv4 refclock address.");
34 	}
35 	return buf;
36 }
37