socket.inet_aton - bug?

Steve Holden sholden at holdenweb.com
Mon Jun 17 19:29:51 EDT 2002


"Uwe Mayer" <merkosh at hadiko.de> wrote ...
> Hi,
>
> socket.inet_ntoa() accepts the string '\xff\xff\xff\xff' which is
> excactly the same i'd expect socket.inet_aton('255.255.255.255') to
> produce if it accepted the string '255.255.255.255' as an IP adress.
> socket.inet_aton() dies with socket.error "illegal IP adress".
>
> i know this is no valid ip adress, but it is a valid netmask. the
> purpose of converting the netmask to a binary format was that i wanted
> to isolate the subnet of an ip adress.
> i wanted to use test_ip & netmask == ip_range to allow subnets to access
> a tcp server.
> is there another way of controlling this or why does socket.inet_aton()
> behave like that?
>

I can't really tell you why socket does that, but it seems to be a feature
of the underlying C socket library, which is where inet_aton() is defined.

The address 255.255.255.255 is, in fact, a valid destination for a
restricted broadcast (one which should be sent out only to hosts on the
local LAN).

 regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list