Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname

methods to the socket module.
This commit is contained in:
Gregory P. Smith 2011-05-15 00:26:45 -07:00
parent 1a4de20d95
commit 5ed2e779f1
7 changed files with 429 additions and 248 deletions

View file

@ -372,6 +372,16 @@ class GeneralModuleTests(unittest.TestCase):
finally:
socket.sethostname(oldhn)
@unittest.skipUnless(hasattr(socket, 'if_nameindex'),
'socket.if_nameindex() not available.')
def testInterfaceNameIndex(self):
interfaces = socket.if_nameindex()
for index, name in interfaces:
# interface indices are non-zero integers
self.assertGreater(index, 0)
self.assertEqual(index, socket.if_nametoindex(name))
self.assertEqual(name, socket.if_indextoname(index))
def testRefCountGetNameInfo(self):
# Testing reference count for getnameinfo
if hasattr(sys, "getrefcount"):