[Python-Dev] [patch #100927] Fix for broken gethostbyname("0")

Thomas Wouters thomas@xs4all.net
Fri, 21 Jul 2000 08:13:54 +0200


On Fri, Jul 21, 2000 at 12:21:08AM +0200, Fredrik Lundh wrote:

> Pekka hasn't followed up on my comments on the patch
> page, so I thought I'd take the question to this forum in-
> stead:
> 
>     -- why is gethostbyname "broken" if it doesn't
>        support the magic strings "0" and "-1"?

> I'm tempted to reject the patch, but I'm probably missing
> something here...

Well, '0' is a valid ipaddress. Strange, but valid. An ipaddress needn't
contain any dots ;) it's just a 32bit value, after all. The dot-notation is
for convenience, mostly:

centurion:~ > ping 0
PING 0 (0.0.0.0) from 127.0.0.1 : 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=0.1 ms

(This is also the reason '127.0.0.1' can be written as '127.1')

You can also type things like 'http://2224488794' in most browsers. Go
ahead, try it ;) So I'd say: accept "0". It's valid behaviour.

However, -1 is something else:

centurion:~ > ping -- -1
ping: unknown host -1

I can see where it comes from, as it should be interpreted as 0xFFFFFFFF,
but it's not a convention I'm aware of. And it's also not 'an ipaddress in
dot notation', because there can't be negative values in an ipaddress even
if you leave out the dots.

All in all, I'm +1 on the first, -1 on the second.

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!