libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit d4b9fc7ee15bad4cee47c91e5ecd2c05b069a70a
parent b47b1c94e28069cf4f46c65713d99d2f0f55bb9c
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue,  6 Oct 2020 21:37:46 +0300

configure: check whether IPv6 could be used for testing

Diffstat:
MChangeLog | 11++++++++---
Mconfigure.ac | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/microhttpd/test_options.c | 6+++---
3 files changed, 104 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +Wed 07 Oct 2020 11:07:00 MSK + W32 default target version changed to Vista, XP is still supported. + Minor fixes and additional asserts for memorypool. + IPv6 tests are not used if IPv6 is disabled at run-time. -EG + Sun 27 Sep 2020 10:08:03 PM CEST Fixed incorrect triggering of epoll edge polling for "upgraded" TLS connections. Fixed a few cases where @@ -16,7 +21,7 @@ Thu 24 Sep 2020 16:55:00 MSK the registries. Fixed portability of test_upgrade_large. Minor testsuite fixes. - Restored parallel build of libmicrohttpd (except tests). + Restored parallel build of libmicrohttpd (except tests). -EG Fri 11 Sep 2020 10:08:22 PM CEST Fix crash problem in PostProcessor reported by MD. -CG @@ -205,11 +210,11 @@ Mon May 20 15:39:35 MSK 2019 Compiler warning fixes. -EG/CG Fixed example for non-64bits platforms. -EG -Web May 15 23:51:49 MSK 2019 +Wed May 15 23:51:49 MSK 2019 Optimized and improved processing speed by using precalculated and already calculated lengths of strings. -EG -Web May 15 14:54:00 MSK 2019 +Wed May 15 14:54:00 MSK 2019 Fixed build from source on GNU Hurd. -EG Mon May 6 11:58:00 MSK 2019 diff --git a/configure.ac b/configure.ac @@ -2129,6 +2129,99 @@ AC_CACHE_CHECK([[for calloc()]], [[mhd_cv_have_func_calloc]], AS_VAR_IF([[mhd_cv_have_func_calloc]], [["yes"]], [AC_DEFINE([[HAVE_CALLOC]], [[1]], [Define to 1 if you have the usable `calloc' function.])]) +# Some systems have IPv6 disabled in kernel at run-time +AS_IF([[test "x${have_inet6}" = "xyes" && test "x${cross_compiling}" = "xno"]], + [ + AC_CACHE_CHECK([whether IPv6 could be used for testing],[mhd_cv_ipv6_for_testing], + [ + AC_RUN_IFELSE( + [ + AC_LANG_SOURCE([[ +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif +#ifdef HAVE_WINSOCK2_H +#include <winsock2.h> +#endif +#ifdef HAVE_WS2TCPIP_H +#include <ws2tcpip.h> +#endif +#ifdef HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#ifdef HAVE_NETINET_IP_H +#include <netinet/ip.h> +#endif +#ifdef HAVE_ARPA_INET_H +#include <arpa/inet.h> +#endif +#ifdef HAVE_NETINET_TCP_H +#include <netinet/tcp.h> +#endif + +static void zr_mem(void *ptr, socklen_t size) +{ char *mem = ptr; while(size--) {mem[0] = 0; mem++;} } + +int main(void) +{ + int ret = 30; + struct sockaddr_in6 sa; +#if !defined(_WIN32) || defined(__CYGWIN__) + int sckt; + const int invld_sckt = -1; +#else + SOCKET sckt; + const SOCKET invld_sckt = INVALID_SOCKET; + WSADATA wsa_data; + + WSAStartup(MAKEWORD(2, 2), &wsa_data); +#endif + zr_mem(&sa, sizeof(sa)); + sa.sin6_family = AF_INET6; + sa.sin6_port = 0; + sa.sin6_addr = in6addr_loopback; +#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN + sa.sin6_len = sizeof(sa); +#endif + sckt = socket (PF_INET6, SOCK_STREAM, 0); + if (invld_sckt != sckt) + { + if (0 == bind (sckt, (struct sockaddr *)&sa, sizeof(sa))) + { + if (0 == listen (sckt, 1)) + ret = 0; + else + ret = 1; /* listen() failed */ + } else ret = 2; /* bind() failed */ +#if !defined(_WIN32) || defined(__CYGWIN__) + close (sckt); +#else + closesocket (sckt); +#endif + } else ret = 3; /* socket() failed */ +#if defined(_WIN32) && !defined(__CYGWIN__) + WSACleanup(); +#endif + return ret; +} + ]]) + ], [[mhd_cv_ipv6_for_testing="yes"]], [[mhd_cv_ipv6_for_testing="no"]], [[mhd_cv_ipv6_for_testing="no"]] + ) + ] + ) + ] +) +AS_VAR_IF([mhd_cv_ipv6_for_testing],["yes"], + [AC_DEFINE([[USE_IPV6_TESTING]], [[1]], [Define to 1 if your kernel supports IPv6 and IPv6 is enabled and useful for testing.])] +) + + # Check for fork() and waitpid(). They are used for tests. AC_MSG_CHECKING([[for fork()]]) mhd_have_fork_waitpid='no' diff --git a/src/microhttpd/test_options.c b/src/microhttpd/test_options.c @@ -84,7 +84,7 @@ test_ip_addr_option () { struct MHD_Daemon *d; struct sockaddr_in daemon_ip_addr; -#if HAVE_INET6 +#if HAVE_INET6 && defined (USE_IPV6_TESTING) struct sockaddr_in6 daemon_ip_addr6; #endif @@ -93,7 +93,7 @@ test_ip_addr_option () daemon_ip_addr.sin_port = 0; daemon_ip_addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); -#if HAVE_INET6 +#if HAVE_INET6 && defined (USE_IPV6_TESTING) memset (&daemon_ip_addr6, 0, sizeof (struct sockaddr_in6)); daemon_ip_addr6.sin6_family = AF_INET6; daemon_ip_addr6.sin6_port = 0; @@ -109,7 +109,7 @@ test_ip_addr_option () MHD_stop_daemon (d); -#if HAVE_INET6 +#if HAVE_INET6 && defined (USE_IPV6_TESTING) d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_IPv6, 0, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR, &daemon_ip_addr6, MHD_OPTION_END);