xref: /freebsd/contrib/ntp/libntp/numtoa.c (revision c0b746e5e8d9479f05b3749cbf1f73b8928719bd)
1c0b746e5SOllivier Robert /*
2c0b746e5SOllivier Robert  * numtoa - return asciized network numbers store in local array space
3c0b746e5SOllivier Robert  */
4c0b746e5SOllivier Robert #include <stdio.h>
5c0b746e5SOllivier Robert 
6c0b746e5SOllivier Robert #include "ntp_fp.h"
7c0b746e5SOllivier Robert #include "lib_strbuf.h"
8c0b746e5SOllivier Robert #include "ntp_stdlib.h"
9c0b746e5SOllivier Robert 
10c0b746e5SOllivier Robert char *
11c0b746e5SOllivier Robert numtoa(
12c0b746e5SOllivier Robert 	u_int32 num
13c0b746e5SOllivier Robert 	)
14c0b746e5SOllivier Robert {
15c0b746e5SOllivier Robert 	register u_int32 netnum;
16c0b746e5SOllivier Robert 	register char *buf;
17c0b746e5SOllivier Robert 
18c0b746e5SOllivier Robert 	netnum = ntohl(num);
19c0b746e5SOllivier Robert 	LIB_GETBUF(buf);
20c0b746e5SOllivier Robert 	(void) sprintf(buf, "%lu.%lu.%lu.%lu", ((u_long)netnum >> 24) & 0xff,
21c0b746e5SOllivier Robert 		       ((u_long)netnum >> 16) & 0xff, ((u_long)netnum >> 8) & 0xff,
22c0b746e5SOllivier Robert 		       (u_long)netnum & 0xff);
23c0b746e5SOllivier Robert 	return buf;
24c0b746e5SOllivier Robert }
25