Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/test_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,22 @@ def test_udp_sendto_dns(self):
s_transport.close()
self.loop.run_until_complete(asyncio.sleep(0.01))

def test_udp_sendto_broadcast(self):
coro = self.loop.create_datagram_endpoint(
asyncio.DatagramProtocol,
local_addr=('127.0.0.1', 0),
family=socket.AF_INET)

s_transport, server = self.loop.run_until_complete(coro)

try:
s_transport.sendto(b'aaaa', ('<broadcast>', 80))
except ValueError as exc:
raise AssertionError('sendto raises {}.'.format(exc))

s_transport.close()
self.loop.run_until_complete(asyncio.sleep(0.01))

def test_send_after_close(self):
coro = self.loop.create_datagram_endpoint(
asyncio.DatagramProtocol,
Expand Down
4 changes: 4 additions & 0 deletions uvloop/dns.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ cdef __convert_pyaddr_to_sockaddr(int family, object addr,

port = __port_to_int(port, None)

# resolve special hostname <broadcast> to the broadcast address
if host == b'<broadcast>':
host = b'255.255.255.255'

ret.addr_size = sizeof(system.sockaddr_in)
err = uv.uv_ip4_addr(host, <int>port, <system.sockaddr_in*>&ret.addr)
if err < 0:
Expand Down
Loading