⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node_operate.c

📁 LInux BootLoader的说明文档
💻 C
字号:


#include "probe_main.h"



connect_node *  compare_node( connect_node_head  *hash_table , packet_t  * packet)
{
	u_int32_t key = 0;
	connect_node * tmp_pt = NULL;
	
	key = packet->source_ip + packet->target_ip + packet->sport + packet->dport;
	key = key & 0xFFFFF;
	tmp_pt = hash_table[key].first;

	while(tmp_pt != NULL)
	{
		if( tmp_pt->sip == packet->source_ip && tmp_pt->dip == packet->target_ip && tmp_pt->sport == packet->sport && tmp_pt->dport == packet->dport)
		{
			if(tmp_pt->protocol == packet->protocol_type)
			{
				
				return tmp_pt;
			}
			else 
				tmp_pt = tmp_pt->next;
		}
		else if( tmp_pt->sip == packet->target_ip && tmp_pt->dip == packet->source_ip && tmp_pt->sport == packet->dport && tmp_pt->dport == packet->sport)
		{
			if(tmp_pt->protocol == packet->protocol_type)
			{
				return tmp_pt;
			}
			else 
				tmp_pt = tmp_pt->next;
		}
		else 
			tmp_pt = tmp_pt->next;

	}
	return NULL;
}


connect_node * insert_node(connect_node_head  *hash_table, packet_t  *packet)
{
	connect_node *node = (connect_node *)malloc(sizeof(connect_node));
	if(node == NULL)
		return NULL;

	memset(node , 0 , sizeof(connect_node));
	node->sip = packet->source_ip;
	node->dip = packet->target_ip;
	node->sport = packet->sport;
	node->dport = packet->dport;
	node->protocol = packet->protocol_type;

	u_int32_t key = packet->source_ip + packet->target_ip + packet->sport + packet->dport;
	key = key & 0xFFFFF;

	if(hash_table[key].first == NULL)
	{
		hash_table[key].first = node;
		hash_table[key].tail = node;
		node->next = NULL;
	}
	else
	{
		node->next = hash_table[key].first;
		hash_table[key].first->prev = node ;
		hash_table[key].first = node;
		node->next = NULL;
	}
	
	return node;
}

int remove_node(connect_node_head  *hash_table , connect_node * node , packet_t *packet)
{
	u_int32_t key;

	if(node->prev == NULL && node->next == NULL)
	{
		key = packet->source_ip + packet->target_ip + packet->sport + packet->dport;
		key = key & 0xFFFFF;
		hash_table[key].first = NULL;
		hash_table[key].tail = NULL;
	}
	else if(node->prev == NULL && node->next != NULL)
	{
		key = packet->source_ip + packet->target_ip + packet->sport + packet->dport;
		key = key & 0xFFFFF;
		hash_table[key].first = node->next;
		node->next->prev = NULL;
	}
	else if(node->next == NULL && node->prev != NULL)
	{
		node->prev->next = NULL;
	}
	else
	{
		node->prev->next = node->next;
		node->next->prev = node->prev;
	}

	
	free(node);
	return 0;
}


connect_node * compare_consult_node(connect_node_head  *hash_consult_table , packet_t * packet )
{
	
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -