Support operating systems with only getaddrinfo(3) #15475
Closed
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_he2ai
may still be called if thelib/asyn-ares.c
happens 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.