Message195859
Currently, setipaddr() has this code to special-case numeric IPv4 addresses and avoid a name resolution:
"""
if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 &&
0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 &&
0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) {
struct sockaddr_in *sin;
sin = (struct sockaddr_in *)addr_ret;
sin->sin_addr.s_addr = htonl(
((long) d1 << 24) | ((long) d2 << 16) |
((long) d3 << 8) | ((long) d4 << 0));
sin->sin_family = AF_INET;
#ifdef HAVE_SOCKADDR_SA_LEN
sin->sin_len = sizeof(*sin);
#endif
return 4;
}
"""
- it's sub-optimal to hand-parse an IP address while we have inet_pton() and getaddrinfo()
- it doesn't work for IPv6 addresses
- it's also subject to integer overflow due to the scanf formatter
Wouldn't it be better getaddrinfo() with AI_NUMERICHOST instead? |
|
Date |
User |
Action |
Args |
2013-08-22 05:44:15 | neologix | set | recipients:
+ neologix, loewis |
2013-08-22 05:44:15 | neologix | set | messageid: <1377150255.36.0.551541174341.issue18806@psf.upfronthosting.co.za> |
2013-08-22 05:44:15 | neologix | link | issue18806 messages |
2013-08-22 05:44:14 | neologix | create | |
|