This does not work:
class ifinfomsg(ctypes.Structure): _fields_ = [ ('ifi_family', ctypes.c_ubyte), ('__ifi_pad', ctypes.c_ubyte), ('ifi_type', ctypes.c_ushort), ('ifi_index', ctypes.c_int), ('ifi_flags', ctypes.c_uint), ('ifi_change', ctypes.c_uint(0xFFFFFFFF)) ]
These are errors with:
File "rtnetlink.py", line 243, in <module> class ifinfomsg(ctypes.Structure): TypeError: Error when calling the metaclass bases second item in _fields_ tuple (index 5) must be a C type
However, I can set the values ββin __init__() :
class ifinfomsg(ctypes.Structure): _fields_ = [ ('ifi_family', ctypes.c_ubyte), ('__ifi_pad', ctypes.c_ubyte), ('ifi_type', ctypes.c_ushort), ('ifi_index', ctypes.c_int), ('ifi_flags', ctypes.c_uint), ('ifi_change', ctypes.c_uint) ] def __init__(self): self.__ifi_pad = 0 self.ifi_change = 0xFFFFFFFF
Is this the right way to do this via __init__ ?
source share