File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / ntp / libntp / numtohost.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:08:38 2012 UTC (12 years, 1 month ago) by misho
Branches: ntp, MAIN
CVS tags: v4_2_6p5p0, v4_2_6p5, HEAD
ntp 4.2.6p5

    1: /*
    2:  * numtohost - convert network number to host name.
    3:  */
    4: #include <config.h>
    5: 
    6: #include <sys/types.h>
    7: #ifdef HAVE_NETINET_IN_H
    8: #include <netinet/in.h>		/* ntohl */
    9: #endif
   10: 
   11: #include "ntp_fp.h"
   12: #include "ntp_stdlib.h"
   13: #include "lib_strbuf.h"
   14: 
   15: #define	LOOPBACKNET	0x7f000000
   16: #define	LOOPBACKHOST	0x7f000001
   17: #define	LOOPBACKNETMASK	0xff000000
   18: 
   19: char *
   20: numtohost(
   21: 	u_int32 netnum
   22: 	)
   23: {
   24: 	char *bp;
   25: 	struct hostent *hp;
   26: 
   27: 	/*
   28: 	 * This is really gross, but saves lots of hanging looking for
   29: 	 * hostnames for the radio clocks.  Don't bother looking up
   30: 	 * addresses on the loopback network except for the loopback
   31: 	 * host itself.
   32: 	 */
   33: 	if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET)
   34: 	     && (ntohl(netnum) != LOOPBACKHOST))
   35: 	    || ((hp = gethostbyaddr((char *)&netnum, sizeof netnum, AF_INET))
   36: 		== 0))
   37: 	    return numtoa(netnum);
   38: 	
   39: 	LIB_GETBUF(bp);
   40: 	
   41: 	bp[LIB_BUFLENGTH-1] = '\0';
   42: 	(void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1);
   43: 	return bp;
   44: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>