getfqdn passes a hostname to gethostbyaddr instead of an ip address

Rhodri James rhodri at kynesim.co.uk
Wed Sep 12 12:08:50 EDT 2018


On 12/09/18 15:29, Florian Bergmann wrote:
> Hello,
> 
> While I was debugging some salt issues I dug into the python code and found a
> piece of code in the `socket.py` module that surprised my a bit:
> 
> In the `getfqdn` function the `gethostbyaddr` name function is being called with
> a `hostname` instead of an `ipaddress`:

[snip]

> 2. `gethostbyaddr()`:
> 
> Also from the documentation:
> 
> ```
> Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host name responding to the *given ip_address* (...)
> ```
> 
> As the documentation states it expects an `ip_address` and not a hostname,
> but it is given a `hostname` instead.

I believe the online documentation is wrong.  The help text certainly 
differs:

Help on built-in function gethostbyaddr in module _socket:

gethostbyaddr(...)
     gethostbyaddr(host) -> (name, aliaslist, addresslist)

     Return the true host name, a list of aliases, and a list of IP 
addresses,
     for a host.  The host argument is a string giving a host name or IP 
number.


-- 
Rhodri James *-* Kynesim Ltd



More information about the Python-list mailing list