NetBSD/lib/libntp/numtohost.c

41 lines
924 B
C
Raw Normal View History

1999-07-02 19:58:35 +04:00
/* $NetBSD: numtohost.c,v 1.3 1999/07/02 15:58:36 simonb Exp $ */
1998-01-09 06:15:09 +03:00
1997-04-18 17:22:49 +04:00
/*
* numtohost - convert network number to host name.
*/
#include <netdb.h>
#include "ntp_fp.h"
#include "ntp_stdlib.h"
#include "lib_strbuf.h"
#define LOOPBACKNET 0x7f000000
#define LOOPBACKHOST 0x7f000001
#define LOOPBACKNETMASK 0xff000000
char *
numtohost(netnum)
u_int32 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);
1999-07-02 19:58:35 +04:00
1997-04-18 17:22:49 +04:00
LIB_GETBUF(bp);
1999-07-02 19:58:35 +04:00
1997-04-18 17:22:49 +04:00
bp[LIB_BUFLENGTH-1] = '\0';
(void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1);
return bp;
}