xref: /netbsd-src/external/bsd/ntp/dist/libntp/numtoa.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: numtoa.c,v 1.1.1.1 2009/12/13 16:55:04 kardel Exp $	*/
2 
3 /*
4  * numtoa - return asciized network numbers store in local array space
5  */
6 #include <config.h>
7 
8 #include <sys/types.h>
9 #ifdef HAVE_NETINET_IN_H
10 #include <netinet/in.h>		/* ntohl */
11 #endif
12 
13 #include <stdio.h>
14 
15 #include "ntp_fp.h"
16 #include "lib_strbuf.h"
17 #include "ntp_stdlib.h"
18 
19 char *
20 numtoa(
21 	u_int32 num
22 	)
23 {
24 	register u_int32 netnum;
25 	register char *buf;
26 
27 	netnum = ntohl(num);
28 	LIB_GETBUF(buf);
29 	snprintf(buf, LIB_BUFLENGTH, "%lu.%lu.%lu.%lu",
30 		 ((u_long)netnum >> 24) & 0xff,
31 		 ((u_long)netnum >> 16) & 0xff,
32 		 ((u_long)netnum >> 8) & 0xff,
33 		 (u_long)netnum & 0xff);
34 	return buf;
35 }
36