Disable these winsock2 functions on Windows to use the curl wrappers
and preserve `WSAGetLastError()` aka `SOCKERRNO` error codes.
curl sources uses `inet_pton()` and `inet_ntop()` via its own `Curl_`
prefixed wrappers. These wrappers promise to not overwrite
`WSAGetLastError()` aka `SOCKERRNO` error codes when calling them.
But, for Windows builds with these built-in winsock2 functions detected
(meaning all supported Windows versions, except Windows CE),
the wrappers were 1-to-1 mapped to the winsock2 functions, which broke
this promise.
https://github.com/curl/curl/blob/
b06c12b7248592cf001e621d7cd8dc78a827212b/lib/inet_ntop.c#L188-L190
https://github.com/curl/curl/blob/
b06c12b7248592cf001e621d7cd8dc78a827212b/lib/inet_pton.c#L66-L70
These promises are old (
a1d598399146984c99baa46db148e87c75261033) and
may not be valid anymore. In this case, the callers would have to be
updated to use `SOCKERRNO` to retrieve any error, instead of using
`errno` as they do now.
https://learn.microsoft.com/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_ntop
https://learn.microsoft.com/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_pton
Closes #16577
set(HAVE_GMTIME_R 0)
set(HAVE_IFADDRS_H 0)
set(HAVE_IF_NAMETOINDEX 0)
+set(HAVE_INET_NTOP 0)
+set(HAVE_INET_PTON 0)
set(HAVE_IOCTLSOCKET 1)
set(HAVE_IOCTLSOCKET_CAMEL 0)
set(HAVE_IOCTLSOCKET_CAMEL_FIONBIO 0)
list(APPEND CURL_INCLUDES "winsock2.h")
list(APPEND CURL_INCLUDES "ws2tcpip.h")
- if(HAVE_WIN32_WINNT)
- if(HAVE_WIN32_WINNT LESS 0x0501 AND NOT WINCE)
- # Windows XP is required for freeaddrinfo, getaddrinfo
- message(FATAL_ERROR "Building for Windows XP or newer is required.")
- endif()
-
- # Pre-fill detection results based on target OS version
- if(MINGW OR MSVC OR WINCE)
- if(WINCE OR HAVE_WIN32_WINNT LESS 0x0600)
- set(HAVE_INET_NTOP 0)
- set(HAVE_INET_PTON 0)
- else() # Windows Vista or newer
- set(HAVE_INET_NTOP 1)
- set(HAVE_INET_PTON 1)
- endif()
- unset(HAVE_INET_NTOP CACHE)
- unset(HAVE_INET_PTON CACHE)
- endif()
+ if(HAVE_WIN32_WINNT AND HAVE_WIN32_WINNT LESS 0x0501 AND NOT WINCE)
+ # Windows XP is required for freeaddrinfo, getaddrinfo
+ message(FATAL_ERROR "Building for Windows XP or newer is required.")
endif()
endif()
if(APPLE)
check_function_exists("mach_absolute_time" HAVE_MACH_ABSOLUTE_TIME)
endif()
-check_symbol_exists("inet_ntop" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP) # arpa/inet.h netinet/in.h sys/socket.h
-check_symbol_exists("inet_pton" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON) # arpa/inet.h netinet/in.h sys/socket.h
+if(NOT WIN32)
+ check_symbol_exists("inet_ntop" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_NTOP) # arpa/inet.h netinet/in.h sys/socket.h
+ check_symbol_exists("inet_pton" "${CURL_INCLUDES};stdlib.h;string.h" HAVE_INET_PTON) # arpa/inet.h netinet/in.h sys/socket.h
+endif()
check_symbol_exists("fsetxattr" "sys/xattr.h" HAVE_FSETXATTR)
if(HAVE_FSETXATTR)
CURL_CHECK_FUNC_GETPEERNAME
CURL_CHECK_FUNC_GETSOCKNAME
CURL_CHECK_FUNC_GMTIME_R
-CURL_CHECK_FUNC_INET_NTOP
-CURL_CHECK_FUNC_INET_PTON
CURL_CHECK_FUNC_IOCTL
CURL_CHECK_FUNC_IOCTLSOCKET
CURL_CHECK_FUNC_IOCTLSOCKET_CAMEL
realpath \
sched_yield \
])
+ CURL_CHECK_FUNC_INET_NTOP
+ CURL_CHECK_FUNC_INET_PTON
CURL_CHECK_FUNC_STRCASECMP
CURL_CHECK_FUNC_STRCMPI
CURL_CHECK_FUNC_STRICMP
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
-#ifdef _WIN32
-#if defined(_MSC_VER) && (_MSC_VER <= 1900)
-#define Curl_inet_ntop(af,addr,buf,size) inet_ntop(af, (void *)addr, buf, size)
-#else
-#define Curl_inet_ntop(af,addr,buf,size) inet_ntop(af, addr, buf, size)
-#endif
-#elif defined(__AMIGA__)
+#ifdef __AMIGA__
#define Curl_inet_ntop(af,addr,buf,size) \
(char *)inet_ntop(af, (void *)addr, (unsigned char *)buf, \
(curl_socklen_t)(size))
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
-#if defined(__AMIGA__)
+#ifdef __AMIGA__
#define Curl_inet_pton(x,y,z) inet_pton(x,(unsigned char *)y,z)
#else
#define Curl_inet_pton(x,y,z) inet_pton(x,y,z)