Eryk Sun added the comment: 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 ---------- nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27612> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com