Index: Lib/test/test_socket.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_socket.py,v retrieving revision 1.65 diff -u -r1.65 test_socket.py --- Lib/test/test_socket.py 12 May 2003 20:19:37 -0000 1.65 +++ Lib/test/test_socket.py 17 Jun 2003 00:51:27 -0000 @@ -318,20 +318,25 @@ # Check that setting it to an invalid type raises TypeError self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") - def testIPv4toString(self): - if not hasattr(socket, 'inet_pton'): - return # No inet_pton() on this platform - from socket import inet_aton as f, inet_pton, AF_INET - g = lambda a: inet_pton(AF_INET, a) + def testIPv4toStringAtoN(self): + from socket import inet_aton as f self.assertEquals('\x00\x00\x00\x00', f('0.0.0.0')) self.assertEquals('\xff\x00\xff\x00', f('255.0.255.0')) self.assertEquals('\xaa\xaa\xaa\xaa', f('170.170.170.170')) self.assertEquals('\x01\x02\x03\x04', f('1.2.3.4')) + # This used to raise socket.error; it should never do so + self.assertEquals('\xff\xff\xff\xff', f('255.255.255.255')) + + def testIPv4toStringPtoN(self): + if not hasattr(socket, 'inet_pton'): + return # No inet_pton() on this platform + from socket import inet_pton, AF_INET + f = lambda a: inet_pton(AF_INET, a) - self.assertEquals('\x00\x00\x00\x00', g('0.0.0.0')) - self.assertEquals('\xff\x00\xff\x00', g('255.0.255.0')) - self.assertEquals('\xaa\xaa\xaa\xaa', g('170.170.170.170')) + self.assertEquals('\x00\x00\x00\x00', f('0.0.0.0')) + self.assertEquals('\xff\x00\xff\x00', f('255.0.255.0')) + self.assertEquals('\xaa\xaa\xaa\xaa', f('170.170.170.170')) def testIPv6toString(self): if not hasattr(socket, 'inet_pton'): @@ -352,20 +357,23 @@ f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae') ) - def testStringToIPv4(self): - if not hasattr(socket, 'inet_ntop'): - return # No inet_ntop() on this platform - from socket import inet_ntoa as f, inet_ntop, AF_INET - g = lambda a: inet_ntop(AF_INET, a) + def testStringToIPv4NtoA(self): + from socket import inet_ntoa as f self.assertEquals('1.0.1.0', f('\x01\x00\x01\x00')) self.assertEquals('170.85.170.85', f('\xaa\x55\xaa\x55')) self.assertEquals('255.255.255.255', f('\xff\xff\xff\xff')) self.assertEquals('1.2.3.4', f('\x01\x02\x03\x04')) - self.assertEquals('1.0.1.0', g('\x01\x00\x01\x00')) - self.assertEquals('170.85.170.85', g('\xaa\x55\xaa\x55')) - self.assertEquals('255.255.255.255', g('\xff\xff\xff\xff')) + def testStringToIPv4NtoP(self): + if not hasattr(socket, 'inet_ntop'): + return # No inet_ntop() on this platform + from socket import inet_ntop, AF_INET + f = lambda a: inet_ntop(AF_INET, a) + + self.assertEquals('1.0.1.0', f('\x01\x00\x01\x00')) + self.assertEquals('170.85.170.85', f('\xaa\x55\xaa\x55')) + self.assertEquals('255.255.255.255', f('\xff\xff\xff\xff')) def testStringToIPv6(self): if not hasattr(socket, 'inet_ntop'): Index: Modules/socketmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v retrieving revision 1.268 diff -u -r1.268 socketmodule.c --- Modules/socketmodule.c 10 May 2003 07:36:55 -0000 1.268 +++ Modules/socketmodule.c 17 Jun 2003 00:51:27 -0000 @@ -2820,14 +2820,16 @@ return NULL; #else /* ! HAVE_INET_ATON */ - /* XXX Problem here: inet_aton('255.255.255.255') raises - an exception while it should be a valid address. */ packed_addr = inet_addr(ip_addr); if (packed_addr == INADDR_NONE) { /* invalid address */ - PyErr_SetString(socket_error, - "illegal IP address string passed to inet_aton"); - return NULL; + /* 255.255.255.255 is a legal input that leads to error out */ + if (strcmp("255.255.255.255", ip_addr) != 0) { + /* Anything here is an illegal input */ + PyErr_SetString(socket_error, + "illegal IP address string passed to inet_aton"); + return NULL; + } } return PyString_FromStringAndSize((char *) &packed_addr, sizeof(packed_addr));