Commit 702b202a authored by Stig Venaas's avatar Stig Venaas
Browse files

changed to not include link header in bytecount (only length of IP packet),...

changed to not include link header in bytecount (only length of IP packet), now passing only IP packet to extract_field

git-svn-id: file:///home/svn/mapi/trunk@808 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 7f242751
......@@ -64,41 +64,29 @@ static int topx_reset(mapidflib_function_instance_t *instance)
return 0;
}
void extract_field(unsigned int link_type, struct topx_field *field, unsigned char *dev_pkt,int protocol, int pfield);
void extract_field(struct topx_field *field, unsigned char *ip_pkt, int protocol, int pfield);
struct topx_hash_node *hash_lookup(unsigned int value,struct topx_data *data);
void check_for_shift(struct topx_data *data,struct topx_list_node *node);
void add_to_hashtable_and_list(struct topx_data *data,unsigned int value,unsigned long long bytes, unsigned int last_rst);
void add_field_to_list(struct topx_field *field,struct topx_data *data,unsigned long long bytes,unsigned int last_rst);
void extract_field(unsigned int link_type, struct topx_field *field, unsigned char *dev_pkt,int protocol, int pfield) {
void extract_field(struct topx_field *field, unsigned char *ip_pkt, int protocol, int pfield) {
ether_header* eth = NULL;
ip_header* ip = NULL;
ip_header* ip;
struct ip6_hdr *ip6;
uint8_t ip_ver;
tcp_header* tcp = NULL;
udp_header* udp = NULL;
int ether_len = 0, ip_len = 0;
if (link_type == DLT_EN10MB) /* ethernet */ {
eth = (ether_header*)dev_pkt;
ether_len = sizeof(ether_header);
} else if (link_type == DLT_CHDLC){
ether_len = CHDLC_HDRLEN;
} else {
assert(0);
}
int ip_len;
tcp_header* tcp;
udp_header* udp;
field->len = 0;
ip = (ip_header*)(dev_pkt + ether_len);
ip = (ip_header *)ip_pkt;
ip_ver = ip->ver_ihl >> 4;
if (ip_ver == 4)
ip_len = (ip->ver_ihl & 0xf) * 4;
else if (ip_ver == 6)
ip6 = (struct ip6_hdr *)ip;
ip6 = (struct ip6_hdr *)ip_pkt;
else
return; /* Only support versions 4 and 6 */
......@@ -166,7 +154,7 @@ void extract_field(unsigned int link_type, struct topx_field *field, unsigned ch
case TOPX_TCP:
if (ip->ptcl != IPPROTO_TCP) /* no TCP packet */
return;
tcp = (tcp_header*)(dev_pkt + ether_len + ip_len);
tcp = (tcp_header*)(ip_pkt + ip_len);
//tcp_len = tcp->off * 4;
switch(pfield) {
case TOPX_TCP_SRCPORT:
......@@ -208,7 +196,7 @@ void extract_field(unsigned int link_type, struct topx_field *field, unsigned ch
case TOPX_UDP:
if (ip->ptcl != IPPROTO_UDP) /* no UDP packet */
return;
udp = (udp_header *)(dev_pkt + ether_len + ip_len);
udp = (udp_header *)(ip_pkt + ip_len);
switch(pfield) {
case TOPX_UDP_SRCPORT:
field->pointer=&(udp->sport);
......@@ -368,8 +356,20 @@ static int topx_process(mapidflib_function_instance_t *instance,
// struct timeval ts;
unsigned int cur_secs = 0;
struct timeval tv;
int ether_len;
switch (instance->hwinfo->link_type) {
case DLT_EN10MB: /* ethernet */
ether_len = sizeof(ether_header);
break;
case DLT_CHDLC:
ether_len = CHDLC_HDRLEN;
break;
default:
assert(0);
}
extract_field(instance->hwinfo->link_type,&field,packet,data->protocol,data->field);
extract_field(&field, packet + ether_len, data->protocol, data->field);
if(field.len==0)
return 1;
......@@ -399,7 +399,7 @@ static int topx_process(mapidflib_function_instance_t *instance,
}
//printf("---- %lf\n",(double)(pkt_head->wlen));
add_field_to_list(&field,data,(unsigned long long)(pkt_head->wlen), data->last_rst);
add_field_to_list(&field,data,(unsigned long long)(pkt_head->wlen - ether_len), data->last_rst);
tmp=data->list_head;
ptr=(unsigned int *)(instance->result.data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment