Bug 88543 - socket.inet_aton("") raises socket.error
Summary: socket.inet_aton("") raises socket.error
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: python
Version: 9
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Mihai Ibanescu
QA Contact: Brock Organ
Depends On:
TreeView+ depends on / blocked
Reported: 2003-04-10 19:38 UTC by Hardy Merrill
Modified: 2007-04-18 16:52 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2004-04-12 16:43:33 UTC

Attachments (Terms of Use)

Description Hardy Merrill 2003-04-10 19:38:55 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225

Description of problem: is a valid ip address (netmask), so running
socket.inet_aton("") 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("")
> 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)
#define INADDR_NONE (-1)

        /* 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;
        packed_addr = inet_addr(ip_addr);

        if (packed_addr == INADDR_NONE) {       /* invalid address */
                        "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 (,
       and inet_aton provides a cleaner  way  to  indicate  error

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. run this script:

   import socket, sys, struct
   result = socket.inet_aton("")

Actual Results:  Traceback (most recent call last):
  File "./test2.py", line 3, in ?
    result = socket.inet_aton("")
socket.error: illegal IP address string passed to inet_aton

Expected Results:  shouldn't raise an error.

Additional info:

Comment 1 Mihai Ibanescu 2004-03-08 15:17:13 UTC
This is fixed in python 2.3.3, as my fedora box shows:

python -c "import socket; socket.inet_aton('')"

The fix could probably be backported from 2.3.3 to 2.2.2.

Comment 2 Mihai Ibanescu 2004-04-12 16:43:33 UTC
Closing, should be reopened if we need the backport.

Note You need to log in before you can comment on or make changes to this bug.