diff options
author | Mark W. Eichin <eichin@thok.org> | 2009-04-24 05:21:41 +0000 |
---|---|---|
committer | Mark W. Eichin <eichin@thok.org> | 2009-04-24 05:21:41 +0000 |
commit | d82e67f2eb756e1e2e8b7c19630dd4a2d6aeaa17 (patch) | |
tree | ddd90e8687751562cb57f7b9a469423b0ae1b9c6 /lib/zephyr_tests.py | |
parent | aa706b41aba93656194347be6cddd9601a286925 (diff) |
test that the file descriptor ZGetFD returns is actually a socket
Diffstat (limited to 'lib/zephyr_tests.py')
-rwxr-xr-x | lib/zephyr_tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/zephyr_tests.py b/lib/zephyr_tests.py index 043ed2b..5855238 100755 --- a/lib/zephyr_tests.py +++ b/lib/zephyr_tests.py @@ -593,6 +593,26 @@ def find_buildpath(): return os.path.join(opts.builddir, "lib") +def getsockname(fd): + """wrapped C lib getsocketname (works on raw fd)""" + libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("c")) + + call_getsockname = libc.getsockname + call_getsockname.argtypes = [ + c_int, # int s + POINTER(sockaddr), # struct sockaddr *name + POINTER(c_int), # socklen_t *namelen + ] + name = sockaddr(0) + namelen = c_int(sizeof(name)) + ret = call_getsockname(fd, name, namelen) + if ret == 0: + return name + # we can't get at errno until python 2.6... + print ret + raise EnvironmentError("getsockname failed") + + if __name__ == "__main__": tester = ZephyrTestSuite(builddir=find_buildpath()) tester.setup() |