File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,23 @@ def test_create_datagram_endpoint_wrong_sock(self):
167
167
'A UDP Socket was expected' ):
168
168
self .loop .run_until_complete (coro )
169
169
170
+ def test_udp_sendto_dns (self ):
171
+ coro = self .loop .create_datagram_endpoint (
172
+ asyncio .DatagramProtocol ,
173
+ local_addr = ('127.0.0.1' , 0 ),
174
+ family = socket .AF_INET )
175
+
176
+ s_transport , server = self .loop .run_until_complete (coro )
177
+
178
+ with self .assertRaisesRegex (ValueError , 'DNS lookup' ):
179
+ s_transport .sendto (b'aaaa' , ('example.com' , 80 ))
180
+
181
+ with self .assertRaisesRegex (ValueError , 'socket family mismatch' ):
182
+ s_transport .sendto (b'aaaa' , ('::1' , 80 ))
183
+
184
+ s_transport .close ()
185
+ self .loop .run_until_complete (asyncio .sleep (0.01 , loop = self .loop ))
186
+
170
187
171
188
class Test_AIO_UDP (_TestUDP , tb .AIOTestCase ):
172
189
pass
Original file line number Diff line number Diff line change @@ -139,6 +139,19 @@ cdef class UDPTransport(UVBaseTransport):
139
139
raise ValueError (
140
140
' Invalid address: must be None or {}' .format(self .address))
141
141
142
+ if addr is not None :
143
+ addrinfo = __static_getaddrinfo_pyaddr(
144
+ addr[0 ], addr[1 ],
145
+ uv.AF_UNSPEC, self .sock.type, self .sock.proto, 0 )
146
+ if addrinfo is None :
147
+ raise ValueError (
148
+ ' UDP.sendto(): address {!r} requires a DNS lookup' .format(
149
+ addr))
150
+ if addrinfo[0 ] != self .sock.family:
151
+ raise ValueError (
152
+ ' UDP.sendto(): {!r} socket family mismatch' .format(
153
+ addr))
154
+
142
155
if self ._conn_lost and self ._address:
143
156
if self ._conn_lost >= LOG_THRESHOLD_FOR_CONNLOST_WRITES:
144
157
aio_logger.warning(' socket.send() raised exception.' )
You can’t perform that action at this time.
0 commit comments