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 loewis, neologix
Date 2013-08-22.05:44:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1377150255.36.0.551541174341.issue18806@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2013-08-22 05:44:15neologixsetrecipients: + neologix, loewis
2013-08-22 05:44:15neologixsetmessageid: <1377150255.36.0.551541174341.issue18806@psf.upfronthosting.co.za>
2013-08-22 05:44:15neologixlinkissue18806 messages
2013-08-22 05:44:14neologixcreate