PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/ntp/libntp/refnumtoa.c

https://bitbucket.org/freebsd/freebsd-head/
C | 36 lines | 27 code | 6 blank | 3 comment | 5 complexity | fe252dcbe84c937a72a0ec3c9ef54ee3 MD5 | raw file
 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
10char *
11refnumtoa(
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}