This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, koobs, mattrobenolt, ned.deily, r.david.murray, ronaldoussoren, xiang.zhang
Date 2016-07-25.20:22:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1469478167.43.0.462115020372.issue27612@psf.upfronthosting.co.za>
In-reply-to
Content
socket.gethostbyname calls the internal function setipaddr, which tries to avoid a name resolution by first calling either inet_pton or inet_addr. Otherwise it calls getaddrinfo.

Windows
-------

setipaddr calls inet_addr, which supports octal [1]. ctypes example:

    ws2_32 = ctypes.WinDLL('ws2_32')
    in_addr = ctypes.c_ubyte * 4
    ws2_32.inet_addr.restype = in_addr

    >>> ws2_32.inet_addr(b'0177.0000.0000.0001')[:]
    [127, 0, 0, 1]

3.5+ could call inet_pton since it was added in Vista. However, it does not support octal:

    >>> addr = in_addr()
    >>> ws2_32.inet_pton(socket.AF_INET, b'0177.0000.0000.0001', addr)
    0
    >>> ws2_32.inet_pton(socket.AF_INET, b'127.0.0.1', addr)
    1
    >>> addr[:]
    [127, 0, 0, 1]

socket.inet_pton instead calls WSAStringToAddressA, which does support octal:

    >>> list(socket.inet_pton(socket.AF_INET, '0177.0000.0000.0001'))
    [127, 0, 0, 1]

socket.gethostbyname_ex calls gethostbyname since gethostbyname_r isn't defined. This does not support octal and errors out:

    >>> socket.gethostbyname_ex('0177.0000.0000.0001')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    socket.herror: [Errno 11001] host not found

getaddrinfo also does not support octal and errors out:

    >>> socket.getaddrinfo('0177.0000.0000.0001', None)[0]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python35\lib\socket.py", line 732, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno 11001] getaddrinfo failed
    
    >>> ctypes.FormatError(11001)
    'No such host is known.'

[1]: https://msdn.microsoft.com/en-us/library/ms738563#internet_addresses
History
Date User Action Args
2016-07-25 20:22:47eryksunsetrecipients: + eryksun, ronaldoussoren, ned.deily, r.david.murray, koobs, xiang.zhang, mattrobenolt
2016-07-25 20:22:47eryksunsetmessageid: <1469478167.43.0.462115020372.issue27612@psf.upfronthosting.co.za>
2016-07-25 20:22:47eryksunlinkissue27612 messages
2016-07-25 20:22:47eryksuncreate