diff options
Diffstat (limited to 'usr.sbin/xntpd/lib/numtohost.c')
-rw-r--r-- | usr.sbin/xntpd/lib/numtohost.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/usr.sbin/xntpd/lib/numtohost.c b/usr.sbin/xntpd/lib/numtohost.c new file mode 100644 index 0000000..c8b532f --- /dev/null +++ b/usr.sbin/xntpd/lib/numtohost.c @@ -0,0 +1,39 @@ +/* numtohost.c,v 3.1 1993/07/06 01:08:40 jbj Exp + * numtohost - convert network number to host name. + */ +#include <string.h> +#include <netdb.h> + +#include "ntp_fp.h" +#include "lib_strbuf.h" +#include "ntp_stdlib.h" + +#define LOOPBACKNET 0x7f000000 +#define LOOPBACKHOST 0x7f000001 +#define LOOPBACKNETMASK 0xff000000 + +char * +numtohost(netnum) + U_LONG netnum; +{ + char *bp; + struct hostent *hp; + + /* + * This is really gross, but saves lots of hanging looking for + * hostnames for the radio clocks. Don't bother looking up + * addresses on the loopback network except for the loopback + * host itself. + */ + if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET) + && (ntohl(netnum) != LOOPBACKHOST)) + || ((hp = gethostbyaddr((char *)&netnum, sizeof netnum, AF_INET)) + == 0)) + return numtoa(netnum); + + LIB_GETBUF(bp); + + bp[LIB_BUFLENGTH-1] = '\0'; + (void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1); + return bp; +} |