From 7d8d5cf876b8af28234c382d318517cca4a26032 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 24 Jul 2025 14:44:03 +0200 Subject: [PATCH] windows: include `wincrypt.h` before `iphlpapi.h` for mingw-w64 <6 Required for mingw-w64 5.x (and older) builds targeting a Windows 7+. mingw-w64 6+ fixed `mprapi.h` (included indirectly via `iphlpapi.h`) to include `wincrypt.h` for the missing types. MSVC is not affected because SDK 7.1a (the oldest MS SDK curl supports), `mprapi.h` does include `wincrypt.h`. Make sure to include `wincrypt.h` before including `iphlpapi.h` as a workaround. `wincrypt.h` is used unconditionally even though it's not available in UWP. This is safe in this context, because we use `iphlpapi.h` for `if_nametoindex`, which is not supported and used in UWP builds. This fixes auto-detection that missed detecting `if_nametoindex` in the affected combination, and this build error in non-unity builds: ``` In file included from D:/my-cache/mingw32/i686-w64-mingw32/include/iprtrmib.h:9:0, from D:/my-cache/mingw32/i686-w64-mingw32/include/iphlpapi.h:17, from D:/a/curl/curl/lib/url.c:63: D:/my-cache/mingw32/i686-w64-mingw32/include/mprapi.h:865:3: error: unknown type name 'CERT_NAME_BLOB' CERT_NAME_BLOB *certificateNames; ^~~~~~~~~~~~~~ D:/my-cache/mingw32/i686-w64-mingw32/include/mprapi.h:887:3: error: unknown type name 'CRYPT_HASH_BLOB' CRYPT_HASH_BLOB certBlob; ^~~~~~~~~~~~~~~ ``` Ref: https://github.com/curl/curl/actions/runs/16497057672/job/46645264552?pr=18012#step:10:140 This combination is not normally tested in CI. It was caught in the `dl-mingw, CM 6.4.0-i686 schannel !unity Win7` job while working on another PR. Follow-up to 0d71b18153c8edb996738f8a362373fc72d0013b #17413 Ref: #18009 Closes #18012 --- CMakeLists.txt | 3 ++- configure.ac | 1 + lib/url.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 334b5c3865..5f51997f2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1785,7 +1785,8 @@ check_function_exists("setlocale" HAVE_SETLOCALE) check_function_exists("setrlimit" HAVE_SETRLIMIT) if(WIN32) - check_symbol_exists("if_nametoindex" "winsock2.h;iphlpapi.h" HAVE_IF_NAMETOINDEX) # Windows Vista+ non-UWP + # include wincrypt.h as a workaround for mingw-w64 __MINGW64_VERSION_MAJOR <= 5 header bug */ + check_symbol_exists("if_nametoindex" "winsock2.h;wincrypt.h;iphlpapi.h" HAVE_IF_NAMETOINDEX) # Windows Vista+ non-UWP */ else() check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # net/if.h check_function_exists("realpath" HAVE_REALPATH) diff --git a/configure.ac b/configure.ac index acf253eadc..27c46bbffc 100644 --- a/configure.ac +++ b/configure.ac @@ -4275,6 +4275,7 @@ if test "$curl_cv_native_windows" = 'yes'; then #define WIN32_LEAN_AND_MEAN #endif #include + #include /* workaround for mingw-w64 __MINGW64_VERSION_MAJOR <= 5 header bug */ #include ]],[[ if_nametoindex(""); diff --git a/lib/url.c b/lib/url.c index 3d78ceeed5..df2a332061 100644 --- a/lib/url.c +++ b/lib/url.c @@ -60,6 +60,9 @@ #endif #if defined(HAVE_IF_NAMETOINDEX) && defined(_WIN32) +#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR <= 5) +#include /* workaround for old mingw-w64 missing to include it */ +#endif #include #endif -- 2.47.2