Sync usage with man page.
[netbsd-mini2440.git] / dist / ntp / libntp / numtohost.c
blobac4425f110e2d2f5c0357d9b68074cae2f9cc939
1 /* $NetBSD: numtohost.c,v 1.2 2003/12/04 16:23:37 drochner Exp $ */
3 /*
4 * numtohost - convert network number to host name.
5 */
7 #include "ntp_fp.h"
8 #include "ntp_stdlib.h"
9 #include "lib_strbuf.h"
11 #define LOOPBACKNET 0x7f000000
12 #define LOOPBACKHOST 0x7f000001
13 #define LOOPBACKNETMASK 0xff000000
15 char *
16 numtohost(
17 u_int32 netnum
20 char *bp;
21 struct hostent *hp;
24 * This is really gross, but saves lots of hanging looking for
25 * hostnames for the radio clocks. Don't bother looking up
26 * addresses on the loopback network except for the loopback
27 * host itself.
29 if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET)
30 && (ntohl(netnum) != LOOPBACKHOST))
31 || ((hp = gethostbyaddr((char *)&netnum, sizeof netnum, AF_INET))
32 == 0))
33 return numtoa(netnum);
35 LIB_GETBUF(bp);
37 bp[LIB_BUFLENGTH-1] = '\0';
38 (void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1);
39 return bp;