From 7aab458a3486852fc4c0e07cbba0b6eee6ebeb29 Mon Sep 17 00:00:00 2001 From: tron Date: Fri, 17 Sep 1999 18:23:54 +0000 Subject: Add IPv6 support supplied by Feico Dillema in PR pkg/8413. --- sysutils/socket/Makefile | 14 +- sysutils/socket/files/patch-sum | 10 +- sysutils/socket/patches/patch-aa | 12 +- sysutils/socket/patches/patch-ac | 28 +++- sysutils/socket/patches/patch-ag | 266 +++++++++++++++++++++++++++++++-- sysutils/socket/patches/patch-ah | 308 +++++++++++++++++++++++++++++++++++++-- 6 files changed, 591 insertions(+), 47 deletions(-) (limited to 'sysutils') diff --git a/sysutils/socket/Makefile b/sysutils/socket/Makefile index d5c1d4909c8..df242dadbfe 100644 --- a/sysutils/socket/Makefile +++ b/sysutils/socket/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.5 1998/06/22 13:09:51 agc Exp $ +# $NetBSD: Makefile,v 1.6 1999/09/17 18:23:54 tron Exp $ # FreeBSD Id: Makefile,v 1.7 1997/08/16 10:14:56 wosch Exp # @@ -10,4 +10,16 @@ MAINTAINER= packages@netbsd.org MAKE_ENV+= INSTALLBASE=${PREFIX} +BUILD_DEFS+= USE_INET6 + +# to get USE_INET6 +.include "../../mk/bsd.prefs.mk" + +# IPv6 support +.if defined(USE_INET6) && ${USE_INET6} == YES +MAKE_ENV+= SWITCHES="-DUSE_INET6 -DHAVE_SYS_PARAM_H -Wall" +.else +MAKE_ENV+= SWITCHES="-DHAVE_SYS_PARAM_H -Wall" +.endif + .include "../../mk/bsd.pkg.mk" diff --git a/sysutils/socket/files/patch-sum b/sysutils/socket/files/patch-sum index 7b23cb63d98..d96b8738ed4 100644 --- a/sysutils/socket/files/patch-sum +++ b/sysutils/socket/files/patch-sum @@ -1,11 +1,11 @@ -$NetBSD: patch-sum,v 1.1 1999/07/09 14:23:11 agc Exp $ +$NetBSD: patch-sum,v 1.2 1999/09/17 18:23:55 tron Exp $ -MD5 (patch-aa) = 745ad4fde6f0bea92f317e824472cc3e +MD5 (patch-aa) = 7e2a566ca1ee4f3edd862f6cd8c64b62 MD5 (patch-ab) = 50a68d724fef522609b09c4658d92e5b -MD5 (patch-ac) = 15926bc6d11c186481236f98dc119bd7 +MD5 (patch-ac) = 252c37b70c82b4dbb9b312da25c68c50 MD5 (patch-ad) = 4f6e46e1f6fa7fccad18685963a1dfec MD5 (patch-ae) = d5a228870cde28457a3b561572dac242 MD5 (patch-af) = 9d6160e4946844d3290efec09250f8a5 -MD5 (patch-ag) = b469fee04b246caffc205bcc4396d440 -MD5 (patch-ah) = f1550e7e3ab0e71c80bac46f843a82bc +MD5 (patch-ag) = 9cd82962ec2399e9e9562cccf9ddf6c1 +MD5 (patch-ah) = fa7b5b078cf2e5b0466626612d356a4f MD5 (patch-ai) = a3021442e8ea4aaf3336b08a725b5cca diff --git a/sysutils/socket/patches/patch-aa b/sysutils/socket/patches/patch-aa index 2dc6bb0ae9c..217ffaa787a 100644 --- a/sysutils/socket/patches/patch-aa +++ b/sysutils/socket/patches/patch-aa @@ -1,4 +1,4 @@ -$NetBSD: patch-aa,v 1.4 1999/02/02 23:00:40 tron Exp $ +$NetBSD: patch-aa,v 1.5 1999/09/17 18:23:55 tron Exp $ --- Makefile.orig Thu Sep 10 16:59:31 1992 +++ Makefile Tue Feb 2 23:52:02 1999 @@ -11,13 +11,3 @@ $NetBSD: patch-aa,v 1.4 1999/02/02 23:00:40 tron Exp $ INSTALLBINPATH = $(INSTALLBASE)/bin INSTALLBINMODE = 755 INSTALLMANPATH = $(INSTALLBASE)/man -@@ -43,7 +43,8 @@ - ### CDC 4680 EP/IX: (I know it *has* setsid(2), but not with bsd43) - # SWITCHES = -systype bsd43 -DNOSETSID - -- -+# FreeBSD 2.x (4.4BSD) -+SWITCHES=-DHAVE_SYS_PARAM_H -Wall - - ### It should not be necessary to change anything below this line. - ################################################################## diff --git a/sysutils/socket/patches/patch-ac b/sysutils/socket/patches/patch-ac index 661811a098f..5fa0e86f466 100644 --- a/sysutils/socket/patches/patch-ac +++ b/sysutils/socket/patches/patch-ac @@ -1,8 +1,8 @@ -$NetBSD: patch-ac,v 1.1 1999/02/02 23:00:40 tron Exp $ +$NetBSD: patch-ac,v 1.2 1999/09/17 18:23:55 tron Exp $ ---- globals.h.orig Sun Aug 30 21:04:27 1992 -+++ globals.h Tue Feb 2 23:52:03 1999 -@@ -8,6 +8,11 @@ +--- globals.h.orig Thu Sep 16 13:52:37 1999 ++++ globals.h Thu Sep 16 12:45:24 1999 +@@ -8,6 +8,10 @@ */ #include "patchlevel.h" @@ -10,11 +10,27 @@ $NetBSD: patch-ac,v 1.1 1999/02/02 23:00:40 tron Exp $ +#if HAVE_SYS_PARAM_H +# include +#endif -+ /* globals for socket */ -@@ -49,4 +54,7 @@ +@@ -22,9 +26,16 @@ + #define A(args) () + #endif + ++#ifndef USE_INET6 + int create_server_socket A((int port, int queue_length)) ; + int create_client_socket A((char **hostname, int port)) ; + int resolve_service A((char *name_or_number, char *protocol, char **name)) ; ++#else /* USE_INET6 */ ++int *create_server_sockets A((char **port, int queue_length)) ; ++int create_client_socket A((char **hostname, char **port)) ; ++int socket_local_name A((int socket, char **name, char **ipname, char **port)); ++int socket_remote_name A((int socket, char **name, char **ipname, char **port)); ++#endif /* USE_INET6 */ + void catchsig A((int sig)) ; + void usage A((void)) ; + int do_read_write A((int from, int to)) ; +@@ -49,4 +60,7 @@ extern int crlfflag ; extern int active_socket ; extern char *progname ; diff --git a/sysutils/socket/patches/patch-ag b/sysutils/socket/patches/patch-ag index 29278a87349..b384e3d309f 100644 --- a/sysutils/socket/patches/patch-ag +++ b/sysutils/socket/patches/patch-ag @@ -1,8 +1,18 @@ -$NetBSD: patch-ag,v 1.1 1999/02/02 23:00:41 tron Exp $ +$NetBSD: patch-ag,v 1.2 1999/09/17 18:23:55 tron Exp $ ---- socket.c.orig Wed Sep 9 16:14:34 1992 -+++ socket.c Tue Feb 2 23:52:03 1999 -@@ -18,6 +18,8 @@ +--- socket.c.orig Thu Sep 16 13:52:48 1999 ++++ socket.c Thu Sep 16 12:54:06 1999 +@@ -9,6 +9,9 @@ + + #include + #include ++#ifdef USE_INET6 ++#include ++#endif /* USE_INET6 */ + #include + #include + #include +@@ -18,6 +21,8 @@ #else #include #endif @@ -11,39 +21,144 @@ $NetBSD: patch-ag,v 1.1 1999/02/02 23:00:41 tron Exp $ #include "globals.h" /* global variables */ -@@ -37,6 +39,8 @@ +@@ -34,9 +39,17 @@ + char *progname ; /* name of the game */ + char *pipe_program = NULL ; /* program to execute in two-way pipe */ + ++#ifndef USE_INET6 void server A((int port, char *service_name)) ; - void handle_server_connection A((void)) ; +-void handle_server_connection A((void)) ; void client A((char *host, int port, char *service_name)) ; ++#else /* USE_INET6 */ ++void server A((char *port)) ; ++void client A((char *host, char *port)) ; ++#endif /* USE_INET6 */ ++ ++void handle_server_connection A((void)) ; +extern void init_signals A((void)) ; +extern void do_io A((void)) ; int main(argc, argv) int argc ; -@@ -46,7 +50,7 @@ +@@ -46,9 +59,11 @@ int opt ; /* option character */ int error = 0 ; /* usage error occurred */ extern int optind ; /* from getopt() */ - char *host ; /* name of remote host */ + /* char *host ; */ /* name of remote host */ ++#ifndef USE_INET6 int port ; /* port number for socket */ char *service_name ; /* name of service for port */ ++#endif /* USE_INET6 */ -@@ -58,7 +62,7 @@ + /* print version ID if requested */ + if (argv[1] && !strcmp(argv[1], "-version")) { +@@ -58,7 +73,8 @@ /* set up progname for later use */ progname = argv[0] ; - if (cp = strrchr(progname, '/')) progname = cp + 1 ; -+ if ((cp = strrchr(progname, '/'))) progname = cp + 1 ; ++ cp = strrchr(progname, '/'); ++ if (cp) progname = cp + 1 ; /* parse options */ while ((opt = getopt(argc, argv, "bcflp:qrsvw?")) != -1) { -@@ -185,15 +189,15 @@ +@@ -126,6 +142,7 @@ + /* set up signal handling */ + init_signals() ; + ++#ifndef USE_INET6 + /* get port number */ + port = resolve_service(argv[optind + 1 - serverflag], + "tcp", &service_name) ; +@@ -134,41 +151,81 @@ + exit(5) ; + } + ++#endif /* not USE_INET6 */ + /* and go */ + if (serverflag) { + if (backgflag) { + background() ; + } ++#ifndef USE_INET6 + server(port, service_name) ; ++#else /* USE_INET6 */ ++ server(argv[optind]) ; ++#endif /* USE_INET6 */ + } else { ++#ifndef USE_INET6 + client(argv[optind], port, service_name) ; ++#else /* USE_INET6 */ ++ client(argv[optind], argv[optind + 1]) ; ++#endif /* USE_INET6 */ + } + exit(0) ; + } + + ++#ifndef USE_INET6 + void server(port, service_name) + int port ; + char *service_name ; ++#else /* USE_INET6 */ ++void server(port) ++char *port ; ++#endif /* USE_INET6 */ + { ++#ifndef USE_INET6 + int socket_handle, alen ; ++#else /* USE_INET6 */ ++ int *socket_handle_list ; ++#endif /* USE_INET6 */ + + /* allocate server socket */ ++#ifndef USE_INET6 + socket_handle = create_server_socket(port, 1) ; + if (socket_handle < 0) { ++#else /* USE_INET6 */ ++ socket_handle_list = create_server_sockets(&port, 1) ; ++ if (!socket_handle_list) { ++#endif /* USE_INET6 */ + perror2("server socket") ; + exit(1) ; + } ++#ifdef USE_INET6 ++ ++#endif /* USE_INET6 */ + if (verboseflag) { ++#ifndef USE_INET6 + fprintf(stderr, "listening on port %d", port) ; + if (service_name) { + fprintf(stderr, " (%s)", service_name) ; + } + fprintf(stderr, "\n") ; ++#else /* USE_INET6 */ ++ char *ip, *port; ++ int fd, i; ++ ++ fd = socket_handle_list[1]; ++ for (i = 1; i <= socket_handle_list[0]; i++) { ++ if (!fd || fd < socket_handle_list[i]) ++ fd = socket_handle_list[i]; ++ socket_local_name (fd, NULL, &ip, &port); ++ fprintf(stderr, "listening at address %s on port %s\n", ip, port) ; ++ } ++#endif /* USE_INET6 */ + } + + /* server loop */ + do { ++#ifndef USE_INET6 + struct sockaddr_in sa ; + + alen = sizeof(sa) ; +@@ -185,16 +242,76 @@ long norder ; char dotted[20] ; - he = gethostbyaddr(&sa.sin_addr.s_addr, -+ he = gethostbyaddr((char *)&sa.sin_addr.s_addr, ++ he = gethostbyaddr((const char *)&sa.sin_addr.s_addr, sizeof(sa.sin_addr.s_addr), AF_INET) ; if (!he) { norder = htonl(sa.sin_addr.s_addr) ; @@ -52,10 +167,131 @@ $NetBSD: patch-ag,v 1.1 1999/02/02 23:00:41 tron Exp $ - (norder >> 16) & 0xff, - (norder >> 8) & 0xff, - norder & 0xff) ; -+ (int)((norder >> 24) & 0xff), -+ (int)((norder >> 16) & 0xff), -+ (int)((norder >> 8) & 0xff), -+ (int)(norder & 0xff)) ; ++ (int)((norder >> 24) & 0xff), ++ (int)((norder >> 16) & 0xff), ++ (int)((norder >> 8) & 0xff), ++ (int)(norder & 0xff)) ; ++#else /* USE_INET6 */ ++ struct timeval tv; ++ fd_set readfd; ++ int fd, i, nfds, retval; ++ ++ fd = socket_handle_list[1]; ++ for (i = 1; i <= socket_handle_list[0]; i++) { ++ if (!fd || fd < socket_handle_list[i]) ++ fd = socket_handle_list[i]; ++ } ++ nfds=fd+1; ++ ++ FD_ZERO(&readfd); ++ for (i = 1; i <= socket_handle_list[0]; i++) ++ FD_SET(socket_handle_list[i],&readfd); ++ ++ tv.tv_sec = 10; ++ tv.tv_usec = 0; ++ ++ retval = select(nfds, &readfd, NULL, NULL, &tv); ++ ++ if(retval!=-1) { ++ for (i = 1; i <= socket_handle_list[0]; i++) { ++ fd = socket_handle_list[i]; ++ if (FD_ISSET(fd, &readfd)) { ++ ++ /* accept a connection */ ++ active_socket = accept(fd, (struct sockaddr *) 0, (int *)0); ++ if (active_socket == -1) { ++ perror2("accept") ; ++ } else { ++ /* if verbose, get name of peer and give message */ ++ if (verboseflag) { ++ char *host, *ip, *port; ++ ++ if(!socket_remote_name(active_socket,&host, &ip, &port)) { ++ fprintf(stderr, "connection from %s at %s to %s\n", host, ip, port); ++ } ++ else ++ fprintf(stderr, "cannot get name or address of peer") ; ++ } ++ ++ if (forkflag) { ++ switch (fork()) { ++ case 0: ++ handle_server_connection() ; ++ exit(0) ; ++ case -1: ++ perror2("fork") ; ++ break ; ++ default: ++ close(active_socket) ; ++ wait_for_children() ; ++ } ++ } else { ++ handle_server_connection() ; ++ } ++ } ++#endif /* USE_INET6 */ } ++#ifndef USE_INET6 fprintf(stderr, "connection from %s\n", (he ? he->h_name : dotted)) ; + } +@@ -212,9 +329,14 @@ + } + } else { + handle_server_connection() ; ++#endif /* not USE_INET6 */ + } + } + } while (loopflag) ; ++#ifdef USE_INET6 ++ ++ free (socket_handle_list); ++#endif /* USE_INET6 */ + } + + +@@ -235,13 +357,25 @@ + } + + ++#ifndef USE_INET6 + void client(host, port, service_name) ++#else /* USE_INET6 */ ++void client(host, port) ++#endif /* USE_INET6 */ + char *host ; ++#ifndef USE_INET6 + int port ; + char *service_name ; ++#else /* USE_INET6 */ ++char *port ; ++#endif /* USE_INET6 */ + { + /* get connection */ ++#ifndef USE_INET6 + active_socket = create_client_socket(&host, port) ; ++#else /* USE_INET6 */ ++ active_socket = create_client_socket(&host, &port) ; ++#endif /* USE_INET6 */ + if (active_socket == -1) { + perror2("client socket") ; + exit(errno) ; +@@ -250,11 +384,18 @@ + exit(13) ; + } + if (verboseflag) { ++#ifndef USE_INET6 + fprintf(stderr, "connected to %s port %d", host, port) ; + if (service_name) { + fprintf(stderr, " (%s)", service_name) ; + } + fprintf(stderr, "\n") ; ++#else /* USE_INET6 */ ++ char *host, *ip, *port; ++ ++ socket_local_name (active_socket, &host, &ip, &port); ++ fprintf(stderr, "connected to %s with address %s at port %s\n", host, ip, port) ; ++#endif /* USE_INET6 */ + } + + /* open pipes to program if requested */ diff --git a/sysutils/socket/patches/patch-ah b/sysutils/socket/patches/patch-ah index d80886fdfe7..3ed55d76784 100644 --- a/sysutils/socket/patches/patch-ah +++ b/sysutils/socket/patches/patch-ah @@ -1,8 +1,8 @@ -$NetBSD: patch-ah,v 1.1 1999/02/02 23:00:41 tron Exp $ +$NetBSD: patch-ah,v 1.2 1999/09/17 18:23:56 tron Exp $ ---- socketp.c.orig Sun Aug 9 03:41:42 1992 -+++ socketp.c Tue Feb 2 23:52:03 1999 -@@ -11,10 +11,16 @@ +--- socketp.c.orig Thu Sep 16 13:52:58 1999 ++++ socketp.c Thu Sep 16 13:26:38 1999 +@@ -11,10 +11,17 @@ #include #include #include @@ -16,10 +16,111 @@ $NetBSD: patch-ah,v 1.1 1999/02/02 23:00:41 tron Exp $ +extern int is_number A((char *)); + ++#ifndef USE_INET6 /* * create a server socket on PORT accepting QUEUE_LENGTH connections */ -@@ -52,7 +58,7 @@ +@@ -25,9 +32,9 @@ + struct sockaddr_in sa ; + int s; + +- if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { ++ s = socket(AF_INET, SOCK_STREAM, 0); ++ if (s < 0) + return -1 ; +- } + + bzero((char *) &sa, sizeof(sa)) ; + sa.sin_family = AF_INET ; +@@ -35,54 +42,270 @@ + sa.sin_port = htons(port) ; + + if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) { +- return -1 ; ++ return -1 ; + } + if (listen(s, 1) < 0) { +- return -1 ; ++ return -1 ; + } + + return s ; + } ++#else /* USE_INET6 */ ++/* ++ * create a server socket(s) on PORT accepting QUEUE_LENGTH connections ++ * ++ * FWD (ifdef USE_INET6): ++ * there can be more than one socket; one for each supported address ++ * family. This is for portability as not all IPv6 stacks implement ++ * the wildcard bind as a bind to *ll IPv4 *and* IPv6 addresses. ++ * so we'll just open a socket for each address getaddrinfo() gives ++ * back to us. The price of portability... ++ */ ++int *create_server_sockets(port, queue_length) ++char **port ; ++int queue_length ; ++{ ++ struct addrinfo hints, *r, *res; ++ int *s, *slist, error, maxs; ++ int reuse_addr = 1; ++ ++ memset(&hints, 0, sizeof(hints)); ++ hints.ai_flags = AI_PASSIVE; ++ hints.ai_family = AF_UNSPEC; ++ hints.ai_socktype = SOCK_STREAM; ++ hints.ai_protocol = 0; ++ error = getaddrinfo(NULL, *port, &hints, &res); ++ ++ if (!error) { ++ for (maxs = 0, r = res; r; r = r->ai_next, maxs++); ++ slist = malloc ((maxs+1) * sizeof(int)); ++ if (slist) { ++ slist[0] = maxs; /* max. num of sockets */ ++ ++ s = slist+1; ++ for (r = res; r; r = r->ai_next) { ++ *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); ++ if (*s < 0) ++ continue; ++ ++ setsockopt(*s,SOL_SOCKET,SO_REUSEADDR,&reuse_addr,sizeof(reuse_addr)); ++ ++ if (bind(*s, r->ai_addr, r->ai_addrlen) < 0) { ++ close (*s); ++ continue; ++ } ++ ++ if (listen(*s, 1) < 0) { ++ close (*s); ++ continue; ++ } ++ s++; ++ } ++ } ++ } ++ else ++ slist = NULL; ++ ++ if (res) ++ freeaddrinfo(res); ++ ++ if (slist && !slist[0]) { ++ free (slist); ++ slist = NULL; ++ } ++ ++ return (slist); ++} ++#endif /* USE_INET6 */ + + + /* create a client socket connected to PORT on HOSTNAME */ ++#ifndef USE_INET6 ++/* create a client socket connected to PORT on HOSTNAME */ + int create_client_socket(hostname, port) + char **hostname ; + int port ; { struct sockaddr_in sa ; struct hostent *hp ; @@ -28,12 +129,201 @@ $NetBSD: patch-ah,v 1.1 1999/02/02 23:00:41 tron Exp $ long addr ; -@@ -76,7 +82,7 @@ + bzero(&sa, sizeof(sa)) ; + if ((addr = inet_addr(*hostname)) != -1) { +- /* is Internet addr in octet notation */ +- bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ +- sa.sin_family = AF_INET ; ++ /* is Internet addr in octet notation */ ++ bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ ++ sa.sin_family = AF_INET ; + } else { +- /* do we know the host's address? */ +- if ((hp = gethostbyname(*hostname)) == NULL) { +- return -2 ; +- } +- *hostname = hp->h_name ; +- bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; +- sa.sin_family = hp->h_addrtype ; ++ /* do we know the host's address? */ ++ if ((hp = gethostbyname(*hostname)) == NULL) { ++ return -2 ; ++ } ++ *hostname = hp->h_name ; ++ bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; ++ sa.sin_family = hp->h_addrtype ; + } + + sa.sin_port = htons((u_short) port) ; + if ((s = socket(sa.sin_family, SOCK_STREAM, 0)) < 0) { /* get socket */ - return -1 ; +- return -1 ; ++ return -1 ; } - if (connect(s, &sa, sizeof(sa)) < 0) { /* connect */ +- close(s) ; +- return -1 ; + if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) { /* connect */ - close(s) ; - return -1 ; ++ close(s) ; ++ return -1 ; + } + return s ; + } + ++#else /* USE_INET6 */ ++int create_client_socket(hostname, port) ++char **hostname ; ++char **port ; ++{ ++ int s, connected, err ; ++ struct addrinfo hints, *r, *res; ++ ++ memset(&hints, 0, sizeof(hints)); ++ hints.ai_flags = AI_NUMERICHOST; ++ hints.ai_family = AF_UNSPEC; ++ hints.ai_socktype= SOCK_STREAM; ++ err = getaddrinfo(*hostname, *port, &hints, &res); ++ if (res) freeaddrinfo(res); ++ ++ if (!err) { ++ /* numeric */ ++ memset(&hints, 0, sizeof(hints)); ++ hints.ai_flags = AI_CANONNAME; ++ hints.ai_family = AF_UNSPEC; ++ hints.ai_socktype = SOCK_STREAM; ++ hints.ai_protocol = 0; ++ err = getaddrinfo(*hostname, *port, &hints, &res); ++ if (err) s = -2; ++ } else { ++ /* non-numeric */ ++ memset(&hints, 0, sizeof(hints)); ++ hints.ai_family = AF_UNSPEC; ++ hints.ai_socktype = SOCK_STREAM; ++ hints.ai_protocol = 0; ++ err = getaddrinfo(*hostname, *port, &hints, &res); ++ if (err) s = -2; ++ } ++ ++ ++ if (!err) { ++ err = 0; s = -1; ++ connected = 0; ++ for (r = res; r && !connected; r = r->ai_next) { ++ s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); ++ if (s < 0) ++ continue; ++ ++ if (connect(s, r->ai_addr, r->ai_addrlen) < 0) { ++ err = errno; ++ close(s); ++ s = -1; ++ continue; ++ } ++ connected++; ++ break; ++ } ++ if (!connected) s = -1; ++ } ++ ++ if (res) ++ freeaddrinfo(res); ++ ++ return (s); ++} ++#endif /* USE_INET6 */ ++ ++#ifdef USE_INET6 ++/* Determines hostname, address and port number used for the peer of socket */ ++int socket_remote_name(socket, name, ipname, port) ++int socket; ++char **name; ++char **ipname; ++char **port; ++{ ++ struct sockaddr_storage server; ++ int length=sizeof(server), retval, error; ++ static char host[NI_MAXHOST],ip[NI_MAXHOST],portstr[NI_MAXSERV]; ++ ++ error = getpeername(socket,(struct sockaddr*)&server,&length); ++ if(!error) { ++ error = getnameinfo((struct sockaddr*)&server, length, host, ++ NI_MAXHOST, NULL, 0, 0); ++ error = getnameinfo((struct sockaddr*)&server, length, ip, ++ NI_MAXHOST, NULL, NI_MAXSERV, ++ NI_NUMERICHOST); ++ retval = error; ++ ++ error = getnameinfo((struct sockaddr*)&server, length, NULL, 0, ++ portstr, NI_MAXSERV, 0); ++ ++ if (error) ++ retval = getnameinfo((struct sockaddr*)&server, length, ip, ++ NI_MAXHOST, portstr, NI_MAXSERV, ++ NI_NUMERICSERV); ++ } ++ else ++ retval = error; ++ ++ if(name) ++ *name=host; ++ if(ipname) ++ *ipname=ip; ++ if(port) ++ *port=portstr; ++ ++ return(retval); ++} ++ ++/* Determines the hostname, address and port number used for our socket */ ++int socket_local_name(socket, name, ipname, port) ++int socket; ++char **name; ++char **ipname; ++char **port; ++{ ++ struct sockaddr_storage server; ++ int length=sizeof(server), retval, error; ++ static char host[NI_MAXHOST],ip[NI_MAXHOST],portstr[NI_MAXSERV]; ++ ++ error = getsockname(socket,(struct sockaddr*)&server,&length); ++ if(!error) { ++ error = getnameinfo((struct sockaddr*)&server, length, host, ++ NI_MAXHOST, NULL, 0, 0); ++ error = getnameinfo((struct sockaddr*)&server, length, ip, ++ NI_MAXHOST, NULL, NI_MAXSERV, ++ NI_NUMERICHOST); ++ retval = error; ++ ++ error = getnameinfo((struct sockaddr*)&server, length, NULL, 0, ++ portstr, NI_MAXSERV, 0); ++ ++ if (error) ++ retval = getnameinfo((struct sockaddr*)&server, length, ip, ++ NI_MAXHOST, portstr, NI_MAXSERV, ++ NI_NUMERICSERV); ++ } ++ else ++ retval = error; ++ ++ if(name) ++ *name=host; ++ if(ipname) ++ *ipname=ip; ++ if(port) ++ *port=portstr; ++ ++ return(retval); ++} ++#endif /* USE_INET6 */ ++ ++#ifndef USE_INET6 + /* return the port number for service NAME_OR_NUMBER. If NAME is non-null, + * the name is the service is written there. + */ +@@ -116,5 +339,6 @@ + return ntohs(servent->s_port) ; } + } ++#endif /* !USE_INET6 */ + + /*EOF*/ -- cgit v1.2.3