254f85
diff -up openssl-1.0.1c/apps/s_apps.h.ipv6-apps openssl-1.0.1c/apps/s_apps.h
254f85
--- openssl-1.0.1c/apps/s_apps.h.ipv6-apps	2012-07-11 22:46:02.409221206 +0200
254f85
+++ openssl-1.0.1c/apps/s_apps.h	2012-07-11 22:46:02.451222165 +0200
2ccfa6
@@ -148,7 +148,7 @@ typedef fd_mask fd_set;
2ccfa6
 #define PORT_STR        "4433"
2ccfa6
 #define PROTOCOL        "tcp"
2ccfa6
 
2ccfa6
-int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
2ccfa6
+int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
2ccfa6
 #ifdef HEADER_X509_H
2ccfa6
 int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
2ccfa6
 #endif
ad05b5
@@ -156,10 +156,9 @@ int MS_CALLBACK verify_callback(int ok,
2ccfa6
 int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);
2ccfa6
 int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);
2ccfa6
 #endif
2ccfa6
-int init_client(int *sock, char *server, int port, int type);
2ccfa6
+int init_client(int *sock, char *server, char *port, int type);
2ccfa6
 int should_retry(int i);
2ccfa6
-int extract_port(char *str, short *port_ptr);
2ccfa6
-int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);
2ccfa6
+int extract_host_port(char *str,char **host_ptr,char **port_ptr);
2ccfa6
 
2ccfa6
 long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
2ccfa6
 				   int argi, long argl, long ret);
254f85
diff -up openssl-1.0.1c/apps/s_client.c.ipv6-apps openssl-1.0.1c/apps/s_client.c
254f85
--- openssl-1.0.1c/apps/s_client.c.ipv6-apps	2012-07-11 22:46:02.433221754 +0200
254f85
+++ openssl-1.0.1c/apps/s_client.c	2012-07-11 22:46:02.452222187 +0200
ad05b5
@@ -563,7 +563,7 @@ int MAIN(int argc, char **argv)
2ccfa6
 	int cbuf_len,cbuf_off;
2ccfa6
 	int sbuf_len,sbuf_off;
2ccfa6
 	fd_set readfds,writefds;
2ccfa6
-	short port=PORT;
2ccfa6
+	char *port_str = PORT_STR;
2ccfa6
 	int full_log=1;
2ccfa6
 	char *host=SSL_HOST_NAME;
2ccfa6
 	char *cert_file=NULL,*key_file=NULL;
254f85
@@ -664,13 +664,12 @@ int MAIN(int argc, char **argv)
2ccfa6
 		else if	(strcmp(*argv,"-port") == 0)
2ccfa6
 			{
2ccfa6
 			if (--argc < 1) goto bad;
2ccfa6
-			port=atoi(*(++argv));
2ccfa6
-			if (port == 0) goto bad;
2ccfa6
+			port_str= *(++argv);
2ccfa6
 			}
2ccfa6
 		else if (strcmp(*argv,"-connect") == 0)
2ccfa6
 			{
2ccfa6
 			if (--argc < 1) goto bad;
2ccfa6
-			if (!extract_host_port(*(++argv),&host,NULL,&port))
2ccfa6
+			if (!extract_host_port(*(++argv),&host,&port_str))
2ccfa6
 				goto bad;
2ccfa6
 			}
2ccfa6
 		else if	(strcmp(*argv,"-verify") == 0)
254f85
@@ -1253,7 +1252,7 @@ bad:
2ccfa6
 
2ccfa6
 re_start:
2ccfa6
 
2ccfa6
-	if (init_client(&s,host,port,socket_type) == 0)
2ccfa6
+	if (init_client(&s,host,port_str,socket_type) == 0)
2ccfa6
 		{
2ccfa6
 		BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error());
2ccfa6
 		SHUTDOWN(s);
254f85
diff -up openssl-1.0.1c/apps/s_server.c.ipv6-apps openssl-1.0.1c/apps/s_server.c
254f85
--- openssl-1.0.1c/apps/s_server.c.ipv6-apps	2012-07-11 22:46:02.434221777 +0200
254f85
+++ openssl-1.0.1c/apps/s_server.c	2012-07-11 22:46:02.453222210 +0200
ad05b5
@@ -929,7 +929,7 @@ int MAIN(int argc, char *argv[])
2ccfa6
 	{
2ccfa6
 	X509_VERIFY_PARAM *vpm = NULL;
2ccfa6
 	int badarg = 0;
2ccfa6
-	short port=PORT;
2ccfa6
+	char *port_str = PORT_STR;
2ccfa6
 	char *CApath=NULL,*CAfile=NULL;
2ccfa6
 	unsigned char *context = NULL;
2ccfa6
 	char *dhfile = NULL;
254f85
@@ -1000,8 +1000,7 @@ int MAIN(int argc, char *argv[])
2ccfa6
 			 (strcmp(*argv,"-accept") == 0))
2ccfa6
 			{
2ccfa6
 			if (--argc < 1) goto bad;
2ccfa6
-			if (!extract_port(*(++argv),&port))
2ccfa6
-				goto bad;
2ccfa6
+			port_str= *(++argv);
2ccfa6
 			}
2ccfa6
 		else if	(strcmp(*argv,"-verify") == 0)
2ccfa6
 			{
254f85
@@ -1878,9 +1877,9 @@ bad:
2ccfa6
 	BIO_printf(bio_s_out,"ACCEPT\n");
2ccfa6
 	(void)BIO_flush(bio_s_out);
2ccfa6
 	if (www)
2ccfa6
-		do_server(port,socket_type,&accept_socket,www_body, context);
2ccfa6
+		do_server(port_str,socket_type,&accept_socket,www_body, context);
2ccfa6
 	else
2ccfa6
-		do_server(port,socket_type,&accept_socket,sv_body, context);
2ccfa6
+		do_server(port_str,socket_type,&accept_socket,sv_body, context);
2ccfa6
 	print_stats(bio_s_out,ctx);
2ccfa6
 	ret=0;
2ccfa6
 end:
254f85
diff -up openssl-1.0.1c/apps/s_socket.c.ipv6-apps openssl-1.0.1c/apps/s_socket.c
254f85
--- openssl-1.0.1c/apps/s_socket.c.ipv6-apps	2011-12-02 15:39:40.000000000 +0100
254f85
+++ openssl-1.0.1c/apps/s_socket.c	2012-07-11 22:49:05.411400450 +0200
bffe20
@@ -102,9 +102,7 @@ static struct hostent *GetHostByName(cha
4d4d77
 static void ssl_sock_cleanup(void);
4d4d77
 #endif
4d4d77
 static int ssl_sock_init(void);
4d4d77
-static int init_client_ip(int *sock,unsigned char ip[4], int port, int type);
4d4d77
-static int init_server(int *sock, int port, int type);
4d4d77
-static int init_server_long(int *sock, int port,char *ip, int type);
4d4d77
+static int init_server(int *sock, char *port, int type);
4d4d77
 static int do_accept(int acc_sock, int *sock, char **host);
4d4d77
 static int host_ip(char *str, unsigned char ip[4]);
4d4d77
 
ad05b5
@@ -234,57 +232,70 @@ static int ssl_sock_init(void)
4d4d77
 	return(1);
4d4d77
 	}
4d4d77
 
4d4d77
-int init_client(int *sock, char *host, int port, int type)
4d4d77
+int init_client(int *sock, char *host, char *port, int type)
4d4d77
 	{
4d4d77
-	unsigned char ip[4];
4d4d77
-
ad05b5
-	memset(ip, '\0', sizeof ip);
4d4d77
-	if (!host_ip(host,&(ip[0])))
ad05b5
-		return 0;
ad05b5
-	return init_client_ip(sock,ip,port,type);
4d4d77
-	}
4d4d77
-
4d4d77
-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
4d4d77
-	{
4d4d77
-	unsigned long addr;
4d4d77
-	struct sockaddr_in them;
4d4d77
-	int s,i;
4d4d77
+	struct addrinfo *res, *res0, hints;
4d4d77
+	char * failed_call = NULL;
4d4d77
+	int s;
4d4d77
+	int e;
4d4d77
 
4d4d77
 	if (!ssl_sock_init()) return(0);
4d4d77
 
4d4d77
-	memset((char *)&them,0,sizeof(them));
4d4d77
-	them.sin_family=AF_INET;
4d4d77
-	them.sin_port=htons((unsigned short)port);
4d4d77
-	addr=(unsigned long)
4d4d77
-		((unsigned long)ip[0]<<24L)|
4d4d77
-		((unsigned long)ip[1]<<16L)|
4d4d77
-		((unsigned long)ip[2]<< 8L)|
4d4d77
-		((unsigned long)ip[3]);
4d4d77
-	them.sin_addr.s_addr=htonl(addr);
4d4d77
-
4d4d77
-	if (type == SOCK_STREAM)
4d4d77
-		s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
4d4d77
-	else /* ( type == SOCK_DGRAM) */
4d4d77
-		s=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
4d4d77
-			
4d4d77
-	if (s == INVALID_SOCKET) { perror("socket"); return(0); }
4d4d77
+	memset(&hints, '\0', sizeof(hints));
4d4d77
+	hints.ai_socktype = type;
4d4d77
+	hints.ai_flags = AI_ADDRCONFIG;
4d4d77
+
4d4d77
+	e = getaddrinfo(host, port, &hints, &res);
4d4d77
+	if (e)
4d4d77
+	{
4d4d77
+		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
4d4d77
+		if (e == EAI_SYSTEM)
4d4d77
+			perror("getaddrinfo");
4d4d77
+		return (0);
4d4d77
+		}
4d4d77
 
4d4d77
+	res0 = res;
4d4d77
+	while (res)
4d4d77
+		{
4d4d77
+		s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
4d4d77
+		if (s == INVALID_SOCKET)
4d4d77
+			{
4d4d77
+			failed_call = "socket";
4d4d77
+			goto nextres;
4d4d77
+			}
2ccfa6
 #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
4d4d77
 	if (type == SOCK_STREAM)
4d4d77
 		{
4d4d77
-		i=0;
4d4d77
-		i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
4d4d77
-		if (i < 0) { perror("keepalive"); return(0); }
4d4d77
+			int i=0;
4d4d77
+			i=setsockopt(s,SOL_SOCKET,SO_KEEPALIVE,
4d4d77
+				(char *)&i,sizeof(i));
4d4d77
+			if (i < 0) {
4d4d77
+				failed_call = "keepalive";
4d4d77
+				goto nextres;
4d4d77
+				}
4d4d77
 		}
4d4d77
 #endif
4d4d77
-
4d4d77
-	if (connect(s,(struct sockaddr *)&them,sizeof(them)) == -1)
2ccfa6
-		{ closesocket(s); perror("connect"); return(0); }
4d4d77
+		if (connect(s,(struct sockaddr *)res->ai_addr,
4d4d77
+			res->ai_addrlen) == 0)
4d4d77
+			{
4d4d77
+			freeaddrinfo(res0);
4d4d77
 	*sock=s;
4d4d77
 	return(1);
4d4d77
 	}
2ccfa6
 
2ccfa6
-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
4d4d77
+		failed_call = "socket";
4d4d77
+nextres:
4d4d77
+		if (s != INVALID_SOCKET)
4d4d77
+			close(s);
4d4d77
+		res = res->ai_next;
4d4d77
+		}
4d4d77
+	freeaddrinfo(res0);
2ccfa6
+
4d4d77
+	perror(failed_call);
4d4d77
+	return(0);
4d4d77
+	}
3849a1
+
4d4d77
+int do_server(char *port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
4d4d77
 	{
4d4d77
 	int sock;
4d4d77
 	char *name = NULL;
254f85
@@ -322,33 +333,50 @@ int do_server(int port, int type, int *r
4d4d77
 		}
4d4d77
 	}
4d4d77
 
4d4d77
-static int init_server_long(int *sock, int port, char *ip, int type)
4d4d77
+static int init_server(int *sock, char *port, int type)
4d4d77
 	{
4d4d77
-	int ret=0;
4d4d77
-	struct sockaddr_in server;
3ff2d4
-	int s= -1;
ad05b5
+	struct addrinfo *res, *res0 = NULL, hints;
4d4d77
+	char * failed_call = NULL;
254f85
+	int s = INVALID_SOCKET;
4d4d77
+	int e;
4d4d77
 
4d4d77
 	if (!ssl_sock_init()) return(0);
4d4d77
 
4d4d77
-	memset((char *)&server,0,sizeof(server));
4d4d77
-	server.sin_family=AF_INET;
4d4d77
-	server.sin_port=htons((unsigned short)port);
4d4d77
-	if (ip == NULL)
4d4d77
-		server.sin_addr.s_addr=INADDR_ANY;
4d4d77
-	else
4d4d77
-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */
4d4d77
-#ifndef BIT_FIELD_LIMITS
4d4d77
-		memcpy(&server.sin_addr.s_addr,ip,4);
4d4d77
-#else
4d4d77
-		memcpy(&server.sin_addr,ip,4);
4d4d77
-#endif
3849a1
+	memset(&hints, '\0', sizeof(hints));
254f85
+	hints.ai_family = AF_INET6;
ad05b5
+tryipv4:
3849a1
+	hints.ai_socktype = type;
254f85
+	hints.ai_flags = AI_PASSIVE;
3849a1
 	
4d4d77
-		if (type == SOCK_STREAM)
4d4d77
-			s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
4d4d77
-		else /* type == SOCK_DGRAM */
4d4d77
-			s=socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP);
4d4d77
+	e = getaddrinfo(NULL, port, &hints, &res);
4d4d77
+	if (e)
4d4d77
+		{
254f85
+		if (hints.ai_family == AF_INET)
254f85
+			{
254f85
+			fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
254f85
+			if (e == EAI_SYSTEM)
254f85
+				perror("getaddrinfo");
254f85
+			return (0);
254f85
+			}
254f85
+			else
254f85
+				res = NULL;
4d4d77
+		}
4d4d77
 
4d4d77
-	if (s == INVALID_SOCKET) goto err;
4d4d77
+	res0 = res;
4d4d77
+	while (res)
4d4d77
+		{
4d4d77
+		s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
4d4d77
+		if (s == INVALID_SOCKET)
4d4d77
+			{
4d4d77
+			failed_call = "socket";
4d4d77
+			goto nextres;
4d4d77
+			}
ad05b5
+		if (hints.ai_family == AF_INET6)
ad05b5
+			{
ad05b5
+			int j = 0;
ad05b5
+			setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
ad05b5
+				   (void *) &j, sizeof j);
ad05b5
+			}
4d4d77
 #if defined SOL_SOCKET && defined SO_REUSEADDR
4d4d77
 		{
4d4d77
 		int j = 1;
254f85
@@ -356,35 +384,49 @@ static int init_server_long(int *sock, i
4d4d77
 			   (void *) &j, sizeof j);
4d4d77
 		}
4d4d77
 #endif
4d4d77
-	if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
4d4d77
+
4d4d77
+		if (bind(s,(struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1)
4d4d77
 		{
4d4d77
-#ifndef OPENSSL_SYS_WINDOWS
4d4d77
-		perror("bind");
4d4d77
-#endif
4d4d77
-		goto err;
4d4d77
+			failed_call = "bind";
4d4d77
+			goto nextres;
4d4d77
 		}
4d4d77
-	/* Make it 128 for linux */
4d4d77
-	if (type==SOCK_STREAM && listen(s,128) == -1) goto err;
4d4d77
-	*sock=s;
4d4d77
-	ret=1;
4d4d77
-err:
4d4d77
-	if ((ret == 0) && (s != -1))
4d4d77
+		if (type==SOCK_STREAM && listen(s,128) == -1)
4d4d77
 		{
4d4d77
-		SHUTDOWN(s);
4d4d77
+			failed_call = "listen";
4d4d77
+			goto nextres;
4d4d77
 		}
4d4d77
-	return(ret);
4d4d77
+
4d4d77
+		*sock=s;
4d4d77
+		return(1);
4d4d77
+
4d4d77
+nextres:
4d4d77
+		if (s != INVALID_SOCKET)
4d4d77
+			close(s);
4d4d77
+		res = res->ai_next;
4d4d77
 	}
ad05b5
+	if (res0)
ad05b5
+		freeaddrinfo(res0);
4d4d77
 
4d4d77
-static int init_server(int *sock, int port, int type)
ad05b5
+	if (s == INVALID_SOCKET)
ad05b5
 	{
4d4d77
-	return(init_server_long(sock, port, NULL, type));
ad05b5
+		if (hints.ai_family == AF_INET6)
ad05b5
+		{
ad05b5
+			hints.ai_family = AF_INET;
ad05b5
+			goto tryipv4;
ad05b5
+		}
ad05b5
+		perror("socket");
ad05b5
+		return(0);
ad05b5
+	}
4d4d77
+
4d4d77
+	perror(failed_call);
4d4d77
+	return(0);
4d4d77
 	}
4d4d77
 
4d4d77
 static int do_accept(int acc_sock, int *sock, char **host)
4d4d77
 	{
4d4d77
+	static struct sockaddr_storage from;
4d4d77
+	char buffer[NI_MAXHOST];
3ff2d4
 	int ret;
3ff2d4
-	struct hostent *h1,*h2;
3ff2d4
-	static struct sockaddr_in from;
4d4d77
 	int len;
4d4d77
 /*	struct linger ling; */
4d4d77
 
254f85
@@ -431,135 +473,58 @@ redoit:
4d4d77
 */
4d4d77
 
bffe20
 	if (host == NULL) goto end;
4d4d77
-#ifndef BIT_FIELD_LIMITS
4d4d77
-	/* I should use WSAAsyncGetHostByName() under windows */
4d4d77
-	h1=gethostbyaddr((char *)&from.sin_addr.s_addr,
4d4d77
-		sizeof(from.sin_addr.s_addr),AF_INET);
4d4d77
-#else
4d4d77
-	h1=gethostbyaddr((char *)&from.sin_addr,
4d4d77
-		sizeof(struct in_addr),AF_INET);
4d4d77
-#endif
4d4d77
-	if (h1 == NULL)
bffe20
+
bffe20
+	if (getnameinfo((struct sockaddr *)&from, sizeof(from),
bffe20
+		buffer, sizeof(buffer),
bffe20
+		NULL, 0, 0))
2ccfa6
 		{
4d4d77
-		BIO_printf(bio_err,"bad gethostbyaddr\n");
bffe20
+		BIO_printf(bio_err,"getnameinfo failed\n");
bffe20
 		*host=NULL;
bffe20
 		/* return(0); */
bffe20
 		}
bffe20
 	else
bffe20
 		{
4d4d77
-		if ((*host=(char *)OPENSSL_malloc(strlen(h1->h_name)+1)) == NULL)
bffe20
+		if ((*host=(char *)OPENSSL_malloc(strlen(buffer)+1)) == NULL)
bffe20
 			{
bffe20
 			perror("OPENSSL_malloc");
4d4d77
 			return(0);
4d4d77
 			}
4d4d77
-		BUF_strlcpy(*host,h1->h_name,strlen(h1->h_name)+1);
bffe20
-
4d4d77
-		h2=GetHostByName(*host);
4d4d77
-		if (h2 == NULL)
bffe20
-			{
4d4d77
-			BIO_printf(bio_err,"gethostbyname failure\n");
bffe20
-			return(0);
bffe20
-			}
4d4d77
-		if (h2->h_addrtype != AF_INET)
bffe20
-			{
4d4d77
-			BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
bffe20
-			return(0);
bffe20
-			}
4d4d77
+		strcpy(*host, buffer);
bffe20
 		}
bffe20
 end:
4d4d77
 	*sock=ret;
4d4d77
 	return(1);
4d4d77
 	}
4d4d77
 
4d4d77
-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
4d4d77
-	     short *port_ptr)
4d4d77
+int extract_host_port(char *str, char **host_ptr, 
4d4d77
+	     char **port_ptr)
4d4d77
 	{
4d4d77
-	char *h,*p;
4d4d77
+	char *h,*p,*x;
4d4d77
 
4d4d77
-	h=str;
4d4d77
-	p=strchr(str,':');
4d4d77
+	x=h=str;
4d4d77
+	if (*h == '[')
4d4d77
+		{
4d4d77
+		h++;
4d4d77
+		p=strchr(h,']');
4d4d77
 	if (p == NULL)
4d4d77
 		{
4d4d77
-		BIO_printf(bio_err,"no port defined\n");
4d4d77
+			BIO_printf(bio_err,"no ending bracket for IPv6 address\n");
4d4d77
 		return(0);
4d4d77
 		}
4d4d77
 	*(p++)='\0';
4d4d77
-
4d4d77
-	if ((ip != NULL) && !host_ip(str,ip))
4d4d77
-		goto err;
4d4d77
-	if (host_ptr != NULL) *host_ptr=h;
4d4d77
-
4d4d77
-	if (!extract_port(p,port_ptr))
4d4d77
-		goto err;
4d4d77
-	return(1);
4d4d77
-err:
4d4d77
-	return(0);
4d4d77
+		x = p;
4d4d77
 	}
4d4d77
-
4d4d77
-static int host_ip(char *str, unsigned char ip[4])
4d4d77
-	{
4d4d77
-	unsigned int in[4]; 
4d4d77
-	int i;
4d4d77
-
4d4d77
-	if (sscanf(str,"%u.%u.%u.%u",&(in[0]),&(in[1]),&(in[2]),&(in[3])) == 4)
4d4d77
-		{
4d4d77
-		for (i=0; i<4; i++)
4d4d77
-			if (in[i] > 255)
4d4d77
-				{
4d4d77
-				BIO_printf(bio_err,"invalid IP address\n");
4d4d77
-				goto err;
4d4d77
-				}
4d4d77
-		ip[0]=in[0];
4d4d77
-		ip[1]=in[1];
4d4d77
-		ip[2]=in[2];
4d4d77
-		ip[3]=in[3];
4d4d77
-		}
4d4d77
-	else
4d4d77
-		{ /* do a gethostbyname */
4d4d77
-		struct hostent *he;
4d4d77
-
4d4d77
-		if (!ssl_sock_init()) return(0);
4d4d77
-
4d4d77
-		he=GetHostByName(str);
4d4d77
-		if (he == NULL)
4d4d77
-			{
4d4d77
-			BIO_printf(bio_err,"gethostbyname failure\n");
4d4d77
-			goto err;
4d4d77
-			}
4d4d77
-		/* cast to short because of win16 winsock definition */
4d4d77
-		if ((short)he->h_addrtype != AF_INET)
4d4d77
+	p=strchr(x,':');
4d4d77
+	if (p == NULL)
4d4d77
 			{
4d4d77
-			BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
4d4d77
-			return(0);
4d4d77
-			}
4d4d77
-		ip[0]=he->h_addr_list[0][0];
4d4d77
-		ip[1]=he->h_addr_list[0][1];
4d4d77
-		ip[2]=he->h_addr_list[0][2];
4d4d77
-		ip[3]=he->h_addr_list[0][3];
4d4d77
-		}
4d4d77
-	return(1);
4d4d77
-err:
4d4d77
+		BIO_printf(bio_err,"no port defined\n");
4d4d77
 	return(0);
4d4d77
 	}
4d4d77
+	*(p++)='\0';
4d4d77
 
4d4d77
-int extract_port(char *str, short *port_ptr)
4d4d77
-	{
4d4d77
-	int i;
4d4d77
-	struct servent *s;
4d4d77
+	if (host_ptr != NULL) *host_ptr=h;
4d4d77
+	if (port_ptr != NULL) *port_ptr=p;
4d4d77
 
4d4d77
-	i=atoi(str);
4d4d77
-	if (i != 0)
4d4d77
-		*port_ptr=(unsigned short)i;
4d4d77
-	else
4d4d77
-		{
4d4d77
-		s=getservbyname(str,"tcp");
4d4d77
-		if (s == NULL)
4d4d77
-			{
4d4d77
-			BIO_printf(bio_err,"getservbyname failure for %s\n",str);
4d4d77
-			return(0);
4d4d77
-			}
4d4d77
-		*port_ptr=ntohs((unsigned short)s->s_port);
4d4d77
-		}
4d4d77
 	return(1);
4d4d77
 	}
4d4d77