Blame SOURCES/openssl-1.0.2a-ipv6-apps.patch

aa8173
diff -up openssl-1.0.2a/apps/s_apps.h.ipv6-apps openssl-1.0.2a/apps/s_apps.h
aa8173
--- openssl-1.0.2a/apps/s_apps.h.ipv6-apps	2015-04-20 15:01:24.029120104 +0200
aa8173
+++ openssl-1.0.2a/apps/s_apps.h	2015-04-20 15:05:00.353137701 +0200
aa8173
@@ -151,7 +151,7 @@ typedef fd_mask fd_set;
aa8173
 #define PORT_STR        "4433"
aa8173
 #define PROTOCOL        "tcp"
aa8173
 
aa8173
-int do_server(int port, int type, int *ret,
aa8173
+int do_server(char *port, int type, int *ret,
aa8173
               int (*cb) (char *hostname, int s, int stype,
aa8173
                          unsigned char *context), unsigned char *context,
aa8173
               int naccept);
aa8173
@@ -167,11 +167,10 @@ int ssl_print_point_formats(BIO *out, SS
aa8173
 int ssl_print_curves(BIO *out, SSL *s, int noshared);
aa8173
 #endif
aa8173
 int ssl_print_tmp_key(BIO *out, SSL *s);
aa8173
-int init_client(int *sock, char *server, int port, int type);
aa8173
+int init_client(int *sock, char *server, char *port, int type);
aa8173
 int should_retry(int i);
aa8173
 int extract_port(char *str, short *port_ptr);
aa8173
-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
aa8173
-                      short *p);
aa8173
+int extract_host_port(char *str, char **host_ptr, char **port_ptr);
aa8173
 
aa8173
 long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
aa8173
                                    int argi, long argl, long ret);
aa8173
diff -up openssl-1.0.2a/apps/s_client.c.ipv6-apps openssl-1.0.2a/apps/s_client.c
aa8173
--- openssl-1.0.2a/apps/s_client.c.ipv6-apps	2015-04-20 15:01:24.022119942 +0200
aa8173
+++ openssl-1.0.2a/apps/s_client.c	2015-04-20 15:06:42.338503234 +0200
aa8173
@@ -662,7 +662,7 @@ int MAIN(int argc, char **argv)
aa8173
     int cbuf_len, cbuf_off;
aa8173
     int sbuf_len, sbuf_off;
aa8173
     fd_set readfds, writefds;
aa8173
-    short port = PORT;
aa8173
+    char *port_str = PORT_STR;
aa8173
     int full_log = 1;
aa8173
     char *host = SSL_HOST_NAME;
aa8173
     char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;
aa8173
@@ -785,13 +785,11 @@ int MAIN(int argc, char **argv)
aa8173
         } else if (strcmp(*argv, "-port") == 0) {
aa8173
             if (--argc < 1)
aa8173
                 goto bad;
aa8173
-            port = atoi(*(++argv));
aa8173
-            if (port == 0)
aa8173
-                goto bad;
aa8173
+            port_str = *(++argv);
aa8173
         } else if (strcmp(*argv, "-connect") == 0) {
aa8173
             if (--argc < 1)
aa8173
                 goto bad;
aa8173
-            if (!extract_host_port(*(++argv), &host, NULL, &port))
aa8173
+            if (!extract_host_port(*(++argv), &host, &port_str))
aa8173
                 goto bad;
aa8173
         } else if (strcmp(*argv, "-verify") == 0) {
aa8173
             verify = SSL_VERIFY_PEER;
aa8173
@@ -1417,7 +1415,7 @@ int MAIN(int argc, char **argv)
aa8173
 
aa8173
  re_start:
aa8173
 
aa8173
-    if (init_client(&s, host, port, socket_type) == 0) {
aa8173
+    if (init_client(&s, host, port_str, socket_type) == 0) {
aa8173
         BIO_printf(bio_err, "connect:errno=%d\n", get_last_socket_error());
aa8173
         SHUTDOWN(s);
aa8173
         goto end;
aa8173
diff -up openssl-1.0.2a/apps/s_server.c.ipv6-apps openssl-1.0.2a/apps/s_server.c
aa8173
--- openssl-1.0.2a/apps/s_server.c.ipv6-apps	2015-04-20 15:01:24.030120127 +0200
aa8173
+++ openssl-1.0.2a/apps/s_server.c	2015-04-20 15:10:47.245187746 +0200
aa8173
@@ -1061,7 +1061,7 @@ int MAIN(int argc, char *argv[])
aa8173
 {
aa8173
     X509_VERIFY_PARAM *vpm = NULL;
aa8173
     int badarg = 0;
aa8173
-    short port = PORT;
aa8173
+    char *port_str = PORT_STR;
aa8173
     char *CApath = NULL, *CAfile = NULL;
aa8173
     char *chCApath = NULL, *chCAfile = NULL;
aa8173
     char *vfyCApath = NULL, *vfyCAfile = NULL;
aa8173
@@ -1148,7 +1148,8 @@ int MAIN(int argc, char *argv[])
aa8173
         if ((strcmp(*argv, "-port") == 0) || (strcmp(*argv, "-accept") == 0)) {
aa8173
             if (--argc < 1)
aa8173
                 goto bad;
aa8173
-            if (!extract_port(*(++argv), &port))
aa8173
+            port_str = *(++argv);
aa8173
+            if (port_str == NULL || *port_str == '\0')
aa8173
                 goto bad;
aa8173
         } else if (strcmp(*argv, "-naccept") == 0) {
aa8173
             if (--argc < 1)
aa8173
@@ -2020,13 +2021,13 @@ int MAIN(int argc, char *argv[])
aa8173
     BIO_printf(bio_s_out, "ACCEPT\n");
aa8173
     (void)BIO_flush(bio_s_out);
aa8173
     if (rev)
aa8173
-        do_server(port, socket_type, &accept_socket, rev_body, context,
aa8173
+        do_server(port_str, socket_type, &accept_socket, rev_body, context,
aa8173
                   naccept);
aa8173
     else if (www)
aa8173
-        do_server(port, socket_type, &accept_socket, www_body, context,
aa8173
+        do_server(port_str, socket_type, &accept_socket, www_body, context,
aa8173
                   naccept);
aa8173
     else
aa8173
-        do_server(port, socket_type, &accept_socket, sv_body, context,
aa8173
+        do_server(port_str, socket_type, &accept_socket, sv_body, context,
aa8173
                   naccept);
aa8173
     print_stats(bio_s_out, ctx);
aa8173
     ret = 0;
aa8173
diff -up openssl-1.0.2a/apps/s_socket.c.ipv6-apps openssl-1.0.2a/apps/s_socket.c
aa8173
--- openssl-1.0.2a/apps/s_socket.c.ipv6-apps	2015-03-19 14:30:36.000000000 +0100
aa8173
+++ openssl-1.0.2a/apps/s_socket.c	2015-04-20 15:32:53.960079507 +0200
aa8173
@@ -106,9 +106,7 @@ static struct hostent *GetHostByName(cha
aa8173
 static void ssl_sock_cleanup(void);
aa8173
 # endif
aa8173
 static int ssl_sock_init(void);
aa8173
-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type);
aa8173
-static int init_server(int *sock, int port, int type);
aa8173
-static int init_server_long(int *sock, int port, char *ip, int type);
aa8173
+static int init_server(int *sock, char *port, int type);
aa8173
 static int do_accept(int acc_sock, int *sock, char **host);
aa8173
 static int host_ip(char *str, unsigned char ip[4]);
aa8173
 
aa8173
@@ -231,65 +229,66 @@ static int ssl_sock_init(void)
aa8173
     return (1);
aa8173
 }
aa8173
 
aa8173
-int init_client(int *sock, char *host, int port, int type)
aa8173
+int init_client(int *sock, char *host, char *port, int type)
aa8173
 {
aa8173
-    unsigned char ip[4];
aa8173
-
aa8173
-    memset(ip, '\0', sizeof ip);
aa8173
-    if (!host_ip(host, &(ip[0])))
aa8173
-        return 0;
aa8173
-    return init_client_ip(sock, ip, port, type);
aa8173
-}
aa8173
-
aa8173
-static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
aa8173
-{
aa8173
-    unsigned long addr;
aa8173
-    struct sockaddr_in them;
aa8173
-    int s, i;
aa8173
+    struct addrinfo *res, *res0, hints;
aa8173
+    char *failed_call = NULL;
aa8173
+    int s;
aa8173
+    int e;
aa8173
 
aa8173
     if (!ssl_sock_init())
aa8173
         return (0);
aa8173
 
aa8173
-    memset((char *)&them, 0, sizeof(them));
aa8173
-    them.sin_family = AF_INET;
aa8173
-    them.sin_port = htons((unsigned short)port);
aa8173
-    addr = (unsigned long)
aa8173
-        ((unsigned long)ip[0] << 24L) |
aa8173
-        ((unsigned long)ip[1] << 16L) |
aa8173
-        ((unsigned long)ip[2] << 8L) | ((unsigned long)ip[3]);
aa8173
-    them.sin_addr.s_addr = htonl(addr);
aa8173
-
aa8173
-    if (type == SOCK_STREAM)
aa8173
-        s = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
aa8173
-    else                        /* ( type == SOCK_DGRAM) */
aa8173
-        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
aa8173
-
aa8173
-    if (s == INVALID_SOCKET) {
aa8173
-        perror("socket");
aa8173
+    memset(&hints, '\0', sizeof(hints));
aa8173
+    hints.ai_socktype = type;
aa8173
+    hints.ai_flags = AI_ADDRCONFIG;
aa8173
+
aa8173
+    e = getaddrinfo(host, port, &hints, &res;;
aa8173
+    if (e) {
aa8173
+        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
aa8173
+        if (e == EAI_SYSTEM)
aa8173
+            perror("getaddrinfo");
aa8173
         return (0);
aa8173
     }
aa8173
+
aa8173
+    res0 = res;
aa8173
+    while (res) {
aa8173
+        s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
aa8173
+        if (s == INVALID_SOCKET) {
aa8173
+            failed_call = "socket";
aa8173
+            goto nextres;
aa8173
+        }
aa8173
 # if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
aa8173
-    if (type == SOCK_STREAM) {
aa8173
-        i = 0;
aa8173
-        i = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, sizeof(i));
aa8173
-        if (i < 0) {
aa8173
-            closesocket(s);
aa8173
-            perror("keepalive");
aa8173
-            return (0);
aa8173
+        if (type == SOCK_STREAM) {
aa8173
+            int i = 0;
aa8173
+            i = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
aa8173
+                           (char *)&i, sizeof(i));
aa8173
+            if (i < 0) {
aa8173
+                failed_call = "keepalive";
aa8173
+                goto nextres;
aa8173
+            }
aa8173
         }
aa8173
-    }
aa8173
 # endif
aa8173
-
aa8173
-    if (connect(s, (struct sockaddr *)&them, sizeof(them)) == -1) {
aa8173
-        closesocket(s);
aa8173
-        perror("connect");
aa8173
-        return (0);
aa8173
+        if (connect(s, (struct sockaddr *)res->ai_addr, res->ai_addrlen) == 0) {
aa8173
+            freeaddrinfo(res0);
aa8173
+            *sock = s;
aa8173
+            return (1);
aa8173
+        }
aa8173
+
aa8173
+        failed_call = "socket";
aa8173
+ nextres:
aa8173
+        if (s != INVALID_SOCKET)
aa8173
+            close(s);
aa8173
+        res = res->ai_next;
aa8173
     }
aa8173
-    *sock = s;
aa8173
-    return (1);
aa8173
+    freeaddrinfo(res0);
aa8173
+    closesocket(s);
aa8173
+
aa8173
+    perror(failed_call);
aa8173
+    return (0);
aa8173
 }
aa8173
 
aa8173
-int do_server(int port, int type, int *ret,
aa8173
+int do_server(char *port, int type, int *ret,
aa8173
               int (*cb) (char *hostname, int s, int stype,
aa8173
                          unsigned char *context), unsigned char *context,
aa8173
               int naccept)
aa8173
@@ -328,69 +327,89 @@ int do_server(int port, int type, int *r
aa8173
     }
aa8173
 }
aa8173
 
aa8173
-static int init_server_long(int *sock, int port, char *ip, int type)
aa8173
+static int init_server(int *sock, char *port, int type)
aa8173
 {
aa8173
-    int ret = 0;
aa8173
-    struct sockaddr_in server;
aa8173
-    int s = -1;
aa8173
+    struct addrinfo *res, *res0 = NULL, hints;
aa8173
+    char *failed_call = NULL;
aa8173
+    int s = INVALID_SOCKET;
aa8173
+    int e;
aa8173
 
aa8173
     if (!ssl_sock_init())
aa8173
         return (0);
aa8173
 
aa8173
-    memset((char *)&server, 0, sizeof(server));
aa8173
-    server.sin_family = AF_INET;
aa8173
-    server.sin_port = htons((unsigned short)port);
aa8173
-    if (ip == NULL)
aa8173
-        server.sin_addr.s_addr = INADDR_ANY;
aa8173
-    else
aa8173
-/* Added for T3E, address-of fails on bit field (beckman@acl.lanl.gov) */
aa8173
-# ifndef BIT_FIELD_LIMITS
aa8173
-        memcpy(&server.sin_addr.s_addr, ip, 4);
aa8173
-# else
aa8173
-        memcpy(&server.sin_addr, ip, 4);
aa8173
-# endif
aa8173
-
aa8173
-    if (type == SOCK_STREAM)
aa8173
-        s = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
aa8173
-    else                        /* type == SOCK_DGRAM */
aa8173
-        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
aa8173
+    memset(&hints, '\0', sizeof(hints));
aa8173
+    hints.ai_family = AF_INET6;
aa8173
+ tryipv4:
aa8173
+    hints.ai_socktype = type;
aa8173
+    hints.ai_flags = AI_PASSIVE;
aa8173
+
aa8173
+    e = getaddrinfo(NULL, port, &hints, &res;;
aa8173
+    if (e) {
aa8173
+        if (hints.ai_family == AF_INET) {
aa8173
+            fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
aa8173
+            if (e == EAI_SYSTEM)
aa8173
+                perror("getaddrinfo");
aa8173
+            return (0);
aa8173
+        } else
aa8173
+            res = NULL;
aa8173
+    }
aa8173
 
aa8173
-    if (s == INVALID_SOCKET)
aa8173
-        goto err;
aa8173
+    res0 = res;
aa8173
+    while (res) {
aa8173
+        s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
aa8173
+        if (s == INVALID_SOCKET) {
aa8173
+            failed_call = "socket";
aa8173
+            goto nextres;
aa8173
+        }
aa8173
+        if (hints.ai_family == AF_INET6) {
aa8173
+            int j = 0;
aa8173
+            setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&j, sizeof j);
aa8173
+        }
aa8173
 # if defined SOL_SOCKET && defined SO_REUSEADDR
aa8173
-    {
aa8173
-        int j = 1;
aa8173
-        setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&j, sizeof j);
aa8173
-    }
aa8173
-# endif
aa8173
-    if (bind(s, (struct sockaddr *)&server, sizeof(server)) == -1) {
aa8173
-# ifndef OPENSSL_SYS_WINDOWS
aa8173
-        perror("bind");
aa8173
+        {
aa8173
+            int j = 1;
aa8173
+            setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&j, sizeof j);
aa8173
+        }
aa8173
 # endif
aa8173
-        goto err;
aa8173
+
aa8173
+        if (bind(s, (struct sockaddr *)res->ai_addr, res->ai_addrlen) == -1) {
aa8173
+            failed_call = "bind";
aa8173
+            goto nextres;
aa8173
+        }
aa8173
+        if (type == SOCK_STREAM && listen(s, 128) == -1) {
aa8173
+            failed_call = "listen";
aa8173
+            goto nextres;
aa8173
+        }
aa8173
+
aa8173
+        *sock = s;
aa8173
+        return (1);
aa8173
+
aa8173
+ nextres:
aa8173
+        if (s != INVALID_SOCKET)
aa8173
+            close(s);
aa8173
+        res = res->ai_next;
aa8173
     }
aa8173
-    /* Make it 128 for linux */
aa8173
-    if (type == SOCK_STREAM && listen(s, 128) == -1)
aa8173
-        goto err;
aa8173
-    *sock = s;
aa8173
-    ret = 1;
aa8173
- err:
aa8173
-    if ((ret == 0) && (s != -1)) {
aa8173
-        SHUTDOWN(s);
aa8173
+    if (res0)
aa8173
+        freeaddrinfo(res0);
aa8173
+
aa8173
+    if (s == INVALID_SOCKET) {
aa8173
+        if (hints.ai_family == AF_INET6) {
aa8173
+            hints.ai_family = AF_INET;
aa8173
+            goto tryipv4;
aa8173
+        }
aa8173
+        perror("socket");
aa8173
+        return (0);
aa8173
     }
aa8173
-    return (ret);
aa8173
-}
aa8173
 
aa8173
-static int init_server(int *sock, int port, int type)
aa8173
-{
aa8173
-    return (init_server_long(sock, port, NULL, type));
aa8173
+    perror(failed_call);
aa8173
+    return (0);
aa8173
 }
aa8173
 
aa8173
 static int do_accept(int acc_sock, int *sock, char **host)
aa8173
 {
aa8173
+    static struct sockaddr_storage from;
aa8173
+    char buffer[NI_MAXHOST];
aa8173
     int ret;
aa8173
-    struct hostent *h1, *h2;
aa8173
-    static struct sockaddr_in from;
aa8173
     int len;
aa8173
 /*      struct linger ling; */
aa8173
 
aa8173
@@ -432,134 +451,60 @@ static int do_accept(int acc_sock, int *
aa8173
     ling.l_onoff=1;
aa8173
     ling.l_linger=0;
aa8173
     i=setsockopt(ret,SOL_SOCKET,SO_LINGER,(char *)&ling,sizeof(ling));
aa8173
-    if (i < 0) { perror("linger"); return(0); }
aa8173
+    if (i < 0) { closesocket(ret); perror("linger"); return(0); }
aa8173
     i=0;
aa8173
     i=setsockopt(ret,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
aa8173
-    if (i < 0) { perror("keepalive"); return(0); }
aa8173
+    if (i < 0) { closesocket(ret); perror("keepalive"); return(0); }
aa8173
 */
aa8173
 
aa8173
     if (host == NULL)
aa8173
         goto end;
aa8173
-# ifndef BIT_FIELD_LIMITS
aa8173
-    /* I should use WSAAsyncGetHostByName() under windows */
aa8173
-    h1 = gethostbyaddr((char *)&from.sin_addr.s_addr,
aa8173
-                       sizeof(from.sin_addr.s_addr), AF_INET);
aa8173
-# else
aa8173
-    h1 = gethostbyaddr((char *)&from.sin_addr,
aa8173
-                       sizeof(struct in_addr), AF_INET);
aa8173
-# endif
aa8173
-    if (h1 == NULL) {
aa8173
-        BIO_printf(bio_err, "bad gethostbyaddr\n");
aa8173
+
aa8173
+    if (getnameinfo((struct sockaddr *)&from, sizeof(from),
aa8173
+                    buffer, sizeof(buffer), NULL, 0, 0)) {
aa8173
+        BIO_printf(bio_err, "getnameinfo failed\n");
aa8173
         *host = NULL;
aa8173
         /* return(0); */
aa8173
     } else {
aa8173
-        if ((*host = (char *)OPENSSL_malloc(strlen(h1->h_name) + 1)) == NULL) {
aa8173
+        if ((*host = (char *)OPENSSL_malloc(strlen(buffer) + 1)) == NULL) {
aa8173
             perror("OPENSSL_malloc");
aa8173
             closesocket(ret);
aa8173
             return (0);
aa8173
         }
aa8173
-        BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1);
aa8173
-
aa8173
-        h2 = GetHostByName(*host);
aa8173
-        if (h2 == NULL) {
aa8173
-            BIO_printf(bio_err, "gethostbyname failure\n");
aa8173
-            closesocket(ret);
aa8173
-            return (0);
aa8173
-        }
aa8173
-        if (h2->h_addrtype != AF_INET) {
aa8173
-            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
aa8173
-            closesocket(ret);
aa8173
-            return (0);
aa8173
-        }
aa8173
+        strcpy(*host, buffer);
aa8173
     }
aa8173
  end:
aa8173
     *sock = ret;
aa8173
     return (1);
aa8173
 }
aa8173
 
aa8173
-int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
aa8173
-                      short *port_ptr)
aa8173
+int extract_host_port(char *str, char **host_ptr, char **port_ptr)
aa8173
 {
aa8173
-    char *h, *p;
aa8173
+    char *h, *p, *x;
aa8173
 
aa8173
-    h = str;
aa8173
-    p = strchr(str, ':');
aa8173
+    x = h = str;
aa8173
+    if (*h == '[') {
aa8173
+        h++;
aa8173
+        p = strchr(h, ']');
aa8173
+        if (p == NULL) {
aa8173
+            BIO_printf(bio_err, "no ending bracket for IPv6 address\n");
aa8173
+            return (0);
aa8173
+        }
aa8173
+        *(p++) = '\0';
aa8173
+        x = p;
aa8173
+    }
aa8173
+    p = strchr(x, ':');
aa8173
     if (p == NULL) {
aa8173
         BIO_printf(bio_err, "no port defined\n");
aa8173
         return (0);
aa8173
     }
aa8173
     *(p++) = '\0';
aa8173
 
aa8173
-    if ((ip != NULL) && !host_ip(str, ip))
aa8173
-        goto err;
aa8173
     if (host_ptr != NULL)
aa8173
         *host_ptr = h;
aa8173
+    if (port_ptr != NULL)
aa8173
+        *port_ptr = p;
aa8173
 
aa8173
-    if (!extract_port(p, port_ptr))
aa8173
-        goto err;
aa8173
-    return (1);
aa8173
- err:
aa8173
-    return (0);
aa8173
-}
aa8173
-
aa8173
-static int host_ip(char *str, unsigned char ip[4])
aa8173
-{
aa8173
-    unsigned int in[4];
aa8173
-    int i;
aa8173
-
aa8173
-    if (sscanf(str, "%u.%u.%u.%u", &(in[0]), &(in[1]), &(in[2]), &(in[3])) ==
aa8173
-        4) {
aa8173
-        for (i = 0; i < 4; i++)
aa8173
-            if (in[i] > 255) {
aa8173
-                BIO_printf(bio_err, "invalid IP address\n");
aa8173
-                goto err;
aa8173
-            }
aa8173
-        ip[0] = in[0];
aa8173
-        ip[1] = in[1];
aa8173
-        ip[2] = in[2];
aa8173
-        ip[3] = in[3];
aa8173
-    } else {                    /* do a gethostbyname */
aa8173
-        struct hostent *he;
aa8173
-
aa8173
-        if (!ssl_sock_init())
aa8173
-            return (0);
aa8173
-
aa8173
-        he = GetHostByName(str);
aa8173
-        if (he == NULL) {
aa8173
-            BIO_printf(bio_err, "gethostbyname failure\n");
aa8173
-            goto err;
aa8173
-        }
aa8173
-        /* cast to short because of win16 winsock definition */
aa8173
-        if ((short)he->h_addrtype != AF_INET) {
aa8173
-            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
aa8173
-            return (0);
aa8173
-        }
aa8173
-        ip[0] = he->h_addr_list[0][0];
aa8173
-        ip[1] = he->h_addr_list[0][1];
aa8173
-        ip[2] = he->h_addr_list[0][2];
aa8173
-        ip[3] = he->h_addr_list[0][3];
aa8173
-    }
aa8173
-    return (1);
aa8173
- err:
aa8173
-    return (0);
aa8173
-}
aa8173
-
aa8173
-int extract_port(char *str, short *port_ptr)
aa8173
-{
aa8173
-    int i;
aa8173
-    struct servent *s;
aa8173
-
aa8173
-    i = atoi(str);
aa8173
-    if (i != 0)
aa8173
-        *port_ptr = (unsigned short)i;
aa8173
-    else {
aa8173
-        s = getservbyname(str, "tcp");
aa8173
-        if (s == NULL) {
aa8173
-            BIO_printf(bio_err, "getservbyname failure for %s\n", str);
aa8173
-            return (0);
aa8173
-        }
aa8173
-        *port_ptr = ntohs((unsigned short)s->s_port);
aa8173
-    }
aa8173
     return (1);
aa8173
 }
aa8173