示例#1
0
    a.done = 0
    return nl.NL_STOP


try:
    cbd = test_class()
    tx_cb = nl.nl_cb_alloc(nl.NL_CB_DEFAULT)
    rx_cb = nl.nl_cb_clone(tx_cb)
    s = nl.nl_socket_alloc_cb(tx_cb)
    nl.py_nl_cb_err(rx_cb, nl.NL_CB_CUSTOM, error_handler, cbd)
    nl.py_nl_cb_set(rx_cb, nl.NL_CB_FINISH, nl.NL_CB_CUSTOM, finish_handler,
                    cbd)
    nl.py_nl_cb_set(rx_cb, nl.NL_CB_ACK, nl.NL_CB_CUSTOM, ack_handler, cbd)
    nl.py_nl_cb_set(rx_cb, nl.NL_CB_VALID, nl.NL_CB_CUSTOM, msg_handler, cbd)

    genl.genl_connect(s)
    family = genl.genl_ctrl_resolve(s, 'nl80211')
    m = nl.nlmsg_alloc()
    genl.genlmsg_put(m, 0, 0, family, 0, 0, nl80211.NL80211_CMD_GET_WIPHY, 0)
    nl.nla_put_u32(m, nl80211.NL80211_ATTR_WIPHY, 0)

    err = nl.nl_send_auto_complete(s, m)
    if err < 0:
        nl.nlmsg_free(msg)

    while cbd.done > 0 and not err < 0:
        err = nl.nl_recvmsgs(s, rx_cb)
except Exception as e:
    (t, v, tb) = sys.exc_info()
    print v.message
    traceback.print_tb(tb)
示例#2
0
	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)
示例#3
0
def ack_handler(m, a):
	a.done = 0
	return nl.NL_STOP

try:
	cbd = test_class()
	tx_cb = nl.nl_cb_alloc(nl.NL_CB_DEFAULT)
	rx_cb = nl.nl_cb_clone(tx_cb)
	s = nl.nl_socket_alloc_cb(tx_cb)
	nl.py_nl_cb_err(rx_cb, nl.NL_CB_CUSTOM, error_handler, cbd);
	# nl.py_nl_cb_set(rx_cb, nl.NL_CB_FINISH, nl.NL_CB_CUSTOM, finish_handler, cbd);
	nl.py_nl_cb_set(rx_cb, nl.NL_CB_ACK, nl.NL_CB_CUSTOM, ack_handler, cbd);
	nl.py_nl_cb_set(rx_cb, nl.NL_CB_VALID, nl.NL_CB_CUSTOM, msg_handler, cbd);

	genl.genl_connect(s)
	family = genl.genl_ctrl_resolve(s, 'nl80211')
	m = nl.nlmsg_alloc()
	genl.genlmsg_put(m, 0, 0, family, 0, 0, nl80211.NL80211_CMD_GET_INTERFACE, 0)
	nl.nla_put_u32(m, nl80211.NL80211_ATTR_IFINDEX, nl.if_nametoindex('wlan0'))

	err = nl.nl_send_auto_complete(s, m);
	if err < 0:
		nl.nlmsg_free(msg)

	while cbd.done > 0 and not err < 0:
		err = nl.nl_recvmsgs(s, rx_cb)

except Exception as e:
	(t, v, tb) = sys.exc_info()
	print v.message
示例#4
0
    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)