@staticmethod def recv(conn): msg = conn.recv() packet = msg.payload hdr = _genl_hdr_parse(packet[:4]) genlmsg = GeNlMessage(msg.type, hdr.cmd, [], msg.flags) genlmsg.attrs = parse_attributes(packet[4:]) genlmsg.version = hdr.version return genlmsg class Controller: def __init__(self, conn): self.conn = conn def get_family_id(self, family): a = NulStrAttr(CTRL_ATTR_FAMILY_NAME, family) m = GeNlMessage(GENL_ID_CTRL, CTRL_CMD_GETFAMILY, flags=NLM_F_REQUEST, attrs=[a]) m.send(self.conn) m = GeNlMessage.recv(self.conn) return m.attrs[CTRL_ATTR_FAMILY_ID].u16() connection = Connection(NETLINK_GENERIC) controller = Controller(connection)
def __init__(self, options): self.options = options self.connection = Connection(NETLINK_GENERIC) controller = Controller(self.connection) self.family_id = controller.get_family_id('TASKSTATS')
class TaskStatHelper(object): connection = Connection(NETLINK_GENERIC) controller = Controller(connection) family_id = controller.get_family_id('TASKSTATS')