[New-bugs-announce] [issue28431] socket gethostbyaddr returns IPv6 names for 127.0.0.1

Nick Carboni report at bugs.python.org
Thu Oct 13 11:12:28 EDT 2016


New submission from Nick Carboni:

socket.gethostbyaddr seems to be equating loopback addresses regardless of IP protocol version.

In both versions tested (2.7.5 and 3.4.3) the ordering of the entries in my /etc/hosts file determines the result I get, rather than what address I'm querying for.

For example:

/etc/hosts:

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

result:

>>> import socket
>>> socket.gethostbyaddr("127.0.0.1")
('localhost', ['localhost.localdomain', 'localhost6', 'localhost6.localdomain6'], ['127.0.0.1'])

Then if I change the ordering of the entries in /etc/hosts as follows:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

result:

>>> import socket
>>> socket.gethostbyaddr("127.0.0.1")
('localhost', ['localhost.localdomain', 'localhost4', 'localhost4.localdomain4'], ['127.0.0.1'])

I would expect gethostbyaddr to return only the hostnames associated with the given address regardless of the ordering of the entries in /etc/hosts.

----------
messages: 278580
nosy: carbonin
priority: normal
severity: normal
status: open
title: socket gethostbyaddr returns IPv6 names for 127.0.0.1
type: behavior
versions: Python 2.7, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28431>
_______________________________________


More information about the New-bugs-announce mailing list