Opened 15 years ago

Closed 15 years ago

#2654 defect closed wontfix (wontfix)

twisted.internet.abstract.isIPAddress rejects valid IPv4 strings

Reported by: Jean-Paul Calderone Owned by:
Priority: highest Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

127.1 is an allowed spelling of 127.0.0.1. isIPAddress returns False for this input, though.

Change History (13)

comment:1 Changed 15 years ago by Glyph

Owner: changed from Glyph to Jean-Paul Calderone

comment:2 Changed 15 years ago by Jean-Paul Calderone

Keywords: review added
Owner: Jean-Paul Calderone deleted

Done in isipaddress-2654

Numerous other common IPv4 conventions are still unsupported, but if someone wants those, they can add them later.

comment:3 Changed 15 years ago by therve

Keywords: review removed
Owner: set to Jean-Paul Calderone
Priority: normalhighest

Looks good. Please update the copyright of abstract.py, and merge.

For the record, it seems that socket.inet_aton might do the job here. I don't know about the platform support though.

comment:4 Changed 15 years ago by Jean-Paul Calderone

Yep, inet_aton would work too, on all platforms I think, but I'm not ready to allow reactor.connectTCP('0x7f.0x00.0.01', ...) or to write tests to make sure it works. :)

comment:5 Changed 15 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [20345]) Merge isipaddress-2654

Author: exarkun Reviewer: therve Fixes #2654

Change twisted.internet.abstract.isIPAddress to accept dotted decimal strings of four or fewer parts if they are otherwise valid.

comment:6 Changed 15 years ago by jknight

Resolution: fixed
Status: closedreopened

What was the impetus for changing this? This is now incorrect for OSX, as 127.1 is actually *not* an IP address for OSX.

Python 2.3.5 (#1, Aug 19 2006, 21:31:42) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> s=socket.socket()
>>> s.connect(('127.1', 22))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 1, in connect
socket.gaierror: (7, 'No address associated with nodename')

Not only that, but it actually sent out a DNS query for the A record for "127.1".

comment:7 Changed 15 years ago by Jean-Paul Calderone

Meh, I hate OS X.

comment:8 Changed 15 years ago by Jean-Paul Calderone

Reverted at r20349.

Why doesn't this work on OS X? inet_aton seems to behave properly there. Is this a Python bug or a platform bug?

The impetus for the change is that '127.1' is a widely-accepted spelling for '127.0.0.1', and I wanted it to work with Twisted.

comment:9 Changed 15 years ago by jknight

It's a "platform bug". But I'd hardly call the 127.1 spelling widely-accepted. "It works sometimes" would be more accurate. E.g. host/nslookup, even on linux, doesn't accept it. I'm sure there's many more similar examples of places it is not accepted.

I suspect apple probably considers it a feature that it's not accepted, since its only use is making confusing URLs for phishing.

PS: doesn't work on winxp either.

comment:10 Changed 15 years ago by Jean-Paul Calderone

But inet_aton _does_ accept it on OS X. This is why I wonder if it's actually Python's fault this isn't working. inet_pton does _not_ accept it on Linux; I wonder if connect doesn't work with it on OS X because Python uses inet_pton on OS X.

comment:11 Changed 15 years ago by Jean-Paul Calderone

Okay, I finally bothered to dig all the way through sock_connect to the getaddrinfo call in setipaddr. I see that it's the difference in getaddrinfo on Linux and OS X that causes the difference in behavior.

comment:12 Changed 15 years ago by Jean-Paul Calderone

Resolution: wontfix
Status: reopenedclosed

This is a pretty big mess. Short of implementing an IPv4 address parser and changing isIPAddress to canonicalizeIPv4Address there's probably no reasonable change to make. Don't really feel like doing that.

comment:13 Changed 11 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.