From 576cb107328b42105563ca8235c7a0d39c0607a0 Mon Sep 17 00:00:00 2001 From: toddouska Date: Wed, 10 Apr 2013 17:09:53 -0700 Subject: [PATCH] fix port 0 hack for unit tests with ipv6 --- cyassl/test.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cyassl/test.h b/cyassl/test.h index bd4e41583..b675b413e 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -487,11 +487,15 @@ static INLINE void tcp_listen(SOCKET_T* sockfd, int* port, int useAnyAddr, err_sys("tcp listen failed"); } #if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) - if (*port == 0) - { + if (*port == 0) { socklen_t len = sizeof(addr); - if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) - *port = ntohs(addr.sin_port); + if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) { + #ifndef TEST_IPV6 + *port = ntohs(addr.sin_port); + #else + *port = ntohs(addr.sin6_port); + #endif + } } #endif } @@ -541,11 +545,15 @@ static INLINE void udp_accept(SOCKET_T* sockfd, int* clientfd, int useAnyAddr, err_sys("tcp bind failed"); #if defined(NO_MAIN_DRIVER) && !defined(USE_WINDOWS_API) - if (port == 0) - { + if (port == 0) { socklen_t len = sizeof(addr); - if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) - port = ntohs(addr.sin_port); + if (getsockname(*sockfd, (struct sockaddr*)&addr, &len) == 0) { + #ifndef TEST_IPV6 + port = ntohs(addr.sin_port); + #else + port = ntohs(addr.sin6_port); + #endif + } } #endif