Support operating systems with only getaddrinfo(3) - #15475
Closed
sortie wants to merge 1 commit into
Closed
Conversation
sortie
force-pushed
the
getaddrinfo-only
branch
from
November 1, 2024 23:55
b464dfb to
b698c60
Compare
The gethostbyname(3) family was removed in POSIX-1.2008 in favor of getaddrinfo(3) introduced in POSIX-1.2001. Modern POSIX systems such as Sortix does not have gethostbyname nor the related definitions and structures. curl already only uses getaddrinfo(3) if available and thread safe, although there is mild breakage if the related gethostbyname definitions are missing. This change attempts to fix that breakage: Remove an unnecessary configure error if gethostbyname is missing since getaddrinfo is enough as a fallback. Rewrite Curl_ip2addr to not use struct hostent as it no longer is standardized and create the struct Curl_addrinfo directly. Only define the Curl_he2ai function on non-getaddrinfo systems where it is going to be used with struct hoestent. Revoke the fallback logic for when it's unknown whether getaddrinfo is thread safe. It doesn't appear to make any sense since h_errno is unrelated to getaddrinfo. The logic prevents new POSIX.1-2024 systems from passing the thread safety test since h_errno does not exist anymore and POSIX already requires getaddrinfo to be thread safe. There's already a denylist in place for operating systems with known buggy implementations.
sortie
force-pushed
the
getaddrinfo-only
branch
from
November 1, 2024 23:57
b698c60 to
dc6558c
Compare
Member
c-ares is a 3rd party asynchronous name resolver library. curl can optionally get built to use that instead of the "normal" resolver functions, which then will not call getaddrinfo() at all. We have CI jobs doing this and since all the CI ran green, it is a good indication your PR does not break that functionality. |
bagder
approved these changes
Nov 2, 2024
Member
|
Thanks! |
Contributor
Author
|
Woohoo thanks Daniel! Was fun to contribute to curl! |
pps83
pushed a commit
to pps83/curl
that referenced
this pull request
Apr 26, 2025
The gethostbyname(3) family was removed in POSIX-1.2008 in favor of getaddrinfo(3) introduced in POSIX-1.2001. Modern POSIX systems such as Sortix does not have gethostbyname nor the related definitions and structures. curl already only uses getaddrinfo(3) if available and thread safe, although there is mild breakage if the related gethostbyname definitions are missing. This change attempts to fix that breakage: Remove an unnecessary configure error if gethostbyname is missing since getaddrinfo is enough as a fallback. Rewrite Curl_ip2addr to not use struct hostent as it no longer is standardized and create the struct Curl_addrinfo directly. Only define the Curl_he2ai function on non-getaddrinfo systems where it is going to be used with struct hoestent. Revoke the fallback logic for when it's unknown whether getaddrinfo is thread safe. It doesn't appear to make any sense since h_errno is unrelated to getaddrinfo. The logic prevents new POSIX.1-2024 systems from passing the thread safety test since h_errno does not exist anymore and POSIX already requires getaddrinfo to be thread safe. There's already a denylist in place for operating systems with known buggy implementations. Closes curl#15475
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The gethostbyname(3) family was removed in POSIX-1.2008 in favor of getaddrinfo(3) introduced in POSIX-1.2001. Modern POSIX systems such as Sortix does not have gethostbyname nor the related definitions and structures.
curl already only uses getaddrinfo(3) if available and thread safe, although there is mild breakage if the related gethostbyname definitions are missing.
This change attempts to fix that breakage:
Remove an unnecessary configure error if gethostbyname is missing since getaddrinfo is enough as a fallback.
Rewrite Curl_ip2addr to not use struct hostent as it no longer is standardized and create the struct Curl_addrinfo directly.
Only define the Curl_he2ai function on non-getaddrinfo systems where it is going to be used with struct hoestent.
Revoke the fallback logic for when it's unknown whether getaddrinfo is thread safe. It doesn't appear to make any sense since h_errno is unrelated to getaddrinfo. The logic prevents new POSIX.1-2024 systems from passing the thread safety test since h_errno does not exist anymore and POSIX already requires getaddrinfo to be thread safe. There's already a denylist in place for operating systems with known buggy implementations.
--
I'm not sure what's up with those pragmas but I removed them, since I rewrote the code and the new implementation is quite clean and parts comes from above, where they were not needed.
Curl_he2aimay still be called if thelib/asyn-ares.chappens to be compiled in on a system with a thread-safe getaddrinfo. I'm unclear what ares even is and whether this would happen. Let me know if the logic needs to be amended or cleaned up.