]> granicus.if.org Git - python/commitdiff
Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even
authorGregory P. Smith <greg@mad-scientist.com>
Wed, 11 Feb 2009 23:45:25 +0000 (23:45 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Wed, 11 Feb 2009 23:45:25 +0000 (23:45 +0000)
on LP64 platforms (most 64-bit Linux, bsd, unix systems).

Lib/test/test_socket.py
Misc/NEWS
Modules/socketmodule.c

index 66664b44ed5bd481d38d3c9139370929db093679..5c906d776a70673cb6f7d79a6b87c90fa841d693 100644 (file)
@@ -388,6 +388,14 @@ class GeneralModuleTests(unittest.TestCase):
         # Check that setting it to an invalid type raises TypeError
         self.assertRaises(TypeError, socket.setdefaulttimeout, "spam")
 
+    def testIPv4_inet_aton_fourbytes(self):
+        if not hasattr(socket, 'inet_aton'):
+            return  # No inet_aton, nothing to check
+        # Test that issue1008086 and issue767150 are fixed.
+        # It must return 4 bytes.
+        self.assertEquals('\x00'*4, socket.inet_aton('0.0.0.0'))
+        self.assertEquals('\xff'*4, socket.inet_aton('255.255.255.255'))
+
     def testIPv4toString(self):
         if not hasattr(socket, 'inet_pton'):
             return # No inet_pton() on this platform
index a8b5a3cbe7b2858b06f7790f8f23c50bee9a55a1..530a55d38d1a9212b1eadaa435e771d63639adf0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -152,6 +152,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #1008086: Fixed socket.inet_aton() to always return 4 bytes even on
+  LP64 platforms (most 64-bit Linux, bsd, unix systems).
+
 - Issue #5203: Fixed ctypes segfaults when passing a unicode string to a
   function without argtypes (only occurs if HAVE_USABLE_WCHAR_T is false).
 
index fc85bcc894a9f358025aa4fbbfcfeff0292a5151..9cefe045ce1af50f32085b4590b2359b94c59fdf 100644 (file)
@@ -3769,8 +3769,11 @@ socket_inet_aton(PyObject *self, PyObject *args)
 #endif
 
 #if !defined(HAVE_INET_ATON) || defined(USE_INET_ATON_WEAKLINK)
+#if (SIZEOF_INT != 4)
+#error "Not sure if in_addr_t exists and int is not 32-bits."
+#endif
        /* Have to use inet_addr() instead */
-       unsigned long packed_addr;
+       unsigned int packed_addr;
 #endif
        char *ip_addr;
 
@@ -5305,7 +5308,10 @@ int
 inet_pton(int af, const char *src, void *dst)
 {
        if (af == AF_INET) {
-               long packed_addr;
+#if (SIZEOF_INT != 4)
+#error "Not sure if in_addr_t exists and int is not 32-bits."
+#endif
+               unsigned int packed_addr;
                packed_addr = inet_addr(src);
                if (packed_addr == INADDR_NONE)
                        return 0;