Beispiel #1
0
int main()
{
	int i;
	struct nlif_handle *h;

	h = nlif_open();
	if (h == NULL) {
		perror("nlif_open");
		exit(EXIT_FAILURE);
	}

	nlif_query(h);

	for (i=0; i<64; i++) {
		char name[IFNAMSIZ];
		unsigned int flags;

		if (nlif_index2name(h, i, name) == -1)
			continue;
		if (nlif_get_ifflags(h, i, &flags) == -1)
			continue;
		printf("index (%d) is %s (%s)\n", i, name,
			flags & IFF_RUNNING ? "RUNNING" : "NOT RUNNING");
	}

	nlif_close(h);
}
Beispiel #2
0
bool NetherNetlink::initialize()
{
	nfqHandle = nfq_open();

	if(!nfqHandle)
	{
		LOGE("Error during nfq_open()");
		return (false);
	}

	if(nfq_unbind_pf(nfqHandle, AF_INET) < 0)
	{
		LOGE("Error during nfq_unbind_pf() (no permission?)");
		return (false);
	}

	if(nfq_bind_pf(nfqHandle, AF_INET) < 0)
	{
		LOGE("Error during nfq_bind_pf()");
		return (false);
	}

	queueHandle = nfq_create_queue(nfqHandle, queue, &callback, this);

	if(!queueHandle)
	{
		LOGE("Error during nfq_create_queue()");
		return (false);
	}

	if(nfq_set_queue_flags(queueHandle, NFQA_CFG_F_SECCTX, NFQA_CFG_F_SECCTX))
		LOGI("This kernel version does not allow to retrieve security context");

	if(nfq_set_mode(queueHandle, netherConfig.copyPackets ? NFQNL_COPY_PACKET : NFQNL_COPY_META, 0xffff) < 0)
	{
		LOGE("Can't set packet_copy mode");
		nfq_destroy_queue(queueHandle);
		return (false);
	}

	if(nfq_set_queue_flags(queueHandle, NFQA_CFG_F_UID_GID, NFQA_CFG_F_UID_GID))
	{
		LOGE("This kernel version does not allow to retrieve process UID/GID");
		nfq_destroy_queue(queueHandle);
		return (false);
	}

	if (netherConfig.interfaceInfo)
	{
		nlif = nlif_open();

		if(!nlif)
			LOGI("Failed to initialize NLIF subsystem, interface information won't be available");
		else
			nlif_query(nlif);
	}

	return (true);
}
Beispiel #3
0
struct nlif_handle *nl_init_interface_handler(void)
{
	struct nlif_handle *h;
	h = nlif_open();
	if (h == NULL)
		return NULL;

	if (nlif_query(h) == -1) {
		free(h);
		return NULL;
	}
	fcntl(nlif_fd(h), F_SETFL, O_NONBLOCK);

	return h;
}
Beispiel #4
0
int main()
{
	int i;
	struct nlif_handle *h;

	h = nlif_open();
	if (h == NULL) {
		perror("nlif_open");
		exit(EXIT_FAILURE);
	}

	nlif_query(h);

	for (i=0; i<64; i++) {
		char name[IFNAMSIZ];

		if (nlif_index2name(h, i, name) == -1)
			continue;
		printf("index (%d) is %s\n", i, name);
	}

	nlif_close(h);
}