Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: do not use winsock2 inet_ntop()/inet_pton() #16577

Closed
wants to merge 3 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Mar 5, 2025

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.

curl/lib/inet_ntop.c

Lines 188 to 190 in b06c12b

* On Windows we store the error in the thread errno, not in the Winsock error
* code. This is to avoid losing the actual last Winsock error. When this
* function returns NULL, check errno not SOCKERRNO.

curl/lib/inet_pton.c

Lines 66 to 70 in b06c12b

* notice:
* On Windows we store the error in the thread errno, not
* in the Winsock error code. This is to avoid losing the
* actual last Winsock error. When this function returns
* -1, check errno not SOCKERRNO.

These promises are old (a1d5983) 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

@vszakats vszakats added the Windows Windows-specific label Mar 5, 2025
@vszakats vszakats changed the title [TEST] lib: do not use Windows inet_pton/inet_ntop windows: do not use winsock2 inet_pton()/inet_ntop() Mar 5, 2025
@vszakats vszakats changed the title windows: do not use winsock2 inet_pton()/inet_ntop() windows: do not use winsock2 inet_ntop()/inet_pton() Mar 6, 2025
@vszakats vszakats closed this in 8537a5b Mar 6, 2025
@vszakats vszakats deleted the sockerrno-more branch March 6, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

1 participant