diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-12-02 09:01:21 +0000 |
---|---|---|
committer | <> | 2014-12-04 16:11:25 +0000 |
commit | bdab5265fcbf3f472545073a23f8999749a9f2b9 (patch) | |
tree | c6018dd03dea906f8f1fb5f105f05b71a7dc250a /libntp/numtohost.c | |
download | ntp-dev-4.2.7p482.tar.gz |
Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz.ntp-dev-4.2.7p482
Diffstat (limited to 'libntp/numtohost.c')
-rw-r--r-- | libntp/numtohost.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libntp/numtohost.c b/libntp/numtohost.c new file mode 100644 index 0000000..6b250d6 --- /dev/null +++ b/libntp/numtohost.c @@ -0,0 +1,43 @@ +/* + * numtohost - convert network number to host name. + */ +#include <config.h> + +#include <sys/types.h> +#ifdef HAVE_NETINET_IN_H +#include <netinet/in.h> /* ntohl */ +#endif + +#include "ntp_fp.h" +#include "ntp_stdlib.h" +#include "lib_strbuf.h" + +#define LOOPBACKNET 0x7f000000 +#define LOOPBACKHOST 0x7f000001 +#define LOOPBACKNETMASK 0xff000000 + +char * +numtohost( + 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); + + LIB_GETBUF(bp); + strlcpy(bp, hp->h_name, LIB_BUFLENGTH); + + return bp; +} |