From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 Description of problem: 255.255.255.255 is a valid ip address (netmask), so running socket.inet_aton("255.255.255.255") should *NOT* raise a socket.error. But it does raise a socket.error. Here is a message from 'misa' in response to my inquiry: > I'm having a problem that I wanted to ask you about since you > are the Python maintainer. When I do > > result = socket.inet_aton("255.255.255.255") > > a socket.error gets raised. Is this correct? A friend of > mine did the same inet_aton call in C and it worked (didn't > fail). Shouldn't that work, and NOT raise an error? Heh again. static PyObject* PySocket_inet_aton(PyObject *self, PyObject *args) { #ifndef INADDR_NONE #define INADDR_NONE (-1) #endif /* Have to use inet_addr() instead */ char *ip_addr; unsigned long packed_addr; if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) { return NULL; } #ifdef USE_GUSI1 packed_addr = inet_addr(ip_addr).s_addr; #else packed_addr = inet_addr(ip_addr); #endif if (packed_addr == INADDR_NONE) { /* invalid address */ PyErr_SetString(PySocket_Error, "illegal IP address string passed to inet_aton"); return NULL; } man inet_addr The inet_addr() function converts the Internet host address cp from numbers-and-dots notation into binary data in network byte order. If the input is invalid, INADDR_NONE (usually -1) is returned. This is an obsolete interface to inet_aton, described immediately above; it is obsolete because -1 is a valid address (255.255.255.255), and inet_aton provides a cleaner way to indicate error return. Version-Release number of selected component (if applicable): python-2.2.2-26 How reproducible: Always Steps to Reproduce: 1. run this script: #!/usr/bin/python import socket, sys, struct result = socket.inet_aton("255.255.255.255") Actual Results: Traceback (most recent call last): File "./test2.py", line 3, in ? result = socket.inet_aton("255.255.255.255") socket.error: illegal IP address string passed to inet_aton Expected Results: shouldn't raise an error. Additional info:
This is fixed in python 2.3.3, as my fedora box shows: python -c "import socket; socket.inet_aton('255.255.255.255')" The fix could probably be backported from 2.3.3 to 2.2.2.
Closing, should be reopened if we need the backport.