Skip to content

Commit b6365aa

Browse files
authored
Ensure matching PTR queries are returned with the ANY query (#618)
Fixes #464
1 parent 427b728 commit b6365aa

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

tests/test_handlers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,31 @@ def test_ptr_optimization():
256256
zc.close()
257257

258258

259+
def test_any_query_for_ptr():
260+
"""Test that queries for ANY will return PTR records."""
261+
zc = Zeroconf(interfaces=['127.0.0.1'])
262+
type_ = "_knownservice._tcp.local."
263+
name = "knownname"
264+
registration_name = "%s.%s" % (name, type_)
265+
desc = {'path': '/~paulsm/'}
266+
server_name = "ash-2.local."
267+
ipv6_address = socket.inet_pton(socket.AF_INET6, "2001:db8::1")
268+
info = ServiceInfo(type_, registration_name, 80, 0, 0, desc, server_name, addresses=[ipv6_address])
269+
zc.register_service(info)
270+
271+
_clear_cache(zc)
272+
generated = r.DNSOutgoing(const._FLAGS_QR_QUERY)
273+
question = r.DNSQuestion(type_, const._TYPE_ANY, const._CLASS_IN)
274+
generated.add_question(question)
275+
packets = generated.packets()
276+
_, multicast_out = zc.query_handler.response(r.DNSIncoming(packets[0]), "1.2.3.4", const._MDNS_PORT)
277+
assert multicast_out.answers[0][0].name == type_
278+
assert multicast_out.answers[0][0].alias == registration_name
279+
# unregister
280+
zc.unregister_service(info)
281+
zc.close()
282+
283+
259284
def test_aaaa_query():
260285
"""Test that queries for AAAA records work."""
261286
zc = Zeroconf(interfaces=['127.0.0.1'])

zeroconf/_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _answer_question(
167167
additionals: Set[DNSRecord] = set()
168168
type_ = question.type
169169

170-
if type_ == _TYPE_PTR:
170+
if type_ in (_TYPE_PTR, _TYPE_ANY):
171171
self._add_pointer_answers(question.name, msg, answers, additionals)
172172

173173
if type_ in (_TYPE_A, _TYPE_AAAA, _TYPE_ANY):

0 commit comments

Comments
 (0)