getaddrinfo: improve the service/port resolution #524
Merged
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.
Hello,
While experimenting with the
wasm32-wasip2
target and CPython, I discovered an issue with thegetaddrinfo()
implementation: it fails to resolve the provided service into a port number, causingsin_port
to always be set to 0. This issue leads to failures in network-related functions that rely ongetaddrinfo()
, such as Python'surllib3
library, which passes the result directly toconnect()
. This results in connection attempts using a port value of 0, which naturally fails.Minimal example to reproduce the problem
Expected output:
Root Cause
The root cause is that
getaddrinfo()
does not correctly translate the provided service into a port number. As described in thegetaddrinfo()
man page, the function should:Proposed Fix
This pull request addresses the issue by implementing the following behavior for
getaddrinfo()
:NULL
, the port number in the returned socket addresses remains uninitialized.The PR does not currently add support for translating named services into port numbers because
getservbyname()
has not been implemented. In cases where a named service is provided, theEAI_NONAME
error code is returned.