Message196452
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 |
|
Date |
User |
Action |
Args |
2013-08-29 10:07:44 | neologix | set | recipients:
+ neologix, pitrou, vstinner, ezio.melotti, santoso.wijaya, maker |
2013-08-29 10:07:44 | neologix | set | messageid: <1377770864.76.0.573171280218.issue16201@psf.upfronthosting.co.za> |
2013-08-29 10:07:44 | neologix | link | issue16201 messages |
2013-08-29 10:07:43 | neologix | create | |
|