File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / ntp / libntp / socktoa.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, 5 months ago) by misho
Branches: ntp, MAIN
CVS tags: v4_2_6p5p0, v4_2_6p5, HEAD
ntp 4.2.6p5

    1: /*
    2:  * socktoa - return a numeric host name from a sockaddr_storage structure
    3:  */
    4: 
    5: #ifdef HAVE_CONFIG_H
    6: #include <config.h>
    7: #endif
    8: 
    9: #include <sys/types.h>
   10: #ifdef HAVE_SYS_SOCKET_H
   11: #include <sys/socket.h>
   12: #endif
   13: #ifdef HAVE_NETINET_IN_H
   14: #include <netinet/in.h>
   15: #endif
   16: 
   17: #include <arpa/inet.h>
   18: 
   19: #ifdef ISC_PLATFORM_NEEDNTOP
   20: #include <isc/net.h>
   21: #endif
   22: 
   23: #include <stdio.h>
   24: 
   25: #include "ntp_fp.h"
   26: #include "lib_strbuf.h"
   27: #include "ntp_stdlib.h"
   28: #include "ntp.h"
   29: 
   30: char *
   31: socktoa(
   32: 	const sockaddr_u *sock
   33: 	)
   34: {
   35: 	register char *buffer;
   36: 
   37: 	LIB_GETBUF(buffer);
   38: 
   39: 	if (NULL == sock)
   40: 		strncpy(buffer, "(null)", LIB_BUFLENGTH);
   41: 	else {
   42: 		switch(AF(sock)) {
   43: 
   44: 		case AF_INET:
   45: 		case AF_UNSPEC:
   46: 			inet_ntop(AF_INET, PSOCK_ADDR4(sock), buffer,
   47: 				  LIB_BUFLENGTH);
   48: 			break;
   49: 
   50: 		case AF_INET6:
   51: 			inet_ntop(AF_INET6, PSOCK_ADDR6(sock), buffer,
   52: 				  LIB_BUFLENGTH);
   53: 			break;
   54: 
   55: 		default:
   56: 			snprintf(buffer, LIB_BUFLENGTH, 
   57: 				 "(socktoa unknown family %d)", 
   58: 				 AF(sock));
   59: 		}
   60: 	}
   61: 	return buffer;
   62: }

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