[Python-Dev] Socket module corner cases
t-bruch at microsoft.com
Tue May 30 23:02:36 CEST 2006
I'm working on implementing a socket module for IronPython that aims to
be compatible with the standard CPython module documented at
http://docs.python.org/lib/module-socket.html. I have a few questions
about some corner cases that I've found. CPython results below are from
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
Without further ado, the questions:
* getfqdn(): The module docs specify that if no FQDN can be found,
socket.getfqdn() should return the hostname as returned by
gethostname(). However, CPython seems to return the passed-in hostname
rather than the local machine's hostname (as would be expected from
gethostname()). What's the correct behavior?
>>> s.getfqdn(' asdlfk asdfsadf ')
# expected 'mybox.mydomain.com'
* 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?
# expected 'otherbox.mydomain.com'
* gethostbyname_ex(): The CPython implementation doesn't seem to
respect the '' == INADDR_ANY and '<broadcast>' == INADDR_BROADCAST
forms. '' is treated as localhost, and '<broadcast>' raises a "host not
found" error. Is this intentional? A quick check seems to reveal that
gethostbyname() is the only function that respects '' and '<broadcast>'.
Are the docs or the implementation wrong?
* getprotobyname(): Only a few protocols seem to be supported. Why?
>>> for p in [a[8:] for a in dir(socket) if a.startswith('IPPROTO_')]:
... print p,
... print socket.getprotobyname(p)
... except socket.error:
... print "(not handled)"
AH (not handled)
DSTOPTS (not handled)
ESP (not handled)
FRAGMENT (not handled)
HOPOPTS (not handled)
ICMPV6 (not handled)
IDP (not handled)
IGMP (not handled)
IPV4 (not handled)
IPV6 (not handled)
MAX (not handled)
ND (not handled)
NONE (not handled)
RAW (not handled)
ROUTING (not handled)
Thanks for your help!
More information about the Python-Dev