Changeset 1146


Ignore:
Timestamp:
02/22/07 10:39:30 (6 years ago)
Author:
spa1
Message:

Removed some hard-coded numbers and generally tidied up the tcp option counting code - nothing too major going on here

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/tracereport/tcpopt_report.c

    r1144 r1146  
    77 
    88static stat_t tcpopt_stat[4][256] = {{{0,0}}}; 
     9/* Suppressing things seems a little pointless to me */ 
    910static bool suppress[4] = {true,true,true,true}; 
    1011 
    1112void tcpopt_per_packet(struct libtrace_packet_t *packet) 
    1213{ 
    13         unsigned char *p=trace_get_link(packet); 
    1414        struct libtrace_tcp *tcp = trace_get_tcp(packet); 
     15        unsigned char *opt_ptr; 
     16        libtrace_direction_t dir = trace_get_direction(packet); 
     17        int tcp_payload, len; 
     18        unsigned char type, optlen, *data; 
    1519         
    1620        if(!tcp) 
    1721                return; 
    1822         
    19         int dir = trace_get_direction(packet); 
    20         if(dir < 0 || dir > 1) 
    21                 dir = 2; 
     23        if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING) 
     24                dir = TRACE_DIR_OTHER; 
    2225         
    23         int len = trace_get_capture_length(packet) - 54; 
     26        len = tcp->doff * 4 - sizeof(libtrace_tcp_t); 
    2427        if(len == 0) 
    2528                return; 
    2629         
    27         int tcp_bytes = trace_get_wire_length(packet) - trace_get_capture_length(packet); 
    28         int i = tcp->doff*4 - sizeof *tcp; 
     30        tcp_payload = trace_get_wire_length(packet) - trace_get_capture_length(packet); 
    2931         
    30         if(len > i) 
    31                 len = i; 
     32        opt_ptr = (unsigned char *)tcp + sizeof (libtrace_tcp_t); 
    3233         
    33         unsigned char type,optlen,*data; 
    34         p += 54; //hax 14 mac header, 20 ip header, 20tcp header 
    35          
    36         while(trace_get_next_option(&p,&len,&type,&optlen,&data)){ 
     34        while(trace_get_next_option(&opt_ptr,&len,&type,&optlen,&data)){ 
     35                /* I don't think we need to count NO-OPs */ 
     36                if (type == 1) 
     37                        continue; 
    3738                tcpopt_stat[dir][type].count++; 
    38                 tcpopt_stat[dir][type].bytes+= tcp_bytes; 
     39                tcpopt_stat[dir][type].bytes+= tcp_payload; 
    3940        } 
    4041         
Note: See TracChangeset for help on using the changeset viewer.