Add support for special hostname <broadcast>#592
Merged
fantix merged 5 commits intoMagicStack:masterfrom Jan 12, 2026
Merged
Conversation
20 tasks
fantix
requested changes
Aug 15, 2024
Member
fantix
left a comment
There was a problem hiding this comment.
Thanks for the PR! This is almost a good one, except that __convert_pyaddr_to_sockaddr also affected getaddrinfo():
>>> import uvloop; loop=uvloop.new_event_loop(); loop.run_until_complete(loop.getaddrinfo('<broadcast>', 0, type=socket.SOCK_DGRAM))
[(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('255.255.255.255', 0))]
while CPython won't return 255.255.255.255:
import socket
>>> socket.getaddrinfo('<broadcast>', 0, type=socket.SOCK_DGRAM)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.12/socket.py", line 964, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name or service not known
Or asyncio:
>>> import asyncio
>>> loop=asyncio.new_event_loop()
>>> loop.run_until_complete(loop.getaddrinfo('<broadcast>',0,type=socket.SOCK_DGRAM))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/base_events.py", line 901, in getaddrinfo
return await self.run_in_executor(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/socket.py", line 964, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name or service not known
Contributor
Author
|
Thanks for the review. I moved the "resolving" of |
|
Any chance of this being merged? |
|
I believe this closes this issue |
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.
Currently
sendtowould fail if you use the special hostname<broadcast>, which is a valid use according to the Python docs. This PR proposes to to "resolve" it to the broadcast address before passing it touv_ip4_addr.This resolves the issue #540