Fix s_server DTLSv1_listen issues
authorMatt Caswell <matt@openssl.org>
Wed, 23 Sep 2015 09:02:18 +0000 (10:02 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 23 Sep 2015 12:53:27 +0000 (13:53 +0100)
Use sockaddr_storage not sockaddr for the client IP address to allow for
IPv6.
Also fixed a section of code which was conditional on OPENSSL_NO_DTLS1
which should not have been.

Reviewed-by: Andy Polyakov <appro@openssl.org>
apps/s_server.c

index dccd98f7ebdfce922cd4ca2f0a9f5f8662ef2498..ec739645f1a8b2deda8842ea88a35e154017ea66 100644 (file)
@@ -261,8 +261,8 @@ static int enable_timeouts = 0;
 static long socket_mtu;
 #ifndef OPENSSL_NO_DTLS1
 static int cert_chain = 0;
 static long socket_mtu;
 #ifndef OPENSSL_NO_DTLS1
 static int cert_chain = 0;
-static int dtlslisten = 0;
 #endif
 #endif
+static int dtlslisten = 0;
 
 static BIO *serverinfo_in = NULL;
 static const char *s_serverinfo_file = NULL;
 
 static BIO *serverinfo_in = NULL;
 static const char *s_serverinfo_file = NULL;
@@ -2395,7 +2395,7 @@ static int init_ssl_connection(SSL *con)
     unsigned next_proto_neg_len;
 #endif
     unsigned char *exportedkeymat;
     unsigned next_proto_neg_len;
 #endif
     unsigned char *exportedkeymat;
-    struct sockaddr client;
+    struct sockaddr_storage client;
 
 #ifndef OPENSSL_NO_DTLS1
     if(dtlslisten) {
 
 #ifndef OPENSSL_NO_DTLS1
     if(dtlslisten) {
@@ -2409,7 +2409,8 @@ static int init_ssl_connection(SSL *con)
                 BIO_get_fd(wbio, &fd);
             }
 
                 BIO_get_fd(wbio, &fd);
             }
 
-            if(!wbio || connect(fd, &client, sizeof(struct sockaddr))) {
+            if(!wbio || connect(fd, (struct sockaddr *)&client,
+                                sizeof(struct sockaddr_storage))) {
                 BIO_printf(bio_err, "ERROR - unable to connect\n");
                 return 0;
             }
                 BIO_printf(bio_err, "ERROR - unable to connect\n");
                 return 0;
             }
@@ -2447,13 +2448,11 @@ static int init_ssl_connection(SSL *con)
 #endif
 
     if (i <= 0) {
 #endif
 
     if (i <= 0) {
-#ifndef OPENSSL_NO_DTLS1
         if ((dtlslisten && i == 0)
                 || (!dtlslisten && BIO_sock_should_retry(i))) {
             BIO_printf(bio_s_out, "DELAY\n");
             return (1);
         }
         if ((dtlslisten && i == 0)
                 || (!dtlslisten && BIO_sock_should_retry(i))) {
             BIO_printf(bio_s_out, "DELAY\n");
             return (1);
         }
-#endif
 
         BIO_printf(bio_err, "ERROR\n");
 
 
         BIO_printf(bio_err, "ERROR\n");