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

📄 p_dispatch.c

📁 LInux BootLoader的说明文档
💻 C
字号:
#include "probe_main.h"
#include <assert.h>

extern u_int32_t total;
extern u_int32_t free_num;

//static int packet_dispatch(pthread_infor_t ** pthread , port_array_t* port , const  u_char * raw_packet , u_int32_t packet_len , time_t tm , unsigned long handle);



/*把到来的数据包按功能丢进不同的缓冲区*/
static int packet_dispatch(pthread_infor_t ** pthread , port_array_t* port , const  u_char * raw_packet , u_int32_t packet_len , time_t tm , unsigned long handle)
{
	packet_t *p = NULL;
	unsigned char  validate = 0 ;
	port_t *tmp = NULL;

//	printf("packet_dispatch  \n\n");
	


	u_int32_t  i = 0;

	p = _pbuffer_packet_validate(raw_packet , packet_len, tm , (unsigned char *)(&validate));
	
	if(p == NULL)
	{
		return -1;
	}
	//printf("p port is %d  \n" , p->sport);
	total++;
	p->handle = handle;

	if(p->protocol_type == TCP_TYPE)
	{
		if(port[p->sport].headt != NULL)
		{
			kfifo_put( port[p->sport].headt->fifo, (unsigned char *)(&p) , 4);
			tmp = port[p->sport].headt->next;
			while(tmp != NULL)
			{
				packet_t *packet = NULL;
				if((packet = malloc(p->size) )==NULL)
					return -1;

				memcpy(packet , p , p->size);

				packet->trans_data = (u_int8_t *)packet + sizeof(packet_t);
				packet->app_data = packet->trans_data + (p->app_data - p->trans_data);
				//_pbuffer_insert_packet( tmp->pbuf ,  packet);
				kfifo_put(tmp->fifo , (unsigned char *)(&packet) , 4) ;
				tmp = tmp->next;
			}
		}
		else if(port[p->dport].headt != NULL)
		{
			assert(port[p->dport].headt->fifo ) ;
			//_pbuffer_insert_packet( port[p->dport].headt->pbuf ,  p);
			kfifo_put( port[p->dport].headt->fifo , (unsigned char *)(&p) , 4);
			tmp = port[p->dport].headt->next;
			while(tmp != NULL)
			{
				packet_t *packet = NULL;
				if((packet = malloc(p->size)) ==NULL)
					return -1;

				memcpy(packet , p , p->size);	
				packet->trans_data = (u_int8_t *)packet + sizeof(packet_t);
				packet->app_data = packet->trans_data + (p->app_data - p->trans_data);
				//_pbuffer_insert_packet( tmp->pbuf ,  packet);
				kfifo_put(tmp->fifo, (unsigned char *)(&packet) , 4);
				tmp = tmp->next;
			}
		}
		else
		{
			free_num++;
			free(p);
		}
	}
	else
	{
		if(port[p->sport].headu != NULL)
		{
			//_pbuffer_insert_packet( port[p->sport].headu->pbuf ,  p);
			kfifo_put( port[p->sport].headu->fifo, (unsigned char *)(&p) , 4);
			tmp = port[p->sport].headu->next;
			while(tmp != NULL)
			{
				packet_t *packet = NULL;
				if((packet = malloc(p->size)) ==NULL)
					return -1;

				memcpy(packet , p , p->size);	
				packet->trans_data = (u_int8_t *)packet + sizeof(packet_t);
				packet->app_data = packet->trans_data + (p->app_data - p->trans_data);
				//_pbuffer_insert_packet( tmp->pbuf ,  packet);
				kfifo_put( tmp->fifo, (unsigned char *)(&packet) , 4);
				tmp = tmp->next;
			}
		}
		else if(port[p->dport].headu != NULL)
		{
			assert(port[p->dport].headu->fifo ) ;
			//_pbuffer_insert_packet( port[p->dport].headu->pbuf ,  p);
			kfifo_put( port[p->dport].headu->fifo, (unsigned char *)(&p) , 4);
			tmp = port[p->dport].headu->next;
			while(tmp != NULL)
			{
				packet_t *packet = NULL;
				if((packet = malloc(p->size)) ==NULL)
					return -1;

				memcpy(packet , p , p->size);
				packet->trans_data = (u_int8_t *)packet + sizeof(packet_t);
				packet->app_data = packet->trans_data + (p->app_data - p->trans_data);
				//_pbuffer_insert_packet( tmp->pbuf ,  packet);
				kfifo_put( tmp->fifo, (unsigned char *)(&packet) , 4);
				tmp = tmp->next;
			}
		}
		else
		{
			free_num++;
			free(p);
		}
	}
	return 0;
}

⌨️ 快捷键说明

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