Extensions to d2i_test.
[openssl.git] / test / dtlsv1listentest.c
index 5069dd505d38f01b62cd3eec0c64c80cfedc9ff5..6eb2e5ccfbb8abae301d5317ae3792884b80beb7 100644 (file)
 #include <openssl/bio.h>
 #include <openssl/err.h>
 #include <openssl/conf.h>
-#include <openssl/engine.h>
+#ifndef OPENSSL_NO_ENGINE
+ #include <openssl/engine.h>
+#endif
 #include "e_os.h"
 
+#ifndef OPENSSL_NO_SOCK
+
 /* Just a ClientHello without a cookie */
 static const unsigned char clienthello_nocookie[] = {
     0x16, /* Handshake */
@@ -337,7 +341,7 @@ static struct {
     }
 };
 
-#define COOKIE_LEN  20
+# define COOKIE_LEN  20
 
 static int cookie_gen(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)
 {
@@ -366,9 +370,11 @@ static int cookie_verify(SSL *ssl, const unsigned char *cookie,
 
     return 1;
 }
+#endif
 
 int main(void)
 {
+#ifndef OPENSSL_NO_SOCK
     SSL_CTX *ctx = NULL;
     SSL *ssl = NULL;
     BIO *outbio = NULL;
@@ -377,11 +383,7 @@ int main(void)
     char *data;
     long datalen;
     int ret, success = 0;
-    size_t i;
-
-    /* Initialise libssl */
-    SSL_load_error_strings();
-    SSL_library_init();
+    long i;
 
     ctx = SSL_CTX_new(DTLS_server_method());
     if (ctx == NULL || peer == NULL)
@@ -401,7 +403,7 @@ int main(void)
     SSL_set_wbio(ssl, outbio);
 
     success = 1;
-    for (i = 0; i < OSSL_NELEM(testpackets) && success; i++) {
+    for (i = 0; i < (long)OSSL_NELEM(testpackets) && success; i++) {
         inbio = BIO_new_mem_buf((char *)testpackets[i].in,
                                 testpackets[i].inlen);
         if (inbio == NULL) {
@@ -460,18 +462,13 @@ int main(void)
     SSL_free(ssl);
     SSL_CTX_free(ctx);
     BIO_free(inbio);
-    /* Unitialise libssl */
-#ifndef OPENSSL_NO_ENGINE
-    ENGINE_cleanup();
-#endif
-    CONF_modules_unload(1);
-    CRYPTO_cleanup_all_ex_data();
-    EVP_cleanup();
-    ERR_remove_thread_state(NULL);
-    ERR_free_strings();
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
+    OPENSSL_free(peer);
+# ifndef OPENSSL_NO_CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
-#endif
+# endif
     return success ? 0 : 1;
+#else
+    printf("DTLSv1_listen() is not supported by this build - skipping\n");
+    return 0;
+#endif
 }
-