4d4d77
diff --exclude-from=exclude-diff-openssl-0.9.8b -bru openssl-0.9.8b.orig/apps/s_apps.h openssl-0.9.8b/apps/s_apps.h
4d4d77
--- openssl-0.9.8b.orig/apps/s_apps.h	2006-07-11 16:14:29.000000000 +0200
4d4d77
+++ openssl-0.9.8b/apps/s_apps.h	2006-07-13 08:44:29.000000000 +0200
4d4d77
@@ -148,7 +148,7 @@
4d4d77
 #define PORT_STR        "4433"
4d4d77
 #define PROTOCOL        "tcp"
4d4d77
 
4d4d77
-int do_server(int port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
4d4d77
+int do_server(char *port, int type, int *ret, int (*cb) (char *hostname, int s, unsigned char *context), unsigned char *context);
4d4d77
 #ifdef HEADER_X509_H
4d4d77
 int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
4d4d77
 #endif
4d4d77
@@ -156,10 +156,9 @@
4d4d77
 int set_cert_stuff(SSL_CTX *ctx, char *cert_file, char *key_file);
4d4d77
 int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key);
4d4d77
 #endif
4d4d77
-int init_client(int *sock, char *server, int port, int type);
4d4d77
+int init_client(int *sock, char *server, char *port, int type);
4d4d77
 int should_retry(int i);
4d4d77
-int extract_port(char *str, short *port_ptr);
4d4d77
-int extract_host_port(char *str,char **host_ptr,unsigned char *ip,short *p);
4d4d77
+int extract_host_port(char *str,char **host_ptr,char **port_ptr);
4d4d77
 
4d4d77
 long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
4d4d77
 	int argi, long argl, long ret);
4d4d77
diff --exclude-from=exclude-diff-openssl-0.9.8b -bru openssl-0.9.8b.orig/apps/s_client.c openssl-0.9.8b/apps/s_client.c
4d4d77
--- openssl-0.9.8b.orig/apps/s_client.c	2005-11-25 14:46:41.000000000 +0100
4d4d77
+++ openssl-0.9.8b/apps/s_client.c	2006-07-13 08:44:29.000000000 +0200
4d4d77
@@ -246,7 +246,7 @@
4d4d77
 	int cbuf_len,cbuf_off;
4d4d77
 	int sbuf_len,sbuf_off;
4d4d77
 	fd_set readfds,writefds;
4d4d77
-	short port=PORT;
4d4d77
+	char *port_str = PORT_STR;
4d4d77
 	int full_log=1;
4d4d77
 	char *host=SSL_HOST_NAME;
4d4d77
 	char *cert_file=NULL,*key_file=NULL;
4d4d77
@@ -330,13 +330,12 @@
4d4d77
 		else if	(strcmp(*argv,"-port") == 0)
4d4d77
 			{
4d4d77
 			if (--argc < 1) goto bad;
4d4d77
-			port=atoi(*(++argv));
4d4d77
-			if (port == 0) goto bad;
4d4d77
+			port_str= *(++argv);
4d4d77
 			}
4d4d77
 		else if (strcmp(*argv,"-connect") == 0)
4d4d77
 			{
4d4d77
 			if (--argc < 1) goto bad;
4d4d77
-			if (!extract_host_port(*(++argv),&host,NULL,&port))
4d4d77
+			if (!extract_host_port(*(++argv),&host,&port_str))
4d4d77
 				goto bad;
4d4d77
 			}
4d4d77
 		else if	(strcmp(*argv,"-verify") == 0)
4d4d77
@@ -619,7 +618,7 @@
4d4d77
 
4d4d77
 re_start:
4d4d77
 
4d4d77
-	if (init_client(&s,host,port,sock_type) == 0)
4d4d77
+	if (init_client(&s,host,port_str,sock_type) == 0)
4d4d77
 		{
4d4d77
 		BIO_printf(bio_err,"connect:errno=%d\n",get_last_socket_error());
4d4d77
 		SHUTDOWN(s);
4d4d77
diff --exclude-from=exclude-diff-openssl-0.9.8b -bru openssl-0.9.8b.orig/apps/s_server.c openssl-0.9.8b/apps/s_server.c
4d4d77
--- openssl-0.9.8b.orig/apps/s_server.c	2005-09-02 14:27:02.000000000 +0200
4d4d77
+++ openssl-0.9.8b/apps/s_server.c	2006-07-13 08:44:29.000000000 +0200
4d4d77
@@ -532,7 +532,7 @@
4d4d77
 	{
4d4d77
 	X509_STORE *store = NULL;
4d4d77
 	int vflags = 0;
4d4d77
-	short port=PORT;
4d4d77
+	char *port_str = PORT_STR;
4d4d77
 	char *CApath=NULL,*CAfile=NULL;
4d4d77
 	unsigned char *context = NULL;
4d4d77
 	char *dhfile = NULL;
4d4d77
@@ -597,8 +597,7 @@
4d4d77
 			 (strcmp(*argv,"-accept") == 0))
4d4d77
 			{
4d4d77
 			if (--argc < 1) goto bad;
4d4d77
-			if (!extract_port(*(++argv),&port))
4d4d77
-				goto bad;
4d4d77
+			port_str= *(++argv);
4d4d77
 			}
4d4d77
 		else if	(strcmp(*argv,"-verify") == 0)
4d4d77
 			{
4d4d77
@@ -1086,9 +1085,9 @@
4d4d77
 
4d4d77
 	BIO_printf(bio_s_out,"ACCEPT\n");
4d4d77
 	if (www)
4d4d77
-		do_server(port,sock_type,&accept_socket,www_body, context);
4d4d77
+		do_server(port_str,sock_type,&accept_socket,www_body, context);
4d4d77
 	else
4d4d77
-		do_server(port,sock_type,&accept_socket,sv_body, context);
4d4d77
+		do_server(port_str,sock_type,&accept_socket,sv_body, context);
4d4d77
 	print_stats(bio_s_out,ctx);
4d4d77
 	ret=0;
4d4d77
 end:
4d4d77
diff --exclude-from=exclude-diff-openssl-0.9.8b -bru openssl-0.9.8b.orig/apps/s_socket.c openssl-0.9.8b/apps/s_socket.c
4d4d77
--- openssl-0.9.8b.orig/apps/s_socket.c	2005-06-13 05:21:00.000000000 +0200
4d4d77
+++ openssl-0.9.8b/apps/s_socket.c	2006-07-13 08:44:29.000000000 +0200
4d4d77
@@ -96,9 +96,7 @@
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
 
4d4d77
@@ -228,60 +226,69 @@
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
-	short p=0;
4d4d77
-
4d4d77
-	if (!host_ip(host,&(ip[0])))
4d4d77
-		{
4d4d77
-		return(0);
4d4d77
-		}
4d4d77
-	if (p != 0) port=p;
4d4d77
-	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
+			}
4d4d77
 #ifndef 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)
4d4d77
-		{ close(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
 	}
4d4d77
+		failed_call = "socket";
4d4d77
+nextres:
4d4d77
+		if (s != INVALID_SOCKET)
4d4d77
+			close(s);
4d4d77
+		res = res->ai_next;
4d4d77
+		}
4d4d77
+	freeaddrinfo(res0);
4d4d77
+
4d4d77
+	perror(failed_call);
4d4d77
+	return(0);
4d4d77
+	}
4d4d77
 
4d4d77
-int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
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;
4d4d77
@@ -319,33 +326,38 @@
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;
4d4d77
-	int s= -1,i;
4d4d77
+	struct addrinfo *res, *res0, hints;
4d4d77
+	char * failed_call = NULL;
4d4d77
+	char port_name[8];
4d4d77
+	int s;
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
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
+	memset(&hints, '\0', sizeof(hints));
4d4d77
+	hints.ai_socktype = type;
4d4d77
+	hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
4d4d77
+	
4d4d77
+	e = getaddrinfo(NULL, 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
-	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
+			}
4d4d77
 #if defined SOL_SOCKET && defined SO_REUSEADDR
4d4d77
 		{
4d4d77
 		int j = 1;
4d4d77
@@ -353,36 +365,39 @@
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
-	i=0;
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
 	}
4d4d77
+	freeaddrinfo(res0);
4d4d77
 
4d4d77
-static int init_server(int *sock, int port, int type)
4d4d77
-	{
4d4d77
-	return(init_server_long(sock, port, NULL, type));
4d4d77
+	if (s == INVALID_SOCKET) { perror("socket"); return(0); }
4d4d77
+
4d4d77
+	perror(failed_call);
4d4d77
+	return(0);
4d4d77
 	}
4d4d77
 
4d4d77
 static int do_accept(int acc_sock, int *sock, char **host)
4d4d77
 	{
4d4d77
-	int ret,i;
4d4d77
-	struct hostent *h1,*h2;
4d4d77
-	static struct sockaddr_in from;
4d4d77
+	static struct sockaddr_storage from;
4d4d77
+	char buffer[NI_MAXHOST];
4d4d77
+	int ret;
4d4d77
 	int len;
4d4d77
 /*	struct linger ling; */
4d4d77
 
4d4d77
@@ -427,137 +442,62 @@
4d4d77
 	if (i < 0) { perror("keepalive"); return(0); }
4d4d77
 */
4d4d77
 
4d4d77
-	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)
4d4d77
+	if (host == NULL)
4d4d77
 		{
4d4d77
-		BIO_printf(bio_err,"bad gethostbyaddr\n");
4d4d77
-		*host=NULL;
4d4d77
-		/* return(0); */
4d4d77
-		}
4d4d77
-	else
4d4d77
-		{
4d4d77
-		if ((*host=(char *)OPENSSL_malloc(strlen(h1->h_name)+1)) == NULL)
4d4d77
-			{
4d4d77
-			perror("OPENSSL_malloc");
4d4d77
+		*sock=ret;
4d4d77
 			return(0);
4d4d77
 			}
4d4d77
-		BUF_strlcpy(*host,h1->h_name,strlen(h1->h_name)+1);
4d4d77
 
4d4d77
-		h2=GetHostByName(*host);
4d4d77
-		if (h2 == NULL)
4d4d77
+	if (getnameinfo((struct sockaddr *)&from, sizeof(from),
4d4d77
+		buffer, sizeof(buffer),
4d4d77
+		NULL, 0, 0))
4d4d77
 			{
4d4d77
-			BIO_printf(bio_err,"gethostbyname failure\n");
4d4d77
+		BIO_printf(bio_err,"getnameinfo failed\n");
4d4d77
+		*host=NULL;
4d4d77
 			return(0);
4d4d77
 			}
4d4d77
-		i=0;
4d4d77
-		if (h2->h_addrtype != AF_INET)
4d4d77
+	else
4d4d77
 			{
4d4d77
-			BIO_printf(bio_err,"gethostbyname addr is not AF_INET\n");
4d4d77
+		if ((*host=(char *)OPENSSL_malloc(strlen(buffer)+1)) == NULL)
4d4d77
+			{
4d4d77
+			perror("OPENSSL_malloc");
4d4d77
 			return(0);
4d4d77
 			}
4d4d77
-		}
4d4d77
-end:
4d4d77
+		strcpy(*host, buffer);
4d4d77
 	*sock=ret;
4d4d77
 	return(1);
4d4d77
 	}
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