From Ivan Lawrow: Added IEEE 802.15.4-2003 AES-CCM security modes
[obnox/wireshark/wip.git] / tap-comparestat.c
index 1634db75515f317423aa34eaae43704356d5d78b..81b063b2d92b82d0e176e79b8686dcb98cca8231 100644 (file)
@@ -1,24 +1,24 @@
 /* tap-comparestat.c
  * Compare two capture files
  * Copyright 2008 Vincenzo Condoleo, Christophe Dirac, Reto Ruoss
- * supported by HSR (Hochschule Rapperswil) 
+ * supported by HSR (Hochschule Rapperswil)
  *
  * $Id$
  *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
@@ -51,7 +51,6 @@
 #include <epan/timestamp.h>
 #include <epan/stat_cmd_args.h>
 #include <epan/dissectors/packet-ip.h>
-#include "register.h"
 #include "timestats.h"
 
 
@@ -121,7 +120,7 @@ comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
        frame_info *fInfo;
        vec_t cksum_vec[3];
        guint16 computed_cksum=0;
-       
+
        /* so this get filled, usually with the first frame */
        if(cs->eth_dst.len==0) {
                cs->eth_dst=pinfo->dl_dst;
@@ -173,7 +172,7 @@ call_foreach_count_ip_id(gpointer value, gpointer arg)
        packet_info *pinfo=(packet_info*)ep_alloc(sizeof(packet_info));
        pinfo->fd=(frame_data*)ep_alloc(sizeof(frame_data));
        pinfo->fd->num = fInfo->num;
-       
+
        fInfoTemp=se_tree_lookup32(cs->ip_id_tree, fInfo->id);
        if(fInfoTemp==NULL){
                /* Detect ongoing package loss */
@@ -257,7 +256,7 @@ call_foreach_new_order(gpointer value, gpointer arg)
                                cs->zebra_time.nsecs++;
                                se_tree_insert32(cs->nr_tree, fInfo->id, fInfo);
                                fInfo->zebra_time=cs->zebra_time;
-                               cs->zebra_time.nsecs=cs->zebra_time.nsecs++;
+                               cs->zebra_time.nsecs++;
                        }
                } else {
                        if((g_array_index(cs->ip_ttl_list, guint8, 0)==fInfo->ip_ttl) || (g_array_index(cs->ip_ttl_list, guint8, 1)==fInfo->ip_ttl)){
@@ -268,9 +267,9 @@ call_foreach_new_order(gpointer value, gpointer arg)
                                cs->zebra_time.nsecs++;
                                se_tree_insert32(cs->nr_tree, fInfo->id, fInfo);
                                fInfo->zebra_time=cs->zebra_time;
-                               cs->zebra_time.nsecs=cs->zebra_time.nsecs++;
+                               cs->zebra_time.nsecs++;
                        }
-                       
+
                }
        } else {
                if(TTL_method==FALSE){
@@ -285,9 +284,9 @@ call_foreach_new_order(gpointer value, gpointer arg)
                        } else {
                                fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs+1;
                        }
-               }       
+               }
        }
-       
+
        /* count packets of file */
        if(fmod(fInfo->zebra_time.nsecs, MERGED_FILES)){
                cs->first_file_amount++;
@@ -299,7 +298,7 @@ call_foreach_new_order(gpointer value, gpointer arg)
        if(!nstime_is_unset(&cs->current_time)){
                fInfo->fp->predecessor_time.nsecs=cs->current_time.nsecs;
        }
-       
+
        cs->current_time.nsecs=fInfo->zebra_time.nsecs;
 
        return FALSE;
@@ -324,6 +323,7 @@ call_foreach_merge_settings(gpointer value, gpointer arg)
                fInfoTemp=se_tree_lookup32(cs->packet_tree, cs->start_packet_nr_first);
                if(fInfoTemp==NULL){
                        printf("ERROR: start number not set correctly\n");
+                       return FALSE;
                }
                if(fmod(fInfoTemp->zebra_time.nsecs, 2)){
                        /*first file*/
@@ -402,7 +402,7 @@ call_foreach_print_ip_tree(gpointer value, gpointer user_data)
                }
                if(fInfo->fp->count > MERGED_FILES){
                        printf("Packet id :%i, count:%i Problem:", fInfo->id, fInfo->fp->count);
-                       printf("More than two packets\n"); 
+                       printf("More than two packets\n");
                        if(fInfo->fp->cksum == WRONG_CHKSUM){
                                printf("Checksum error over IP header\n");
                        }
@@ -426,7 +426,7 @@ call_foreach_print_ip_tree(gpointer value, gpointer user_data)
                        } else if((nstime_cmp(&fInfo->fp->predecessor_time, &fInfo->zebra_time)>0||nstime_cmp(&fInfo->fp->partner->fp->predecessor_time, &fInfo->fp->partner->zebra_time)>0) && fInfo->zebra_time.nsecs != MERGED_FILES && ON_method){
                                printf("Packet id :%i, count:%i Problem:", fInfo->id, fInfo->fp->count);
                                printf("Not correct order\n");
-                       }       
+                       }
                }
        }
        return FALSE;
@@ -438,7 +438,7 @@ call_foreach_print_ip_tree(gpointer value, gpointer user_data)
  * stdout.
  * TShark will only call this callback once, which is when tshark has
  * finished reading all packets and exists.
- * If used with wireshark this may be called any time, perhaps once every 3 
+ * If used with wireshark this may be called any time, perhaps once every 3
  * seconds or so.
  * This function may even be called in parallell with (*reset) or (*draw)
  * so make sure there are no races. The data in the rpcstat_t can thus change
@@ -490,7 +490,7 @@ comparestat_draw(void *prs)
        cs->stats.variance=compare_variance;
 
        /* add statistic string */
-       statis_string=g_strdup_printf("Compare Statistics: \nNumber of packets total:%i 1st file:%i, 2nd file:%i\nScopes:\t start:%i stop:%i\nand:\t start:%i stop:%i\nEqual packets: %i \nAllowed variation: %f \nAverage time difference: %f\n", (first_file_amount+second_file_amount), first_file_amount, second_file_amount, cs->start_packet_nr_first, cs->stop_packet_nr_first, cs->start_packet_nr_second, cs->stop_packet_nr_second, cs->stats.num, cs->stats.variance, fabs(get_average(&cs->stats.tot, cs->stats.num)));
+       statis_string=g_strdup_printf("Compare Statistics: \nFilter: %s\nNumber of packets total:%i 1st file:%i, 2nd file:%i\nScopes:\t start:%i stop:%i\nand:\t start:%i stop:%i\nEqual packets: %i \nAllowed variation: %f \nAverage time difference: %f\n", cs->filter ? cs->filter : "", (first_file_amount+second_file_amount), first_file_amount, second_file_amount, cs->start_packet_nr_first, cs->stop_packet_nr_first, cs->start_packet_nr_second, cs->stop_packet_nr_second, cs->stats.num, cs->stats.variance, fabs(get_average(&cs->stats.tot, cs->stats.num)));
 
        printf("\n");
        printf("===================================================================\n");
@@ -515,9 +515,12 @@ comparestat_init(const char *optarg, void* userdata _U_)
        gint start, stop,ttl, order, pos=0;
        gdouble variance;
 
-       if(sscanf(optarg,"compare,%d,%d,%d,%d,%lf,%n",&start, &stop, &ttl, &order, &variance, &pos)==5){
+       if(sscanf(optarg,"compare,%d,%d,%d,%d,%lf%n",&start, &stop, &ttl, &order, &variance, &pos)==5){
                if(pos){
-                       filter=optarg+pos;
+                       if(*(optarg+pos)==',')
+                               filter=optarg+pos+1;
+                       else
+                               filter=optarg+pos;
                } else {
                        filter=NULL;
                }
@@ -556,11 +559,11 @@ comparestat_init(const char *optarg, void* userdata _U_)
        } else {
                cs->filter=NULL;
        }
-       
+
        /* create a Hash to count the packets with the same ip.id */
        cs->packet_tree=se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "Packet_info_tree");
 
-       error_string=register_tap_listener("ip", cs, filter, comparestat_reset, comparestat_packet, comparestat_draw);
+       error_string=register_tap_listener("ip", cs, filter, 0, comparestat_reset, comparestat_packet, comparestat_draw);
        if(error_string){
                /* error, we failed to attach to the tap. clean up */
                g_free(cs->filter);