def subscribe_multicast(self, mcname): mcid = genl.genl_ctrl_resolve_grp(self._sock._sock, 'nl80211', mcname) nl.nl_socket_add_membership(self._sock._sock, mcid) return mcid
def __init__(self,lig_program, mapresolver=None,simulate=None): self.done = 1; # by default, should be possible to override self.mapresolver = mapresolver or "153.16.49.112"; self.simulate = simulate self.lig_program = lig_program # TODO replace by Socket # allocates callback tx_cb = nl.nl_cb_alloc(nl.NL_CB_DEFAULT) #Clone an existing callback handle self.rx_cb = nl.nl_cb_clone(tx_cb) # allocates sockets self.sk = nl.nl_socket_alloc_cb(tx_cb) # set callback handers # last parameter represents arguments to pass logger.info("Setting callback functions") # nl.py_nl_cb_err(self.rx_cb, nl.NL_CB_CUSTOM, error_handler, self); # nl_cb_set( callback_set, type, kind, function,args ) nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_FINISH, nl.NL_CB_VERBOSE, finish_handler, self); nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_ACK, nl.NL_CB_VERBOSE, ack_handler, self); nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_VALID, nl.NL_CB_CUSTOM, msg_handler, self); # nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_VALID, nl.NL_CB_CUSTOM, self.handle, self); nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_INVALID, nl.NL_CB_DEBUG, None, None); # Notifications do not use sequence numbers, disable sequence number checking. # nl.nl_socket_disable_seq_check(self.sk); # MANDATORY because of a bug in netlink that sends -NLE_SEQ_MISMATCH otherwise nl.nl_socket_disable_auto_ack(self.sk); # establish connection genl.genl_connect(self.sk) self.family_id = genl.genl_ctrl_resolve(self.sk, LIG_FAMILY_NAME) # register to the multicast group # print( dir( sys.modules["netlink.genl.capi"]) ) # print( dir( sys.modules["netlink.capi"]) ) logger.info("family %s registered with number %d"%(LIG_FAMILY_NAME, self.family_id)); self.group_id = genl.genl_ctrl_resolve_grp (self.sk, LIG_FAMILY_NAME, LIG_GROUP_NAME); if self.group_id < 0 : # should log it logger.error("Could not find group group %s. Is the adequate module loaded ?"%LIG_FAMILY_NAME) exit(1) logger.info("Group id found: %d" % self.group_id); logger.info("Using mapresolver %s"%self.mapresolver) if self.simulate: logger.info("Simulation mode enabled %d"%self.simulate) else: logger.info("Real mode enabled") ret = nl.nl_socket_add_membership(self.sk, self.group_id); if ret == 0: logger.info("Registration successful") else: logger.error("Could not register to group") exit(1)
def subscribe_multicast(self, mcname): mcid = genl_ctrl_resolve_grp(self._sock, 'nl80211', mcname) nl_socket_add_membership(self._sock, mcid) return mcid
def __init__(self, lig_program, mapresolver=None, simulate=None): self.done = 1 # by default, should be possible to override self.mapresolver = mapresolver or "153.16.49.112" self.simulate = simulate self.lig_program = lig_program # TODO replace by Socket # allocates callback tx_cb = nl.nl_cb_alloc(nl.NL_CB_DEFAULT) #Clone an existing callback handle self.rx_cb = nl.nl_cb_clone(tx_cb) # allocates sockets self.sk = nl.nl_socket_alloc_cb(tx_cb) # set callback handers # last parameter represents arguments to pass logger.info("Setting callback functions") # nl.py_nl_cb_err(self.rx_cb, nl.NL_CB_CUSTOM, error_handler, self); # nl_cb_set( callback_set, type, kind, function,args ) nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_FINISH, nl.NL_CB_VERBOSE, finish_handler, self) nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_ACK, nl.NL_CB_VERBOSE, ack_handler, self) nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_VALID, nl.NL_CB_CUSTOM, msg_handler, self) # nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_VALID, nl.NL_CB_CUSTOM, self.handle, self); nl.py_nl_cb_set(self.rx_cb, nl.NL_CB_INVALID, nl.NL_CB_DEBUG, None, None) # Notifications do not use sequence numbers, disable sequence number checking. # nl.nl_socket_disable_seq_check(self.sk); # MANDATORY because of a bug in netlink that sends -NLE_SEQ_MISMATCH otherwise nl.nl_socket_disable_auto_ack(self.sk) # establish connection genl.genl_connect(self.sk) self.family_id = genl.genl_ctrl_resolve(self.sk, LIG_FAMILY_NAME) # register to the multicast group # print( dir( sys.modules["netlink.genl.capi"]) ) # print( dir( sys.modules["netlink.capi"]) ) logger.info("family %s registered with number %d" % (LIG_FAMILY_NAME, self.family_id)) self.group_id = genl.genl_ctrl_resolve_grp(self.sk, LIG_FAMILY_NAME, LIG_GROUP_NAME) if self.group_id < 0: # should log it logger.error( "Could not find group group %s. Is the adequate module loaded ?" % LIG_FAMILY_NAME) exit(1) logger.info("Group id found: %d" % self.group_id) logger.info("Using mapresolver %s" % self.mapresolver) if self.simulate: logger.info("Simulation mode enabled %d" % self.simulate) else: logger.info("Real mode enabled") ret = nl.nl_socket_add_membership(self.sk, self.group_id) if ret == 0: logger.info("Registration successful") else: logger.error("Could not register to group") exit(1)