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 neologix
Recipients ezio.melotti, maker, neologix, pitrou, santoso.wijaya, vstinner
Date 2013-08-29.10:07:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1377770864.76.0.573171280218.issue16201@psf.upfronthosting.co.za>
In-reply-to
Content
Stupid question: why use scanf()/strtol() to parse an IP address, and not simply inet_pton()/inet_aton(), which are made precisely for that purpose?
inet_pton() is POSIX (it was introduced at the same time as getaddrinfo(), which is used unconditionally a couple lines below). If it's not available, we could use inet_aton() as fallback (which is amusingly not POSIX, but I doubt we'll find a platform with neither inet_pton() nor inet_aton()).

Using inet_pton() would have the added advantage of working with IPv6 addresses: right now, a numeric IPv6 address is always resolved by getaddrinfo(), which results in a performance overhead:

$ python -m timeit -s "from socket import *; s = socket(AF_INET, SOCK_DGRAM); DATA = 'hello'" "s.sendto(DATA, ('127.0.0.1', 42))"
100000 loops, best of 3: 6.86 usec per loop
$ python -m timeit -s "from socket import *; s = socket(AF_INET6, SOCK_DGRAM); DATA = 'hello'" "s.sendto(DATA, ('::1', 42))"
10000 loops, best of 3: 24.2 usec per loop
History
Date User Action Args
2013-08-29 10:07:44neologixsetrecipients: + neologix, pitrou, vstinner, ezio.melotti, santoso.wijaya, maker
2013-08-29 10:07:44neologixsetmessageid: <1377770864.76.0.573171280218.issue16201@psf.upfronthosting.co.za>
2013-08-29 10:07:44neologixlinkissue16201 messages
2013-08-29 10:07:43neologixcreate