From b5c43d8ad48179e3d42288ba35503ce09a93ecb6 Mon Sep 17 00:00:00 2001 From: toddouska Date: Thu, 11 Apr 2013 10:12:15 -0700 Subject: [PATCH] don't default to loopback only for ipv6 tests, if inet_pton available allow lookups --- configure.ac | 1 + cyassl/test.h | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 62d8b6209..69fcbb446 100644 --- a/configure.ac +++ b/configure.ac @@ -60,6 +60,7 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) AX_CXX_COMPILER_VERSION AC_CHECK_FUNCS([gethostbyname]) +AC_CHECK_FUNCS([inet_pton]) AC_CHECK_FUNCS([gettimeofday]) AC_CHECK_FUNCS([inet_ntoa]) AC_CHECK_FUNCS([memset]) diff --git a/cyassl/test.h b/cyassl/test.h index b675b413e..d7137035c 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -163,7 +163,11 @@ void start_thread(THREAD_FUNC, func_args*, THREAD_TYPE*); void join_thread(THREAD_TYPE); /* yaSSL */ -static const char* const yasslIP = "127.0.0.1"; +#ifndef TEST_IPV6 + static const char* const yasslIP = "127.0.0.1"; +#else + static const char* const yasslIP = "::1"; +#endif static const word16 yasslPort = 11111; @@ -331,39 +335,50 @@ static INLINE void showPeer(CYASSL* ssl) static INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer, word16 port) { -#ifndef TEST_IPV6 - const char* host = peer; + int useLookup = 0; + (void)useLookup; + memset(addr, 0, sizeof(SOCKADDR_IN_T)); + +#ifndef TEST_IPV6 /* peer could be in human readable form */ if (peer != INADDR_ANY && isalpha((int)peer[0])) { struct hostent* entry = gethostbyname(peer); if (entry) { - struct sockaddr_in tmp; - memset(&tmp, 0, sizeof(struct sockaddr_in)); - memcpy(&tmp.sin_addr.s_addr, entry->h_addr_list[0], + memcpy(&addr->sin_addr.s_addr, entry->h_addr_list[0], entry->h_length); - host = inet_ntoa(tmp.sin_addr); + useLookup = 1; } else err_sys("no entry for host"); } #endif - memset(addr, 0, sizeof(SOCKADDR_IN_T)); #ifndef TEST_IPV6 addr->sin_family = AF_INET_V; addr->sin_port = htons(port); - if (host == INADDR_ANY) + if (peer == INADDR_ANY) addr->sin_addr.s_addr = INADDR_ANY; - else - addr->sin_addr.s_addr = inet_addr(host); + else { + if (!useLookup) + addr->sin_addr.s_addr = inet_addr(peer); + } #else - (void)peer; addr->sin6_family = AF_INET_V; addr->sin6_port = htons(port); - addr->sin6_addr = in6addr_loopback; + if (peer == INADDR_ANY) + addr->sin6_addr = in6addr_any; + else { + #ifdef HAVE_INET_PTON + if (inet_pton(AF_INET_V, peer, &addr->sin6_addr) != 1) + err_sys("ipv6 lookup failed"); + #else + printf("no ipv6 inet_pton, loopback only tests/examples\n"); + addr->sin6_addr = in6addr_loopback; + #endif + } #endif }