Bug 88543 - socket.inet_aton("255.255.255.255") raises socket.error
Summary: socket.inet_aton("255.255.255.255") raises socket.error
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: python (Show other bugs)
(Show other bugs)
Version: 9
Hardware: All Linux
medium
medium
Target Milestone: ---
Assignee: Mihai Ibanescu
QA Contact: Brock Organ
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
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:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-04-12 16:43:33 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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:
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:

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('255.255.255.255')"

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.