-
Notifications
You must be signed in to change notification settings - Fork 202
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
getaddrinfo: improve the service/port resolution #524
Conversation
Previously, the `getaddrinfo` function did not resolve service names into port numbers, resulting in `sin_port` and `sin6_port` being hard-coded to `0`. This commit adds support for `getaddrinfo` to parse the service string as a port number if it is provided in numeric form. However, this commit does not include support for resolving service names into port numbers, as the getservbyname() function has not been implemented (yet). In this case the `EAI_NONAME` error is returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I only implemented enough of Thanks, @Henkru! |
Thanks @abrown and @dicej for checking it out. I'm also considering to implement the
A 70 kB increase feels heavy for me. While compression could reduce this size, it would add complexity when updating the table and obscure its contents. Alternatively, the implementation could attempt to read the Any thoughts? |
I'd start out with a static array containing a dozen-or-so of the most commonly used protocols (http, ftp, ssh, etc) as the baseline. |
If you want an arbitrary sample, I did look into this a while ago and landed on this shortlist:
|
Note that |
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.