-
Notifications
You must be signed in to change notification settings - Fork 550
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
Add support for special hostname <broadcast> #592
base: master
Are you sure you want to change the base?
Conversation
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.
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
Thanks for the review. I moved the "resolving" of |
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.
Thanks!
Any chance of this being merged? |
Currently
sendto
would 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