]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ntp/libntp/numtohost.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ntp / libntp / numtohost.c
1 /*
2  * numtohost - convert network number to host name.
3  */
4
5 #include "ntp_fp.h"
6 #include "ntp_stdlib.h"
7 #include "lib_strbuf.h"
8
9 #define LOOPBACKNET     0x7f000000
10 #define LOOPBACKHOST    0x7f000001
11 #define LOOPBACKNETMASK 0xff000000
12
13 char *
14 numtohost(
15         u_int32 netnum
16         )
17 {
18         char *bp;
19         struct hostent *hp;
20
21         /*
22          * This is really gross, but saves lots of hanging looking for
23          * hostnames for the radio clocks.  Don't bother looking up
24          * addresses on the loopback network except for the loopback
25          * host itself.
26          */
27         if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET)
28              && (ntohl(netnum) != LOOPBACKHOST))
29             || ((hp = gethostbyaddr((char *)&netnum, sizeof netnum, AF_INET))
30                 == 0))
31             return numtoa(netnum);
32         
33         LIB_GETBUF(bp);
34         
35         bp[LIB_BUFLENGTH-1] = '\0';
36         (void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1);
37         return bp;
38 }