This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Allow socket.inet_aton("255.255.255.255") on Windo
Type: Stage:
Components: Extension Modules Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: che_fox, georg.brandl, georg.brandl, irmen, rhettinger
Priority: normal Keywords: patch

Created on 2003-06-17 16:30 by che_fox, last changed 2022-04-10 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
socket.patch che_fox, 2003-06-17 16:30 socket.inet_aton fix for Windows "255.255.255.255"
socket-255.diff georg.brandl, 2005-06-10 17:29
Messages (5)
msg44049 - (view) Author: Ben Gertzfield (che_fox) (Python triager) Date: 2003-06-17 16:30
Currently there's an XXX comment in socketmodule.c for
the Windows implementation (actually, for any platform
that doesn't have inet_aton) of socket.inet_aton:

/* XXX Problem here: inet_aton('255.255.255.255') raises
   an exception while it should be a valid address. */

This patch (against Python CVS) fixes this problem by
special-casing "255.255.255.255" as input when
inet_addr returns -1 (usually an error).  We just
strcmp() the input string with "255.255.255.255" if
inet_addr returned -1; if it matches, we allow
PyString_FromStringAndSize() to do its thing on -1.

Also, I noticed that the unit tests for
module.inet_aton and friends were skipped if the
platform didn't have inet_pton; this is an obvious
error, and so I've split out the tests for inet_pton
and inet_ntop's IPv4 functionality from inet_aton and
inet_ntoa, as well as adding an explicit test for the
now-handled "255.255.255.255" case.

Finally, I haven't gotten CVS python to build on
Windows under Visual Studio.NET (I get 'invalid project
errors' when it tries to convert the VS6 project files
-- and I don't have VS6) although I've tested this
patch and the new tests on Debian Linux.  

This patch really should be applied to the 2.2
maintenance branch as well as 2.3, since
"255.255.255.255" is a legal IP address and is not
documented to raise an exception in the Python docs
(even though it does currently on Windows).
msg44050 - (view) Author: Irmen de Jong (irmen) (Python triager) Date: 2005-01-16 15:34
Logged In: YES 
user_id=129426

Looks good but I have one suggestion:
isn't it better to test for "255.255.255.255" before calling
inet_addr and then return '\xff\xff\xff\xff' directly,
rather than relying on INADDR_NONE being 0xffffffff ?
msg44051 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-10 17:29
Logged In: YES 
user_id=1188172

Attached new patch which special-cases 255.255.255.255 as
proposed by Irmen.
msg44052 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-08-26 08:23
Logged In: YES 
user_id=80475

Go for it.
msg44053 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-08-26 08:34
Logged In: YES 
user_id=1188172

Committed as
Modules/socketmodule.c r1.312 r1.311.2.1
Lib/test/test_socket.py r1.80, r1.77.2.2
History
Date User Action Args
2022-04-10 16:09:16adminsetgithub: 38668
2003-06-17 16:30:41che_foxcreate