]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
When checking for "same address", use the binary form of the address.
authorBob Halley <halley@nominum.com>
Thu, 18 Jun 2009 13:10:28 +0000 (14:10 +0100)
committerBob Halley <halley@nominum.com>
Thu, 18 Jun 2009 13:10:28 +0000 (14:10 +0100)
By doing that, we don't get confused if the textual forms for the addresses
are equivalent but different (which can happen with IPv6 addresses).

Thanks to Kim Davies for finding this bug.

dns/query.py

index 93adc2eb23fbec3136a8b872f1401ee2069e05b3..81a78b43bfd3781a0e53aed3e10375b25c1203fe 100644 (file)
@@ -72,6 +72,14 @@ def _wait_for_readable(s, expiration):
 def _wait_for_writable(s, expiration):
     _wait_for([], [s], [s], expiration)
 
+def _addresses_equal(af, a1, a2):
+    # Convert the first value of the tuple, which is a textual format
+    # address into binary form, so that we are not confused by different
+    # textual representations of the same address
+    n1 = dns.inet.inet_pton(af, a1[0])
+    n2 = dns.inet.inet_pton(af, a2[0])
+    return n1 == n2 and a1[1:] == a2[1:]
+
 def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
         ignore_unexpected=False, one_rr_per_rrset=False):
     """Return the response obtained after sending a query via UDP.
@@ -127,9 +135,9 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
         while 1:
             _wait_for_readable(s, expiration)
             (wire, from_address) = s.recvfrom(65535)
-            if from_address == destination or \
-               (dns.inet.is_multicast(where) and \
-                from_address[1] == destination[1]):
+            if _addresses_equal(from_address, destination) or \
+                    (dns.inet.is_multicast(where) and \
+                         from_address[1:] == destination[1:]):
                 break
             if not ignore_unexpected:
                 raise UnexpectedSource, \