I have a Structure (in this case, the Netlink Msg Header), which I need to send through the socket to the kernel. The only way I understood is to use __reduce__() .
>>> class nlmsghdr(ctypes.Structure): ... _fields_ = [('nlmsg_len', ctypes.c_int32), ... ('nlmsg_type', ctypes.c_int16), ... ('nlmsg_flags', ctypes.c_int16), ... ('nlmsg_seq', ctypes.c_int32), ... ('nlmsg_pid', ctypes.c_int32)] ... >>> >>> hdr = nlmsghdr(20, 22, 769, 1328884876, 0) >>> hdr.__reduce__()[1][1][1] '\x14\x00\x00\x00\x16\x00\x01\x03\x8c,5O\x00\x00\x00\x00' >>> # socket.send(hdr.__reduce__()[1][1][1])
It seems that __reduce__ designed for serialization (pickle) and depending on it, to always work the same, it seems like a mistake.
Should there be a better way?
source share