From 5d7abd1f8c0626445026712082e7e4b7835263a4 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 8 Jan 2025 19:51:06 -0500 Subject: [PATCH] Port: restore Windows XP minimal support (#958) Windows XP support was removed in 2021, but we've had a recent request for basic Windows XP support. It looks like the needed changes are very minimal these days, the only real requirement is to build without threading support, everything else can be conditionally bypassed. This changeset mostly just disables building the event subsystem if threading is disabled then makes a couple minor build system changes to allow overriding of the `_WIN32_WINNT` macro. Fixes #956 --------- Signed-off-by: Brad House (@bradh352) --- CMakeLists.txt | 7 +++++-- Makefile.m32 | 4 +++- appveyor.yml | 17 ++++++++------- configure.ac | 1 + src/lib/ares_config.h.cmake | 3 +++ src/lib/ares_ipv6.h | 10 +++++++++ src/lib/ares_sysconfig_win.c | 31 ++++++++++++++++------------ src/lib/config-win32.h | 8 +++++-- src/lib/event/ares_event.h | 25 ++++++++++++---------- src/lib/event/ares_event_configchg.c | 13 +++++++----- src/lib/event/ares_event_epoll.c | 4 ++-- src/lib/event/ares_event_kqueue.c | 4 ++-- src/lib/event/ares_event_poll.c | 5 +++-- src/lib/event/ares_event_select.c | 9 ++++---- src/lib/event/ares_event_thread.c | 16 ++++++++++++++ src/lib/event/ares_event_wake_pipe.c | 16 +++++++------- src/lib/event/ares_event_win32.c | 6 ++++-- src/lib/util/ares_iface_ips.c | 8 ++++++- test/Makefile.m32 | 4 +++- test/ares-fuzz.c | 2 +- test/ares-test-internal.cc | 2 ++ 21 files changed, 131 insertions(+), 64 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 139defd8ff..d0516230e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -274,12 +274,14 @@ ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "QNX") LIST (APPEND SYSFLAGS -D_QNX_SOURCE) ELSEIF (WIN32) - LIST (APPEND SYSFLAGS -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0602) + LIST (APPEND SYSFLAGS -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) + IF (NOT CMAKE_C_FLAGS MATCHES ".*-D_WIN32_WINNT=.*") + LIST (APPEND SYSFLAGS -D_WIN32_WINNT=0x0602) + ENDIF () ENDIF () ADD_DEFINITIONS(${SYSFLAGS}) - # Tell C-Ares about libraries to depend on IF (HAVE_LIBRESOLV) LIST (APPEND CARES_DEPENDENT_LIBS resolv) @@ -426,6 +428,7 @@ CHECK_SYMBOL_EXISTS (getservbyname_r "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETSERV CHECK_SYMBOL_EXISTS (gettimeofday "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETTIMEOFDAY) CHECK_SYMBOL_EXISTS (if_indextoname "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IF_INDEXTONAME) CHECK_SYMBOL_EXISTS (if_nametoindex "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IF_NAMETOINDEX) +CHECK_SYMBOL_EXISTS (GetBestRoute2 "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETBESTROUTE2) CHECK_SYMBOL_EXISTS (ConvertInterfaceIndexToLuid "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CONVERTINTERFACEINDEXTOLUID) CHECK_SYMBOL_EXISTS (ConvertInterfaceLuidToNameA "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CONVERTINTERFACELUIDTONAMEA) CHECK_SYMBOL_EXISTS (NotifyIpInterfaceChange "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_NOTIFYIPINTERFACECHANGE) diff --git a/Makefile.m32 b/Makefile.m32 index 7bd8516597..427b08771e 100644 --- a/Makefile.m32 +++ b/Makefile.m32 @@ -19,7 +19,9 @@ RANLIB = $(CROSSPREFIX)ranlib #RM = rm -f CP = cp -afv -CFLAGS = $(CARES_CFLAG_EXTRAS) -O2 -Wall -I./include -I./src/lib -I./src/lib/include -D_WIN32_WINNT=0x0602 +WIN32_WINNT ?= 0x0602 + +CFLAGS = $(CARES_CFLAG_EXTRAS) -O2 -Wall -I./include -I./src/lib -I./src/lib/include -D_WIN32_WINNT=$(WIN32_WINNT) CFLAGS += -DCARES_STATICLIB LDFLAGS = $(CARES_LDFLAG_EXTRAS) -s LIBS = -lws2_32 -liphlpapi diff --git a/appveyor.yml b/appveyor.yml index 63e396671a..ca2201fa73 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,14 +23,14 @@ configuration: # CMAKE_EXTRA_OPTIONS: -DOPENSSL_ROOT_DIR=C:/OpenSSL-Win32 environment: matrix: - # MSVC 2022, 32-bit x86 (cmake) + # MSVC 2022, 32-bit x86 (cmake, WindowsXP) - COMPILER: MSVC CONFTOOL: CMAKE SYSTEM: CONSOLE SKIP_TESTS: no MSVC_SETUP_ARG: x86 MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat - CMAKE_EXTRA_OPTIONS: -GNinja -DCARES_BUILD_TESTS=ON -DGTEST_ROOT=C:\projects\googletest -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL + CMAKE_EXTRA_OPTIONS: -GNinja -DCARES_BUILD_TESTS=ON -DGTEST_ROOT=C:\projects\googletest -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL -DCARES_THREADS=OFF -DCMAKE_C_FLAGS="-D_WIN32_WINNT=0x0501" -DCMAKE_CXX_FLAGS="-D_WIN32_WINNT=0x0501" TOOLSDIR: ./build/bin TESTDIR: ./build/bin BUILD_GOOGLETEST: yes @@ -65,15 +65,16 @@ environment: MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat BUILD_GOOGLETEST: yes - # MinGW, 32-bit x86 (makefiles) + # MinGW, 32-bit x86 (makefiles, Windows XP) - COMPILER: MINGW CONFTOOL: MAKE SYSTEM: CONSOLE SKIP_TESTS: no PATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;%PATH% BUILD_GOOGLETEST: yes + MAKE_FLAGS: WIN32_WINNT=0x0501 - # MinGW, 32-bit x86 (cmake static only) + # MinGW, 32-bit x86 (cmake static only, Windows XP) - COMPILER: MINGW CONFTOOL: CMAKE SYSTEM: CONSOLE @@ -81,7 +82,7 @@ environment: TOOLSDIR: ./build/bin TESTDIR: ./build/bin PATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;%PATH% - CMAKE_EXTRA_OPTIONS: -DCARES_SHARED=OFF -GNinja -DCARES_BUILD_TESTS=ON -DGTEST_ROOT=C:\projects\googletest + CMAKE_EXTRA_OPTIONS: -DCARES_SHARED=OFF -GNinja -DCARES_BUILD_TESTS=ON -DGTEST_ROOT=C:\projects\googletest -DCARES_THREADS=OFF -DCMAKE_C_FLAGS="-D_WIN32_WINNT=0x0501" -DCMAKE_CXX_FLAGS="-D_WIN32_WINNT=0x0501" BUILD_GOOGLETEST: yes # Disabled until AppVeyor updates their Visual Studio with this patch: @@ -117,7 +118,7 @@ build_script: - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" cmake --build build --config Debug - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" cmake --install build --config Debug - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" copy .\include\ares_build.h.dist .\include\ares_build.h - - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" mingw32-make.exe -f Makefile.m32 demos + - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" mingw32-make.exe -f Makefile.m32 demos %MAKE_FLAGS% test_script: # We can't use powershell for tests due to treating stderr as an error @@ -126,8 +127,8 @@ test_script: - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" if not "%SKIP_TESTS%" == "yes" nmake GTEST_ROOT=C:\projects\googletest /NOLOGO /f .\Makefile.msvc aresfuzz aresfuzzname dnsdump - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" if not "%SKIP_TESTS%" == "yes" .\msvc\arestest\lib-debug\dnsdump.exe fuzzinput\answer_a fuzzinput\answer_aaaa - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" cd test - - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" mingw32-make.exe GTEST_ROOT=C:\projects\googletest -f Makefile.m32 vtest - - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" mingw32-make.exe GTEST_ROOT=C:\projects\googletest -f Makefile.m32 aresfuzz.exe aresfuzzname.exe dnsdump.exe + - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" mingw32-make.exe GTEST_ROOT=C:\projects\googletest -f Makefile.m32 vtest %MAKE_FLAGS% + - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" mingw32-make.exe GTEST_ROOT=C:\projects\googletest -f Makefile.m32 aresfuzz.exe aresfuzzname.exe dnsdump.exe %MAKE_FLAGS% - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" .\dnsdump.exe fuzzinput\answer_a fuzzinput\answer_aaaa - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" if not "%SKIP_TESTS%" == "yes" cd %TESTDIR% - if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" if not "%SKIP_TESTS%" == "yes" .\adig.exe www.google.com diff --git a/configure.ac b/configure.ac index 9dacf1fb2e..06120c2991 100644 --- a/configure.ac +++ b/configure.ac @@ -594,6 +594,7 @@ AC_CHECK_DECL(pipe, [AC_DEFINE([HAVE_PIPE], 1, [Define t AC_CHECK_DECL(pipe2, [AC_DEFINE([HAVE_PIPE2], 1, [Define to 1 if you have `pipe2`] )], [], $cares_all_includes) AC_CHECK_DECL(kqueue, [AC_DEFINE([HAVE_KQUEUE], 1, [Define to 1 if you have `kqueue`] )], [], $cares_all_includes) AC_CHECK_DECL(epoll_create1, [AC_DEFINE([HAVE_EPOLL], 1, [Define to 1 if you have `epoll_{create1,ctl,wait}`])], [], $cares_all_includes) +AC_CHECK_DECL(GetBestRoute2, [AC_DEFINE([HAVE_GETBESTROUTE2], 1, [Define to 1 if you have `GetBestRoute2`] )], [], $cares_all_includes) AC_CHECK_DECL(ConvertInterfaceIndexToLuid, [AC_DEFINE([HAVE_CONVERTINTERFACEINDEXTOLUID], 1, [Define to 1 if you have `ConvertInterfaceIndexToLuid`])], [], $cares_all_includes) AC_CHECK_DECL(ConvertInterfaceLuidToNameA, [AC_DEFINE([HAVE_CONVERTINTERFACELUIDTONAMEA], 1, [Define to 1 if you have `ConvertInterfaceLuidToNameA`])], [], $cares_all_includes) AC_CHECK_DECL(NotifyIpInterfaceChange, [AC_DEFINE([HAVE_NOTIFYIPINTERFACECHANGE], 1, [Define to 1 if you have `NotifyIpInterfaceChange`] )], [], $cares_all_includes) diff --git a/src/lib/ares_config.h.cmake b/src/lib/ares_config.h.cmake index 51744fe143..cff1818721 100644 --- a/src/lib/ares_config.h.cmake +++ b/src/lib/ares_config.h.cmake @@ -145,6 +145,9 @@ /* Define to 1 if you have the `if_nametoindex' function. */ #cmakedefine HAVE_IF_NAMETOINDEX 1 +/* Define to 1 if you have the `GetBestRoute2' function. */ +#cmakedefine HAVE_GETBESTROUTE2 1 + /* Define to 1 if you have the `ConvertInterfaceIndexToLuid' function. */ #cmakedefine HAVE_CONVERTINTERFACEINDEXTOLUID 1 diff --git a/src/lib/ares_ipv6.h b/src/lib/ares_ipv6.h index 5da341b010..d2007cc29e 100644 --- a/src/lib/ares_ipv6.h +++ b/src/lib/ares_ipv6.h @@ -90,6 +90,16 @@ struct addrinfo { # define NS_INT16SZ 2 #endif +/* Windows XP Compatibility with later MSVC/Mingw versions */ +#if defined(_WIN32) +# if !defined(IF_MAX_STRING_SIZE) +# define IF_MAX_STRING_SIZE 256 /* =256 in */ +# endif +# if !defined(NDIS_IF_MAX_STRING_SIZE) +# define NDIS_IF_MAX_STRING_SIZE IF_MAX_STRING_SIZE /* =256 in */ +# endif +#endif + #ifndef IF_NAMESIZE # ifdef IFNAMSIZ # define IF_NAMESIZE IFNAMSIZ diff --git a/src/lib/ares_sysconfig_win.c b/src/lib/ares_sysconfig_win.c index f6e07f92e4..01109a89ba 100644 --- a/src/lib/ares_sysconfig_win.c +++ b/src/lib/ares_sysconfig_win.c @@ -176,6 +176,7 @@ static int compareAddresses(const void *arg1, const void *arg2) return 0; } +#if defined(HAVE_GETBESTROUTE2) && !defined(__WATCOMC__) /* There can be multiple routes to "the Internet". And there can be different * DNS servers associated with each of the interfaces that offer those routes. * We have to assume that any DNS server can serve any request. But, some DNS @@ -213,18 +214,6 @@ static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */ const SOCKADDR_INET * const dest, const ULONG interfaceMetric) { - /* On this interface, get the best route to that destination. */ -# if defined(__WATCOMC__) - /* OpenWatcom's builtin Windows SDK does not have a definition for - * MIB_IPFORWARD_ROW2, and also does not allow the usage of SOCKADDR_INET - * as a variable. Let's work around this by returning the worst possible - * metric, but only when using the OpenWatcom compiler. - * It may be worth investigating using a different version of the Windows - * SDK with OpenWatcom in the future, though this may be fixed in OpenWatcom - * 2.0. - */ - return (ULONG)-1; -# else MIB_IPFORWARD_ROW2 row; SOCKADDR_INET ignored; if (GetBestRoute2(/* The interface to use. The index is ignored since we are @@ -257,8 +246,8 @@ static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */ * which describes the combination as a "sum". */ return row.Metric + interfaceMetric; -# endif /* __WATCOMC__ */ } +#endif /* * get_DNS_Windows() @@ -379,9 +368,21 @@ static ares_bool_t get_DNS_Windows(char **outptr) addressesSize = newSize; } +# if defined(HAVE_GETBESTROUTE2) && !defined(__WATCOMC__) + /* OpenWatcom's builtin Windows SDK does not have a definition for + * MIB_IPFORWARD_ROW2, and also does not allow the usage of SOCKADDR_INET + * as a variable. Let's work around this by returning the worst possible + * metric, but only when using the OpenWatcom compiler. + * It may be worth investigating using a different version of the Windows + * SDK with OpenWatcom in the future, though this may be fixed in OpenWatcom + * 2.0. + */ addresses[addressesIndex].metric = getBestRouteMetric( &ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)), ipaaEntry->Ipv4Metric); +# else + addresses[addressesIndex].metric = (ULONG)-1; +# endif /* Record insertion index to make qsort stable */ addresses[addressesIndex].orig_idx = addressesIndex; @@ -423,9 +424,13 @@ static ares_bool_t get_DNS_Windows(char **outptr) ll_scope = ipaaEntry->Ipv6IfIndex; } +# if defined(HAVE_GETBESTROUTE2) && !defined(__WATCOMC__) addresses[addressesIndex].metric = getBestRouteMetric( &ipaaEntry->Luid, (SOCKADDR_INET *)((void *)(namesrvr.sa)), ipaaEntry->Ipv6Metric); +# else + addresses[addressesIndex].metric = (ULONG)-1; +# endif /* Record insertion index to make qsort stable */ addresses[addressesIndex].orig_idx = addressesIndex; diff --git a/src/lib/config-win32.h b/src/lib/config-win32.h index be233a2f8b..fc533c7551 100644 --- a/src/lib/config-win32.h +++ b/src/lib/config-win32.h @@ -237,8 +237,10 @@ # undef HAVE_NETIOAPI_H #endif -/* Threading support enabled */ -#define CARES_THREADS 1 +/* Threading support enabled for Vista+ */ +#if !defined(_WIN32_WINNT) || _WIN32_WINNT >= 0x0600 +# define CARES_THREADS 1 +#endif /* ---------------------------------------------------------------- */ /* TYPEDEF REPLACEMENTS */ @@ -370,6 +372,8 @@ # define HAVE_CONVERTINTERFACELUIDTONAMEA 1 /* Define to 1 if you have the `NotifyIpInterfaceChange' function. */ # define HAVE_NOTIFYIPINTERFACECHANGE 1 +/* Define to 1 if you have the `GetBestRoute2` function */ +# define HAVE_GETBESTROUTE2 1 #endif /* ---------------------------------------------------------------- */ diff --git a/src/lib/event/ares_event.h b/src/lib/event/ares_event.h index 36cd10dcf8..bf298dfb61 100644 --- a/src/lib/event/ares_event.h +++ b/src/lib/event/ares_event.h @@ -159,30 +159,33 @@ ares_status_t ares_event_update(ares_event_t **event, ares_event_thread_t *e, ares_event_signal_cb_t signal_cb); -#ifdef HAVE_PIPE +#ifdef CARES_THREADS +# ifdef HAVE_PIPE ares_event_t *ares_pipeevent_create(ares_event_thread_t *e); -#endif +# endif -#ifdef HAVE_POLL +# ifdef HAVE_POLL extern const ares_event_sys_t ares_evsys_poll; -#endif +# endif -#ifdef HAVE_KQUEUE +# ifdef HAVE_KQUEUE extern const ares_event_sys_t ares_evsys_kqueue; -#endif +# endif -#ifdef HAVE_EPOLL +# ifdef HAVE_EPOLL extern const ares_event_sys_t ares_evsys_epoll; -#endif +# endif -#ifdef _WIN32 +# ifdef _WIN32 extern const ares_event_sys_t ares_evsys_win32; -#endif +# endif /* All systems have select(), but not all have a way to wake, so we require * pipe() to wake the select() */ -#ifdef HAVE_PIPE +# ifdef HAVE_PIPE extern const ares_event_sys_t ares_evsys_select; +# endif + #endif #endif diff --git a/src/lib/event/ares_event_configchg.c b/src/lib/event/ares_event_configchg.c index 5ecc6888ab..4dd6df8d1d 100644 --- a/src/lib/event/ares_event_configchg.c +++ b/src/lib/event/ares_event_configchg.c @@ -26,7 +26,7 @@ #include "ares_private.h" #include "ares_event.h" -#ifdef __ANDROID__ +#if defined(__ANDROID__) && defined(CARES_THREADS) ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, ares_event_thread_t *e) @@ -43,7 +43,7 @@ void ares_event_configchg_destroy(ares_event_configchg_t *configchg) (void)configchg; } -#elif defined(__linux__) +#elif defined(__linux__) && defined(CARES_THREADS) # include @@ -174,7 +174,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, return status; } -#elif defined(USE_WINSOCK) +#elif defined(USE_WINSOCK) && defined(CARES_THREADS) # include # include @@ -379,7 +379,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, return status; } -#elif defined(__APPLE__) +#elif defined(__APPLE__) && defined(CARES_THREADS) # include # include @@ -531,7 +531,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, return status; } -#elif defined(HAVE_STAT) && !defined(_WIN32) +#elif defined(HAVE_STAT) && !defined(_WIN32) && defined(CARES_THREADS) # ifdef HAVE_SYS_TYPES_H # include # endif @@ -722,6 +722,8 @@ void ares_event_configchg_destroy(ares_event_configchg_t *configchg) ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, ares_event_thread_t *e) { + (void)configchg; + (void)e; /* No ability */ return ARES_ENOTIMP; } @@ -729,6 +731,7 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, void ares_event_configchg_destroy(ares_event_configchg_t *configchg) { /* No-op */ + (void)configchg; } #endif diff --git a/src/lib/event/ares_event_epoll.c b/src/lib/event/ares_event_epoll.c index 538c38b4f9..d451c86a3d 100644 --- a/src/lib/event/ares_event_epoll.c +++ b/src/lib/event/ares_event_epoll.c @@ -26,6 +26,8 @@ #include "ares_private.h" #include "ares_event.h" +#if defined(HAVE_EPOLL) && defined(CARES_THREADS) + #ifdef HAVE_SYS_EPOLL_H # include #endif @@ -33,8 +35,6 @@ # include #endif -#ifdef HAVE_EPOLL - typedef struct { int epoll_fd; } ares_evsys_epoll_t; diff --git a/src/lib/event/ares_event_kqueue.c b/src/lib/event/ares_event_kqueue.c index dbbd0dbd9f..00cdcbe9c2 100644 --- a/src/lib/event/ares_event_kqueue.c +++ b/src/lib/event/ares_event_kqueue.c @@ -26,6 +26,8 @@ #include "ares_private.h" #include "ares_event.h" +#if defined(HAVE_KQUEUE) && defined(CARES_THREADS) + #ifdef HAVE_SYS_TYPES_H # include #endif @@ -39,8 +41,6 @@ # include #endif -#ifdef HAVE_KQUEUE - typedef struct { int kqueue_fd; struct kevent *changelist; diff --git a/src/lib/event/ares_event_poll.c b/src/lib/event/ares_event_poll.c index c6ab4b6207..28e3c09657 100644 --- a/src/lib/event/ares_event_poll.c +++ b/src/lib/event/ares_event_poll.c @@ -25,12 +25,13 @@ */ #include "ares_private.h" #include "ares_event.h" + +#if defined(HAVE_POLL) && defined(CARES_THREADS) + #ifdef HAVE_POLL_H # include #endif -#if defined(HAVE_POLL) - static ares_bool_t ares_evsys_poll_init(ares_event_thread_t *e) { e->ev_signal = ares_pipeevent_create(e); diff --git a/src/lib/event/ares_event_select.c b/src/lib/event/ares_event_select.c index 4d7c085d87..df758b5a1e 100644 --- a/src/lib/event/ares_event_select.c +++ b/src/lib/event/ares_event_select.c @@ -31,13 +31,14 @@ #include "ares_private.h" #include "ares_event.h" -#ifdef HAVE_SYS_SELECT_H -# include -#endif /* All systems have select(), but not all have a way to wake, so we require * pipe() to wake the select() */ -#if defined(HAVE_PIPE) +#if defined(HAVE_PIPE) && defined(CARES_THREADS) + +#ifdef HAVE_SYS_SELECT_H +# include +#endif static ares_bool_t ares_evsys_select_init(ares_event_thread_t *e) { diff --git a/src/lib/event/ares_event_thread.c b/src/lib/event/ares_event_thread.c index d59b7880a4..c77514e02c 100644 --- a/src/lib/event/ares_event_thread.c +++ b/src/lib/event/ares_event_thread.c @@ -26,6 +26,7 @@ #include "ares_private.h" #include "ares_event.h" +#ifdef CARES_THREADS static void ares_event_destroy_cb(void *arg) { ares_event_t *event = arg; @@ -549,3 +550,18 @@ ares_status_t ares_event_thread_init(ares_channel_t *channel) return ARES_SUCCESS; } + +#else + +ares_status_t ares_event_thread_init(ares_channel_t *channel) +{ + (void)channel; + return ARES_ENOTIMP; +} + +void ares_event_thread_destroy(ares_channel_t *channel) +{ + (void)channel; +} + +#endif diff --git a/src/lib/event/ares_event_wake_pipe.c b/src/lib/event/ares_event_wake_pipe.c index d3b166a3d6..cd1534bbbd 100644 --- a/src/lib/event/ares_event_wake_pipe.c +++ b/src/lib/event/ares_event_wake_pipe.c @@ -25,14 +25,16 @@ */ #include "ares_private.h" #include "ares_event.h" -#ifdef HAVE_UNISTD_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#ifdef HAVE_PIPE +#if defined(HAVE_PIPE) && defined(CARES_THREADS) + +# ifdef HAVE_UNISTD_H +# include +# endif +# ifdef HAVE_FCNTL_H +# include +# endif + typedef struct { int filedes[2]; } ares_pipeevent_t; diff --git a/src/lib/event/ares_event_win32.c b/src/lib/event/ares_event_win32.c index 7a25f1205e..d7d1d65735 100644 --- a/src/lib/event/ares_event_win32.c +++ b/src/lib/event/ares_event_win32.c @@ -37,12 +37,14 @@ #include "ares_private.h" #include "ares_event.h" #include "ares_event_win32.h" + + +#if defined(USE_WINSOCK) && defined(CARES_THREADS) + #ifdef HAVE_LIMITS_H # include #endif -#if defined(USE_WINSOCK) - /* IMPLEMENTATION NOTES * ==================== * diff --git a/src/lib/util/ares_iface_ips.c b/src/lib/util/ares_iface_ips.c index 46cb291e30..c5f507f87e 100644 --- a/src/lib/util/ares_iface_ips.c +++ b/src/lib/util/ares_iface_ips.c @@ -431,8 +431,14 @@ static ares_status_t ares_iface_ips_enumerate(ares_iface_ips_t *ips, } status = ares_iface_ips_add(ips, addrflag, ifname, &addr, +#if _WIN32_WINNT >= 0x0600 ipaddr->OnLinkPrefixLength /* netmask */, - address->Ipv6IfIndex /* ll_scope */); +#else + ipaddr->Address.lpSockaddr->sa_family + == AF_INET?32:128, +#endif + address->Ipv6IfIndex /* ll_scope */ + ); if (status != ARES_SUCCESS) { goto done; diff --git a/test/Makefile.m32 b/test/Makefile.m32 index 5227f98fbb..26ab0421a2 100644 --- a/test/Makefile.m32 +++ b/test/Makefile.m32 @@ -10,6 +10,8 @@ CXX = g++ CC = gcc LD = g++ +WIN32_WINNT ?= 0x0602 + ifeq "$(GTEST_ROOT)" "" $(error missing GTEST_ROOT) endif @@ -19,7 +21,7 @@ ARES_SRC_DIR = .. # Where to find the built c-ares static library ARES_BLD_DIR = .. ARESLIB = $(ARES_BLD_DIR)/src/lib/libcares.a -CPPFLAGS = -I$(ARES_SRC_DIR)/include -I$(ARES_SRC_DIR)/src/lib -I$(ARES_SRC_DIR)/src/lib/include -I$(GTEST_ROOT)/include -DCARES_STATICLIB -DCARES_NO_DEPRECATED +CPPFLAGS = -I$(ARES_SRC_DIR)/include -I$(ARES_SRC_DIR)/src/lib -I$(ARES_SRC_DIR)/src/lib/include -I$(GTEST_ROOT)/include -DCARES_STATICLIB -DCARES_NO_DEPRECATED -D_WIN32_WINNT=$(WIN32_WINNT) CXXFLAGS = -Wall $(PTHREAD_CFLAGS) -std=gnu++14 LDFLAGS = LDLIBS = -lws2_32 -liphlpapi diff --git a/test/ares-fuzz.c b/test/ares-fuzz.c index 8203d48da8..239f127dbf 100644 --- a/test/ares-fuzz.c +++ b/test/ares-fuzz.c @@ -33,7 +33,7 @@ #include #include #include -#ifdef WIN32 +#ifdef _WIN32 # include #else # include diff --git a/test/ares-test-internal.cc b/test/ares-test-internal.cc index 3e3760bf13..0000a90a44 100644 --- a/test/ares-test-internal.cc +++ b/test/ares-test-internal.cc @@ -299,6 +299,7 @@ TEST_F(LibraryTest, SlistMisuse) { EXPECT_EQ(NULL, ares_slist_node_claim(NULL)); } +#if !defined(_WIN32) || _WIN32_WINNT >= 0x0600 TEST_F(LibraryTest, IfaceIPs) { ares_status_t status; ares_iface_ips_t *ips = NULL; @@ -354,6 +355,7 @@ TEST_F(LibraryTest, IfaceIPs) { ares_iface_ips_destroy(ips); } +#endif TEST_F(LibraryTest, HtableMisuse) { EXPECT_EQ(NULL, ares_htable_create(NULL, NULL, NULL, NULL));