[issue37495] socket.inet_aton parsing issue on some libc versions

STINNER Victor report at bugs.python.org
Fri Jul 5 08:32:32 EDT 2019


STINNER Victor <vstinner at redhat.com> added the comment:

One solution would to be reimplement socket.inet_aton() with inet_pton() internally.

inet_pton() is well specified and standard (POSIX). inet_aton() is not ("inet_aton() is not specified in POSIX.1, but is available on most systems." says its Linux manual page).

>>> socket.inet_pton(socket.AF_INET, "1.2.3.4")
b'\x01\x02\x03\x04'
>>> socket.inet_pton(socket.AF_INET, "1.2.3.4 extra string")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: illegal IP address string passed to inet_pton

Problems:

* inet_pton() requires an address family. Should we iterate on all supported address families until one works?
* inet_pton() doesn't accept IPv4 "short format" like "127"

>>> socket.inet_aton("127")
b'\x00\x00\x00\x7f'
>>> socket.inet_pton(socket.AF_INET, "127")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: illegal IP address string passed to inet_pton

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37495>
_______________________________________


More information about the Python-bugs-list mailing list