From: Bob Halley Date: Tue, 7 Jul 2020 03:00:05 +0000 (-0700) Subject: In gethostbyaddr(), remove unneeded workarounds for getfqdn(). X-Git-Tag: v2.0.0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b9f344a97be43eb449ba68659be1dda2d8da61c;p=thirdparty%2Fdnspython.git In gethostbyaddr(), remove unneeded workarounds for getfqdn(). --- diff --git a/dns/resolver.py b/dns/resolver.py index ab408727..4f630e4d 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -1475,6 +1475,11 @@ def _gethostbyaddr(ip): sockaddr = (ip, 80, 0, 0) family = socket.AF_INET6 except Exception: + try: + dns.ipv4.inet_aton(ip) + except Exception: + raise socket.gaierror(socket.EAI_NONAME, + 'Name or service not known') sockaddr = (ip, 80) family = socket.AF_INET (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD) @@ -1486,16 +1491,11 @@ def _gethostbyaddr(ip): # We only want to include an address from the tuples if it's the # same as the one we asked about. We do this comparison in binary # to avoid any differences in text representations. - try: - bin_ip = dns.inet.inet_pton(family, ip) - except Exception: - # socket.getfqdn() apparently calls gethostbyaddr() with a name, - # and this all works, so do what it does. - bin_ip = None + bin_ip = dns.inet.inet_pton(family, ip) for item in tuples: addr = item[4][0] bin_addr = dns.inet.inet_pton(family, addr) - if bin_ip is None or bin_ip == bin_addr: + if bin_ip == bin_addr: addresses.append(addr) # XXX we just ignore aliases return (canonical, aliases, addresses)