From 72740cb687fe2decdf1a93bc185fce78357778be Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 24 Nov 2018 22:07:22 +0000 Subject: [PATCH] tests/test_tls.c: Add in GnuTLS build support HAVE_GNUTLS -> HAVE_LIBGNUTLS Correct TinyDTLS version checks as TinyDTLS is now returning the actual TinyDTLS library version. For TinyDTLS builds, #undef PACKAGE_* to remove compiler warnings. --- tests/test_tls.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/test_tls.c b/tests/test_tls.c index 1278b146..517f14f1 100644 --- a/tests/test_tls.c +++ b/tests/test_tls.c @@ -16,8 +16,17 @@ #ifdef HAVE_LIBTINYDTLS #define HAVE_DTLS 1 +/* Need to #undef these to stop compiler warnings when tinydtls.h is included */ +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_URL +#undef PACKAGE_VERSION + #include #include +#include #endif /* HAVE_LIBTINYDTLS */ #ifdef HAVE_OPENSSL @@ -25,10 +34,10 @@ #include #endif /* HAVE_OPENSSL */ -#ifdef HAVE_GNUTLS +#ifdef HAVE_LIBGNUTLS #define HAVE_DTLS 1 #include -#endif /* HAVE_GNUTLS */ +#endif /* HAVE_LIBGNUTLS */ static void t_tls1(void) { @@ -51,9 +60,23 @@ t_tls2(void) { version.version = SSLeay(); version.type = COAP_TLS_LIBRARY_OPENSSL; #elif defined(HAVE_LIBTINYDTLS) - version.version = DTLS_VERSION; + const char *vers = dtls_package_version(); + version.version = 0; + if (vers) { + long int p1, p2 = 0, p3 = 0; + char* endptr; + + p1 = strtol(vers, &endptr, 10); + if (*endptr == '.') { + p2 = strtol(endptr+1, &endptr, 10); + if (*endptr == '.') { + p3 = strtol(endptr+1, &endptr, 10); + } + } + version.version = (p1 << 16) | (p2 << 8) | p3; + } version.type = COAP_TLS_LIBRARY_TINYDTLS; -#elif defined(HAVE_GNUTLS) +#elif defined(HAVE_LIBGNUTLS) version.version = GNUTLS_VERSION_NUMBER; version.type = COAP_TLS_LIBRARY_GNUTLS; #else /* no DTLS */