Blame SOURCES/openssl-1.0.1c-ipv6-apps.patch

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