diff --git a/tests/test_dns.py b/tests/test_dns.py index 66da026b..6f3f7d65 100644 --- a/tests/test_dns.py +++ b/tests/test_dns.py @@ -199,6 +199,10 @@ def test_getaddrinfo_22(self): self._test_getaddrinfo(payload, 80) self._test_getaddrinfo(payload, 80, type=socket.SOCK_STREAM) + def test_getaddrinfo_broadcast(self): + self._test_getaddrinfo('', 80) + self._test_getaddrinfo('', 80, type=socket.SOCK_STREAM) + ###### def test_getnameinfo_1(self): diff --git a/tests/test_udp.py b/tests/test_udp.py index dd739650..1b7953f2 100644 --- a/tests/test_udp.py +++ b/tests/test_udp.py @@ -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', ('', 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, diff --git a/uvloop/handles/udp.pyx b/uvloop/handles/udp.pyx index ef20c3f7..eac1bca5 100644 --- a/uvloop/handles/udp.pyx +++ b/uvloop/handles/udp.pyx @@ -208,6 +208,10 @@ cdef class UDPTransport(UVBaseTransport): if addr is None: saddr = NULL else: + # resolve special hostname to the broadcast address before use + if self._family == uv.AF_INET and addr[0] == '': + addr = (b'255.255.255.255', addr[1]) + try: __convert_pyaddr_to_sockaddr(self._family, addr, &saddr_st)