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

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