diff options
| author | Bob Halley <halley@nominum.com> | 2009-06-18 14:10:28 +0100 |
|---|---|---|
| committer | Bob Halley <halley@nominum.com> | 2009-06-18 14:10:28 +0100 |
| commit | f7a29a67ac18a27bfa74bc9caeb6bd886fc3173c (patch) | |
| tree | 726d3528b5d4510e6d7c0cd45cc40c2fad1441bc | |
| parent | 791c9cb7df40cd1aabbc5bb89d79f504bca09175 (diff) | |
| download | dnspython-f7a29a67ac18a27bfa74bc9caeb6bd886fc3173c.tar.gz | |
When checking for "same address", use the binary form of the address.
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.
| -rw-r--r-- | dns/query.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/dns/query.py b/dns/query.py index 93adc2e..81a78b4 100644 --- a/dns/query.py +++ b/dns/query.py @@ -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, \ |
