[pypy-commit] pypy arm-backend-2: fix for test_addr_raw_packet to get the correct interface number for lo and use that in the test instead of 1

bivab noreply at buildbot.pypy.org
Wed Aug 8 15:08:36 CEST 2012


Author: David Schneider <david.schneider at picle.org>
Branch: arm-backend-2
Changeset: r56653:d599042a2d28
Date: 2012-08-08 13:07 +0000
http://bitbucket.org/pypy/pypy/changeset/d599042a2d28/

Log:	fix for test_addr_raw_packet to get the correct interface number for
	lo and use that in the test instead of 1

diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -243,10 +243,17 @@
 def test_addr_raw_packet():
     if not hasattr(rsocket._c, 'sockaddr_ll'):
         py.test.skip("posix specific test")
+    # HACK: To get the correct interface numer of lo, which in most cases is 1,
+    # but can be anything (i.e. 39), we need to call the libc function
+    # if_nametoindex to get the correct index
+    import ctypes
+    libc = ctypes.CDLL(ctypes.util.find_library('c'))
+    ifnum = libc.if_nametoindex('lo')
+
     c_addr_ll = lltype.malloc(rsocket._c.sockaddr_ll, flavor='raw')
     addrlen = rffi.sizeof(rsocket._c.sockaddr_ll)
     c_addr = rffi.cast(lltype.Ptr(rsocket._c.sockaddr), c_addr_ll)
-    rffi.setintfield(c_addr_ll, 'c_sll_ifindex', 1)
+    rffi.setintfield(c_addr_ll, 'c_sll_ifindex', ifnum)
     rffi.setintfield(c_addr_ll, 'c_sll_protocol', 8)
     rffi.setintfield(c_addr_ll, 'c_sll_pkttype', 13)
     rffi.setintfield(c_addr_ll, 'c_sll_hatype', 0)


More information about the pypy-commit mailing list