[Python-Dev] Socket module corner cases

Bruce Christensen t-bruch at microsoft.com
Wed May 31 03:59:58 CEST 2006

> > * getfqdn(): The function seems to not always return the FQDN. For 
> >example, if I run the following code from 'mybox.mydomain.com', I get

> >strange output. Does getfqdn() remove the common domain between my 
> >hostname and the one that I'm looking up?
> >>>> socket.getfqdn('otherbox')
> ># expected 'otherbox.mydomain.com'
> getfqdn() calls the system library gethostbyaddr(), and searches the
> result for the first name that contains '.' or if no name contains
dot, it
> returns the canonical name (as defined by gethostbyaddr() and the
> host name resolver libraries (hosts file, DNS, NMB)).

After a little more investigation here, it appears that getfqdn()
returns the
name unchanged (or perhaps run through the system's resolver libs) if
there's no reverse DNS PTR entry. In the case given above,
otherbox.mydomain.com didn't have a reverse DNS entry, so getfqdn()
'OTHERBOX'. However, when getfqdn() is called with a name whose IP
have a PTR record, it returns the correct FQDN.

Thanks for the help. Now, couple more questions:

getnameinfo() accepts the NI_NAMEREQD flag. It appears, though that a
lookup (and associated error if the lookup fails) occurs independent of
whether the flag is specified. Does it actually do anything?

Does getnameinfo() support IPv6? It appears to fail (with a socket.error
that says "sockaddr resolved to multiple addresses") if both IPv4 and
are enabled.


More information about the Python-Dev mailing list