?? p_dispatch.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 + -