[pypy-svn] r26178 - pypy/dist/pypy/rpython/rctypes/socketmodule

ac at codespeak.net ac at codespeak.net
Sun Apr 23 12:39:20 CEST 2006


Author: ac
Date: Sun Apr 23 12:39:20 2006
New Revision: 26178

Modified:
   pypy/dist/pypy/rpython/rctypes/socketmodule/_socket.py
   pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py
Log:
(arre, sanxiyn)
Better ip-number parsing (hopefully fixing byte-order problems).



Modified: pypy/dist/pypy/rpython/rctypes/socketmodule/_socket.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/socketmodule/_socket.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/socketmodule/_socket.py	Sun Apr 23 12:39:20 2006
@@ -8,11 +8,6 @@
 class error(Exception):
     pass
 
-def _ip_to_number(ip):
-    p1, p2, p3, p4 = [ int(part) for part in ip.split('.') ]
-    num = ((p1 * 256 + p2) * 256 + p3) * 256 + p4
-    return num
-
 
 class socket(object):
 
@@ -44,11 +39,10 @@
         if self.family == AF_INET:
             (host, port) = addr
             ip = host # XXX
-            num = _ip_to_number(ip)
             caddr = _c.sockaddr_in()
             caddr.sin_family = AF_INET
             caddr.sin_port = _c.htons(port)
-            caddr.sin_addr.s_addr = _c.htonl(num)
+            _c.inet_aton(ip, pointer(caddr.sin_addr))
             return caddr
         else:
             raise NotImplementedError('sorry') # XXX

Modified: pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py	Sun Apr 23 12:39:20 2006
@@ -100,3 +100,7 @@
 ntohs = socketdll.htonl
 ntohs.argtypes = [uint16_t]
 ntohs.restype = uint16_t
+
+inet_aton = socketdll.inet_aton
+inet_aton.argtypes = [c_char_p, POINTER(in_addr)]
+inet_aton.restype = c_int



More information about the Pypy-commit mailing list