Mark an unused argument.
[obnox/wireshark/wip.git] / gtk / compare_stat.c
1 /* compare_stat.c
2  * Compare two capture files
3  * Copyright 2008 Vincenzo Condoleo, Christophe Dirac, Reto Ruoss
4  * supported by HSR (Hochschule Rapperswil)
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  0F111-1307, USA.
25  */
26
27 /* This module provides statistics about two merged capture files, to find packet loss,
28  * time delay, ip header checksum errors and order check.
29  * It's also detecting the matching regions of the different files.
30  * After the coloring is set Info column can be sorted to create zebra effect.
31  *
32  * The packets are compared by the ip id. MAC or TTL is used to distinct the different files.
33  */
34
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <math.h>
42
43 #include <glib.h>
44 #include <gtk/gtk.h>
45
46 #include <epan/packet_info.h>
47 #include <epan/epan.h>
48 #include <epan/epan_dissect.h>
49 #include <epan/stat_cmd_args.h>
50 #include <epan/to_str.h>
51 #include <epan/tap.h>
52 #include <epan/emem.h>
53 #include <epan/packet.h>
54 #include <epan/report_err.h>
55 #include <epan/dissectors/packet-ip.h>
56 #include <epan/nstime.h>
57 #include <epan/in_cksum.h>
58
59 #include "../stat_menu.h"
60 #include "../simple_dialog.h"
61 #include "../timestats.h"
62
63 #include "gtk/gui_stat_menu.h"
64 #include "gtk/stock_icons.h"
65 #include "gtk/help_dlg.h"
66 #include "gtk/filter_autocomplete.h"
67
68 #include "gui_utils.h"
69 #include "dlg_utils.h"
70 #include "register.h"
71 #include "main.h"
72 #include "filter_dlg.h"
73 #include "service_response_time_table.h"
74 #include "gtkglobals.h"
75 #include "gui_utils.h"
76 #include "globals.h"
77
78 /* Color settings */
79 #include "color.h"
80 #include "color_filters.h"
81 #include "color_dlg.h"
82 #include "new_packet_list.h"
83 /* From colorize convertion */
84 #define COLOR_N 1
85
86 /* For checksum */
87 #define BYTES 8
88 #define WRONG_CHKSUM 0
89
90 #define MERGED_FILES 2
91
92 #define TTL_SEARCH 5
93
94
95
96 /* information which are needed for the display */
97 typedef struct _for_gui {
98         guint count;
99         guint16 cksum;
100         nstime_t predecessor_time;
101         struct _frame_info *partner;
102 } for_gui;
103
104 /* each tracked packet */
105 typedef struct _frame_info {
106         for_gui *fg;
107         column_info *cinfo;
108         guint32 num;
109         guint16 id;
110         guint8 ip_ttl;
111         address dl_dst;
112         nstime_t abs_ts, zebra_time, delta;
113 } frame_info;
114
115 /* used to keep track of the statistics for an entire program interface */
116 typedef struct _compstat_t {
117         GtkWidget *win, *treeview, *scrolled_win, *statis_label;
118         GtkTreeStore *simple_list;
119         GtkTreeIter iter, child;
120         emem_tree_t *packet_tree, *ip_id_tree, *nr_tree;
121         address eth_dst, eth_src;
122         nstime_t zebra_time, current_time;
123         timestat_t stats;
124         GArray *ip_ttl_list;
125         gboolean last_hit;
126         guint32 start_ongoing_hits, stop_ongoing_hits, start_packet_nr_first, start_packet_nr_second, stop_packet_nr_first, stop_packet_nr_second;
127         guint32 first_file_amount, second_file_amount;
128 } compstat_t;
129
130 /* column numbers */
131 enum
132 {
133         IP_ID=0,
134         PROBLEM,
135         COUNT,
136         DELTA,
137         COLUMNS
138 };
139
140 /* only one compare window should be open */
141 static gboolean first_window=TRUE;
142
143 /* allowed variace */
144 static GtkWidget *spin_var_int=NULL;
145
146 /* start/stop compare */
147 static GtkWidget  *spin_start_int, *spin_stop_int;
148
149 /* to call directly _init */
150 static gdouble compare_variance=0.0;
151 static guint8 compare_start, compare_stop;
152 static gboolean TTL_method=TRUE, ON_method=TRUE;
153 static GtkWidget *radio_TTL, *radio_ON;
154
155 static void
156 comparestat_set_title(compstat_t *cs)
157 {
158         char *title;
159
160         title=g_strdup_printf("Compare two capture files: %s", cf_get_display_name(&cfile));
161         gtk_window_set_title(GTK_WINDOW(cs->win), title);
162         g_free(title);
163 }
164
165 /* called when new capture starts, when it rescans the packetlist after some prefs have
166  * changed
167  */
168 static void
169 comparestat_reset(void *arg)
170 {
171         compstat_t *cs=arg;
172
173         SET_ADDRESS(&cs->eth_src, AT_ETHER, 0, NULL);
174         SET_ADDRESS(&cs->eth_dst, AT_ETHER, 0, NULL);
175
176         gtk_tree_store_clear(cs->simple_list);
177         comparestat_set_title(cs);
178 }
179
180 /* This callback is invoked whenever the tap system has seen a packet
181  * we might be interested in.
182  * function returns :
183  *  0: no updates, no need to call (*draw) later
184  * !0: state has changed, call (*draw) sometime later
185  */
186 static int
187 comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *arg2)
188 {
189         compstat_t *cs=arg;
190         const ws_ip *ci=arg2;
191         frame_info *fInfo, *fInfoTemp;
192         vec_t cksum_vec[3];
193         guint16 computed_cksum=0;
194
195         /* so this get filled, usually with the first frame */
196         if(cs->eth_dst.len==0) {
197                 cs->eth_dst=pinfo->dl_dst;
198                 cs->eth_src=pinfo->dl_src;
199         }
200
201         /* Set up the fields of the pseudo-header and create checksum */
202         cksum_vec[0].ptr=&ci->ip_v_hl;
203         cksum_vec[0].len=BYTES;
204         /* skip TTL */
205         cksum_vec[1].ptr=&ci->ip_p;
206         cksum_vec[1].len=1;
207         /* skip header checksum and ip's (because of NAT)*/
208         cksum_vec[2].ptr=ci->ip_dst.data;
209         cksum_vec[2].ptr=cksum_vec[2].ptr+ci->ip_dst.len;
210         /* dynamic computation */
211         cksum_vec[2].len=pinfo->iphdrlen-20;
212         computed_cksum=in_cksum(&cksum_vec[0], 3);
213
214         /* Set up the new order to create the zebra effect */
215         fInfoTemp=se_tree_lookup32(cs->packet_tree, pinfo->fd->num);
216         if((fInfoTemp!=NULL)){
217                 col_set_time(pinfo->cinfo, COL_INFO, &fInfoTemp->zebra_time, "ZebraTime");
218         }
219
220         /* collect all packet infos */
221         fInfo=(frame_info*)se_alloc(sizeof(frame_info));
222         fInfo->fg=(for_gui*)se_alloc(sizeof(for_gui));
223         fInfo->fg->partner=NULL;
224         fInfo->fg->count=1;
225         fInfo->fg->cksum=computed_cksum;
226         fInfo->num=pinfo->fd->num;
227         fInfo->id=ci->ip_id;
228         fInfo->ip_ttl=ci->ip_ttl;
229         fInfo->dl_dst=pinfo->dl_dst;
230         fInfo->abs_ts=pinfo->fd->abs_ts;
231         /* clean memory */
232         nstime_set_zero(&fInfo->zebra_time);
233         nstime_set_zero(&fInfo->fg->predecessor_time);
234         se_tree_insert32(cs->packet_tree, pinfo->fd->num, fInfo);
235
236         if(cf_get_packet_count(&cfile)==abs(fInfo->num)){
237                 nstime_set_unset(&cs->current_time);
238                 return 1;
239         } else {
240                 return 0;
241         }
242 }
243
244 /* Find equal packets, same IP-Id, count them and make time statistics */
245 static gboolean
246 call_foreach_count_ip_id(gpointer value, gpointer arg)
247 {
248         compstat_t *cs=(compstat_t*)arg;
249         frame_info *fInfo=(frame_info*)value, *fInfoTemp;
250         nstime_t delta;
251         guint i;
252
253         /* we only need one value out of pinfo we use a temp one */
254         packet_info *pinfo=(packet_info*)ep_alloc(sizeof(packet_info));
255         pinfo->fd=(frame_data*)ep_alloc(sizeof(frame_data));
256         pinfo->fd->num = fInfo->num;
257
258         fInfoTemp=se_tree_lookup32(cs->ip_id_tree, fInfo->id);
259         if(fInfoTemp==NULL){
260                 /* Detect ongoing package loss */
261                 if((cs->last_hit==FALSE)&&(cs->start_ongoing_hits>compare_start)&&(cs->stop_ongoing_hits<compare_stop)){
262                         cs->stop_ongoing_hits++;
263                         cs->stop_packet_nr_first=fInfo->num;
264                 } else if(cs->stop_ongoing_hits<compare_stop){
265                         cs->stop_ongoing_hits=0;
266                         cs->stop_packet_nr_first=G_MAXINT32;
267                 }
268                 cs->last_hit=FALSE;
269
270                 fInfo->fg->count=1;
271                 se_tree_insert32(cs->ip_id_tree, fInfo->id, fInfo);
272         } else {
273                 /* Detect ongoing package hits, special behavior if start is set to 0 */
274                 if((cs->last_hit||(compare_start==0))&&(cs->start_ongoing_hits<compare_start||(compare_start==0))){
275                         if((compare_start==0)&&(cs->start_ongoing_hits!=0)){
276                                 /* start from the first packet so allready set */
277                         } else {
278                                 cs->start_ongoing_hits++;
279                                 /* Take the lower number */
280                                 cs->start_packet_nr_first=fInfoTemp->num;
281                                 cs->start_packet_nr_second=fInfo->num;
282                         }
283                 } else if(cs->start_ongoing_hits<compare_start){
284                         cs->start_ongoing_hits=0;
285                         cs->start_packet_nr_first=G_MAXINT32;
286                 }
287                 cs->last_hit=TRUE;
288
289                 fInfo->fg->count=fInfoTemp->fg->count + 1;
290                 if(fInfoTemp->fg->cksum!=fInfo->fg->cksum){
291                         fInfo->fg->cksum=WRONG_CHKSUM;
292                         fInfoTemp->fg->cksum=WRONG_CHKSUM;
293                 }
294                 /* Add partner */
295                 fInfo->fg->partner=fInfoTemp;
296                 /* Create time statistic */
297                 if(fInfo->fg->count==MERGED_FILES){
298                         nstime_delta(&delta, &fInfo->abs_ts, &fInfoTemp->abs_ts);
299                         /* Set delta in both packets */
300                         nstime_set_zero(&fInfoTemp->delta);
301                         nstime_add(&fInfoTemp->delta, &delta);
302                         nstime_set_zero(&fInfo->delta);
303                         nstime_add(&fInfo->delta, &delta);
304                         time_stat_update(&cs->stats, &delta, pinfo);
305                 }
306                 se_tree_insert32(cs->ip_id_tree, fInfo->id, fInfo);
307         }
308
309         /* collect TTL's */
310         if(TTL_method && (fInfo->num<TTL_SEARCH)){
311                 for(i=0; i < cs->ip_ttl_list->len; i++){
312                         if(g_array_index(cs->ip_ttl_list, guint8, i) == fInfo->ip_ttl){
313                                 return FALSE;
314                         }
315                 }
316                 g_array_append_val(cs->ip_ttl_list, fInfo->ip_ttl);
317         }
318
319         return FALSE;
320 }
321
322 /*Create new numbering in the Info column, to create a zebra effect */
323 static gboolean
324 call_foreach_new_order(gpointer value, gpointer arg)
325 {
326         compstat_t *cs=(compstat_t*)arg;
327         frame_info *fInfo=(frame_info*)value, *fInfoTemp;
328
329         /* overwrite Info column for new ordering */
330         fInfoTemp=se_tree_lookup32(cs->nr_tree, fInfo->id);
331         if(fInfoTemp==NULL){
332                 if(TTL_method==FALSE){
333                         if((ADDRESSES_EQUAL(&cs->eth_dst, &fInfo->dl_dst)) || (ADDRESSES_EQUAL(&cs->eth_src, &fInfo->dl_dst))){
334                                 se_tree_insert32(cs->nr_tree, fInfo->id, fInfo);
335                                 fInfo->zebra_time=cs->zebra_time;
336                                 cs->zebra_time.nsecs=cs->zebra_time.nsecs + MERGED_FILES;
337                         } else {
338                                 cs->zebra_time.nsecs++;
339                                 se_tree_insert32(cs->nr_tree, fInfo->id, fInfo);
340                                 fInfo->zebra_time=cs->zebra_time;
341                                 cs->zebra_time.nsecs++;
342                         }
343                 } else {
344                         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)){
345                                 se_tree_insert32(cs->nr_tree, fInfo->id, fInfo);
346                                 fInfo->zebra_time=cs->zebra_time;
347                                 cs->zebra_time.nsecs=cs->zebra_time.nsecs + MERGED_FILES;
348                         } else {
349                                 cs->zebra_time.nsecs++;
350                                 se_tree_insert32(cs->nr_tree, fInfo->id, fInfo);
351                                 fInfo->zebra_time=cs->zebra_time;
352                                 cs->zebra_time.nsecs++;
353                         }
354
355                 }
356         } else {
357                 if(TTL_method==FALSE){
358                         if(((ADDRESSES_EQUAL(&cs->eth_dst, &fInfo->dl_dst)) || (ADDRESSES_EQUAL(&cs->eth_src, &fInfo->dl_dst)))&&(!fmod(fInfoTemp->zebra_time.nsecs,MERGED_FILES))){
359                                 fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs;
360                         } else {
361                                 fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs+1;
362                         }
363                 } else {
364                         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))&&(!fmod(fInfoTemp->zebra_time.nsecs,MERGED_FILES))){
365                                 fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs;
366                         } else {
367                                 fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs+1;
368                         }
369                 }
370         }
371
372         /* count packets of file */
373         if(fmod(fInfo->zebra_time.nsecs, MERGED_FILES)){
374                 cs->first_file_amount++;
375         } else {
376                 cs->second_file_amount++;
377         }
378
379         /* ordering */
380         if(!nstime_is_unset(&cs->current_time)){
381                 fInfo->fg->predecessor_time.nsecs=cs->current_time.nsecs;
382         }
383
384         cs->current_time.nsecs=fInfo->zebra_time.nsecs;
385
386         return FALSE;
387 }
388
389 /* calculate scopes if not set yet */
390 static gboolean
391 call_foreach_merge_settings(gpointer value, gpointer arg)
392 {
393         compstat_t *cs=(compstat_t*)arg;
394         frame_info *fInfo=(frame_info*)value, *fInfoTemp=NULL;
395         guint32 tot_packet_amount=cs->first_file_amount+cs->second_file_amount, swap;
396
397         if((fInfo->num==tot_packet_amount)&&(cs->stop_packet_nr_first!=G_MAXINT32)){
398                 /* calculate missing stop number */
399                 swap=cs->stop_packet_nr_first;
400                 cs->stop_packet_nr_first=tot_packet_amount-cs->second_file_amount;;
401                 cs->stop_packet_nr_second=swap;
402         }
403
404         if((fInfo->num==tot_packet_amount)&&(cs->stop_packet_nr_first==G_MAXINT32)&&(cs->start_packet_nr_first!=G_MAXINT32)){
405                 fInfoTemp=se_tree_lookup32(cs->packet_tree, cs->start_packet_nr_first);
406                 if(fInfoTemp==NULL){
407                         fprintf(stderr,"ERROR: Incorrect start number\n");
408                 }
409                 if(fInfoTemp && fmod(fInfoTemp->zebra_time.nsecs, 2)){
410                         /*first file*/
411                         cs->stop_packet_nr_first=cs->start_packet_nr_first+abs(cs->second_file_amount-(cs->start_packet_nr_second-cs->first_file_amount));
412                         if(cs->stop_packet_nr_first>(tot_packet_amount-cs->second_file_amount)){
413                                 cs->stop_packet_nr_first=tot_packet_amount-cs->second_file_amount;
414                         }
415                         /*this only happens if we have too many MAC's or TTL*/
416                         if(cs->stop_packet_nr_first>cs->start_packet_nr_second){
417                                 cs->stop_packet_nr_first=cs->start_packet_nr_second-1;
418                         }
419                         fInfoTemp=se_tree_lookup32(cs->packet_tree, cs->stop_packet_nr_first);
420                         while((fInfoTemp!=NULL)?fmod(!fInfoTemp->zebra_time.nsecs, 2):TRUE){
421                                 cs->stop_packet_nr_first--;
422                                 fInfoTemp=se_tree_lookup32(cs->packet_tree, cs->stop_packet_nr_first);
423                         }
424                 } else {
425                         /*this only happens if we have too many MAC's or TTL*/
426                         cs->stop_packet_nr_first=cs->first_file_amount+cs->start_packet_nr_first;
427                         if(cs->stop_packet_nr_first>tot_packet_amount-cs->first_file_amount){
428                                 cs->stop_packet_nr_first=tot_packet_amount-cs->first_file_amount;
429                         }
430                         fInfoTemp=se_tree_lookup32(cs->packet_tree, cs->stop_packet_nr_first);
431                         while((fInfoTemp!=NULL)?fmod(fInfoTemp->zebra_time.nsecs, 2):TRUE){
432                                 cs->stop_packet_nr_first--;
433                                 fInfoTemp=se_tree_lookup32(cs->packet_tree, cs->stop_packet_nr_first);
434                         }
435                 }
436                 /* set second stop location */
437                 cs->stop_packet_nr_second=cs->start_packet_nr_second+abs(cs->stop_packet_nr_first-cs->start_packet_nr_first);
438                 if(cs->stop_packet_nr_second>tot_packet_amount){
439                         cs->stop_packet_nr_second=tot_packet_amount;
440                 }
441         }
442
443         /* no start found */
444         if(fInfo->num==tot_packet_amount&&compare_start!=0&&compare_stop!=0){
445                 if(cs->start_packet_nr_first==G_MAXINT32){
446                         report_failure("Start point couldn't be set. Please choose a lower start number.");
447                 }
448         }
449
450         return FALSE;
451 }
452
453
454 /* build gtk-tree of lost, delayed, checksum error and wrong order Packets*/
455 static gboolean
456 call_foreach_print_ip_tree(gpointer value, gpointer user_data)
457 {
458         frame_info *fInfo=(frame_info*)value;
459         compstat_t *cs=(compstat_t*)user_data;
460         gdouble delta, average;
461         gboolean show_it=FALSE;
462
463         delta=fabs(get_average(&fInfo->delta,1));
464         average=fabs(get_average(&cs->stats.tot, cs->stats.num));
465
466         /* special case if both are set to zero ignore start and stop numbering */
467         if(compare_start!=0&&compare_stop!=0){
468                 /* check out if packet is in searched scope */
469                 if((cs->start_packet_nr_first<fInfo->num)&&(cs->stop_packet_nr_first>fInfo->num)){
470                         show_it=TRUE;
471                 } else {
472                         /* so we won't miss the other file */
473                         if((fInfo->num>cs->start_packet_nr_second)&&(fInfo->num<cs->stop_packet_nr_second)){
474                                 show_it=TRUE;
475                         }
476                 }
477         } else {
478                 show_it=TRUE;
479         }
480
481         /* Create the gtk tree */
482         if(show_it){
483                 if((fInfo->fg->count<MERGED_FILES)){
484                         gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, NULL);
485                         gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, IP_ID, fInfo->id, PROBLEM, "Lost packet", COUNT, fInfo->fg->count, DELTA, 0.0, -1);
486                 }
487
488                 if(fInfo->fg->count > MERGED_FILES){
489                         gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, NULL);
490                         gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, IP_ID, fInfo->id, PROBLEM, "More than two packets", COUNT, fInfo->fg->count, DELTA, 0.0, -1);
491                         if(fInfo->fg->cksum == WRONG_CHKSUM) {
492                                 gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, &cs->iter);
493                                 gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, IP_ID, fInfo->id, PROBLEM, "IP header checksum incorrect", COUNT, fInfo->fg->count, DELTA, 0.0, -1);
494                         }
495                 }
496                 if(fInfo->fg->count == MERGED_FILES){
497                         if(fInfo->fg->cksum == WRONG_CHKSUM) {
498                                 gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, NULL);
499                                 gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, IP_ID, fInfo->id, PROBLEM, "IP header checksum incorrect", COUNT, fInfo->fg->count, DELTA, delta, -1);
500                                 if(((delta < (average-cs->stats.variance)) || (delta > (average+cs->stats.variance))) && (delta > 0.0) && (cs->stats.variance!=0)){
501                                         gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, &cs->iter);
502                                         gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, IP_ID, fInfo->id, PROBLEM, "Late arrival", COUNT, fInfo->fg->count, DELTA, delta, -1);
503                                 }
504                                 if((nstime_cmp(&fInfo->fg->predecessor_time, &fInfo->zebra_time)>0||nstime_cmp(&fInfo->fg->partner->fg->predecessor_time, &fInfo->fg->partner->zebra_time)>0) && (fInfo->zebra_time.nsecs!=MERGED_FILES) && ON_method){
505                                         gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, &cs->iter);
506                                         gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, IP_ID, fInfo->id, PROBLEM, "Out of order", COUNT, fInfo->fg->count, DELTA, delta, -1);
507                                 }
508                         } else if(((delta < (average-cs->stats.variance)) || (delta > (average+cs->stats.variance))) && (delta > 0.0) && (cs->stats.variance!=0)) {
509                                 gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, NULL);
510                                 gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, IP_ID, fInfo->id, PROBLEM, "Late arrival", COUNT, fInfo->fg->count, DELTA, delta, -1);
511                                 if((nstime_cmp(&fInfo->fg->predecessor_time, &fInfo->zebra_time)>0||nstime_cmp(&fInfo->fg->partner->fg->predecessor_time, &fInfo->fg->partner->zebra_time)>0) && fInfo->zebra_time.nsecs != MERGED_FILES && ON_method){
512                                         gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, &cs->iter);
513                                         gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->child, IP_ID, fInfo->id, PROBLEM, "Out of order", COUNT, fInfo->fg->count, DELTA, delta, -1);
514                                 }
515                         } else if((nstime_cmp(&fInfo->fg->predecessor_time, &fInfo->zebra_time)>0||nstime_cmp(&fInfo->fg->partner->fg->predecessor_time, &fInfo->fg->partner->zebra_time)>0) && fInfo->zebra_time.nsecs != MERGED_FILES && ON_method){
516                                 gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, NULL);
517                                 gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, IP_ID, fInfo->id, PROBLEM, "Out of order", COUNT, fInfo->fg->count, DELTA, delta, -1);
518                         }
519                 }
520         }
521         return FALSE;
522 }
523
524 /* since the gtk2 implementation of tap is multithreaded we must protect
525  * remove_tap_listener() from modifying the list while draw_tap_listener()
526  * is running.  the other protected block is in main.c
527  *
528  * there should not be any other critical regions in gtk2
529  */
530 static void
531 win_destroy_cb(GtkWindow *win _U_, gpointer data)
532 {
533         compstat_t *cs=(compstat_t *)data;
534
535         protect_thread_critical_region();
536         remove_tap_listener(cs);
537         unprotect_thread_critical_region();
538
539         first_window=TRUE;
540         gtk_tree_store_clear(cs->simple_list);
541         g_free(cs);
542 }
543
544 /* this may be called any time, perhaps once every 3 seconds or so.
545  */
546 static void
547 comparestat_draw(void *arg)
548 {
549         compstat_t *cs = arg;
550         GString *filter_str = g_string_new("");
551         const gchar *statis_string;
552         frame_info *fInfo;
553         guint32 first_file_amount, second_file_amount;
554
555         /* inital steps, clear all data before start*/
556         cs->zebra_time.secs=0;
557         cs->zebra_time.nsecs=1;
558         nstime_set_unset(&cs->current_time);
559         cs->ip_ttl_list=g_array_new(FALSE, FALSE, sizeof(guint8));
560         cs->last_hit=FALSE;
561         cs->start_ongoing_hits=0;
562         cs->stop_ongoing_hits=0;
563         cs->start_packet_nr_first=G_MAXINT32;
564         cs->start_packet_nr_second=G_MAXINT32;
565         cs->stop_packet_nr_first=G_MAXINT32;
566         cs->stop_packet_nr_second=G_MAXINT32;
567         cs->first_file_amount=0;
568         cs->second_file_amount=0;
569
570         time_stat_init(&cs->stats);
571
572         /* no need to do anything no file is open*/
573         if(cf_get_packet_count(&cfile)==0){
574                 /* add statistic string */
575                 statis_string=g_strdup_printf("No file open");
576                 gtk_label_set_text((GtkLabel *) cs->statis_label, statis_string);
577                 return;
578         }
579
580         /* not using g_free, because struct is managed by se binarytrees */
581         cs->ip_id_tree=se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "ip_id_tree");
582         emem_tree_foreach(cs->packet_tree, call_foreach_count_ip_id, cs);
583
584         /* set up TTL choice if only one number found */
585         if(TTL_method&&cs->ip_ttl_list->len==1){
586                 g_array_append_val(cs->ip_ttl_list, g_array_index(cs->ip_ttl_list, guint8, 1));
587         }
588
589         emem_tree_foreach(cs->packet_tree, call_foreach_new_order,cs);
590         emem_tree_foreach(cs->packet_tree, call_foreach_merge_settings, cs);
591
592         /* remembering file amounts */
593         first_file_amount=cs->first_file_amount;
594         second_file_amount=cs->second_file_amount;
595         /* reset after numbering */
596         cs->nr_tree=se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "nr_tree");
597         /* microsecond precision for Info column*/
598         timestamp_set_precision(TS_PREC_AUTO_NSEC);
599         /* reset ordering */
600         nstime_set_unset(&cs->current_time);
601
602         /* set color filter, in Routing environment */
603         if(TTL_method&&cs->ip_ttl_list->len!=0){
604                 g_string_printf(filter_str, "%s %i %s %i", "ip.ttl ==", g_array_index(cs->ip_ttl_list, guint8, 0), "|| ip.ttl ==", g_array_index(cs->ip_ttl_list, guint8, 1));
605         } else if(cs->eth_dst.len!=0&&cs->eth_src.len!=0){
606                 g_string_printf(filter_str, "%s %s %s %s", "eth.dst==", ep_address_to_str(&cs->eth_dst), "|| eth.dst==", ep_address_to_str(&cs->eth_src));
607         }
608         color_filters_set_tmp(COLOR_N, filter_str->str, FALSE);
609         new_packet_list_colorize_packets();
610         /* Variance */
611         cs->stats.variance=compare_variance;
612
613         /* add statistic string */
614         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", cf_get_packet_count(&cfile), 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)));
615         gtk_label_set_text((GtkLabel *) cs->statis_label, statis_string);
616
617         /* add start and stop of scanning */
618         if(cs->start_packet_nr_first!=G_MAXINT32&&compare_start!=0&&compare_stop!=0){
619                 fInfo=se_tree_lookup32(cs->packet_tree, cs->start_packet_nr_first);
620                 if(fInfo){
621                         gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, NULL);
622                         gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, IP_ID, fInfo->id, PROBLEM, "Start scanning", COUNT, 0, DELTA, 0.0, -1);
623                 }
624         }
625         if(cs->stop_packet_nr_first!=G_MAXINT32&&compare_start!=0&&compare_stop!=0){
626                 fInfo=se_tree_lookup32(cs->packet_tree, cs->stop_packet_nr_first);
627                 if(fInfo){
628                         gtk_tree_store_append(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, NULL);
629                         gtk_tree_store_set(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cs->treeview))), &cs->iter, IP_ID, fInfo->id, PROBLEM, "Stop scanning", COUNT, 0, DELTA, 0.0, -1);
630                 }
631         }
632
633         emem_tree_foreach(cs->ip_id_tree, call_foreach_print_ip_tree, cs);
634         g_string_free(filter_str, TRUE);
635         g_array_free(cs->ip_ttl_list, TRUE);
636 }
637
638 /* called when a tree row is (un)selected in the popup window */
639 static void
640 new_tree_view_selection_changed(GtkTreeSelection *sel, gpointer user_data)
641 {
642         gchar *problem;
643         GtkTreeModel *model;
644         GtkTreeIter iter;
645         frame_info *fInfo;
646         /* Because it could be zero */
647         gint id=-1;
648
649         compstat_t *cs=(compstat_t*)user_data;
650
651         /* if something is selected */
652         if(gtk_tree_selection_get_selected(sel, &model, &iter)){
653                 gtk_tree_model_get(model, &iter, 0, &id, 1, &problem, -1);
654                 if (id<0) return;
655                 /* The id is not enough to find the start or the end packet */
656                 if(strcmp("Start scanning",problem)==0){
657                         cf_goto_frame(&cfile, cs->start_packet_nr_first);
658                         return;
659                 }
660                 if(strcmp("Stop scanning",problem)==0){
661                         cf_goto_frame(&cfile, cs->stop_packet_nr_first);
662                         return;
663                 }
664                 fInfo=se_tree_lookup32(cs->ip_id_tree, id);
665                 if(fInfo != NULL){
666                         cf_goto_frame(&cfile, fInfo->num);
667                 }
668         }
669
670 }
671
672 /* add three columns to the GtkTreeView. All three of the columns will be
673  * displayed as text*/
674 static void
675 setup_tree_view(GtkWidget *treeview)
676 {
677         GtkCellRenderer *renderer;
678         GtkTreeViewColumn *column;
679         /* Create a new GtkCellRendererText, add it to the tree view column and
680          * append the column to the tree view. */
681         renderer=gtk_cell_renderer_text_new ();
682         column=gtk_tree_view_column_new_with_attributes("IP ID", renderer, "text", IP_ID, NULL);
683         gtk_tree_view_append_column(GTK_TREE_VIEW (treeview), column);
684         renderer=gtk_cell_renderer_text_new ();
685         column=gtk_tree_view_column_new_with_attributes("Problem", renderer, "text", PROBLEM, NULL);
686         gtk_tree_view_append_column(GTK_TREE_VIEW (treeview), column);
687         renderer=gtk_cell_renderer_text_new ();
688         column=gtk_tree_view_column_new_with_attributes("Count", renderer, "text", COUNT, NULL);
689         gtk_tree_view_append_column(GTK_TREE_VIEW (treeview), column);
690         renderer=gtk_cell_renderer_text_new ();
691         column=gtk_tree_view_column_new_with_attributes("Delta", renderer, "text", DELTA, NULL);
692         gtk_tree_view_append_column(GTK_TREE_VIEW (treeview), column);
693 }
694
695 /* when called, this function will create a new instance of gtk2-comparestat.
696  */
697 static void
698 gtk_comparestat_init(const char *optarg, void* userdata _U_)
699 {
700         compstat_t *cs;
701         char *title_string;
702         char *filter_string;
703         GtkWidget *stat_label;
704         GtkWidget *filter_label;
705         GtkWidget *bbox;
706         GtkWidget *close_bt;
707         GtkWidget *help_bt;
708         GtkWidget *vbox;
709         gdouble variance;
710         gint start, stop,ttl, order, pos=0;
711         const char *filter=NULL;
712         GString *error_string;
713
714         if(sscanf(optarg,"compare,%d,%d,%d,%d,%lf%n",&start, &stop, &ttl, &order, &variance, &pos)==5){
715                 if(pos){
716                         if(*(optarg+pos)==',')
717                                 filter=optarg+pos+1;
718                         else
719                                 filter=optarg+pos;
720                 } else {
721                         filter=NULL;
722                 }
723         } else {
724                 fprintf(stderr, "wireshark: invalid \"-z compare,<start>,<stop>,<ttl[0|1]>,<order[0|1]>,<variance>[,<filter>]\" argument\n");
725                 exit(1);
726         }
727
728         compare_variance=variance;
729         compare_start=start;
730         compare_stop=stop;
731         TTL_method=ttl;
732         ON_method=order;
733
734         cs=g_malloc(sizeof(compstat_t));
735         nstime_set_unset(&cs->current_time);
736         cs->ip_ttl_list=g_array_new(FALSE, FALSE, sizeof(guint8));
737         cs->last_hit=FALSE;
738         cs->start_ongoing_hits=0;
739         cs->stop_ongoing_hits=0;
740         cs->start_packet_nr_first=G_MAXINT32;
741         cs->start_packet_nr_second=G_MAXINT32;
742         cs->stop_packet_nr_first=G_MAXINT32;
743         cs->stop_packet_nr_second=G_MAXINT32;
744         cs->first_file_amount=0;
745         cs->second_file_amount=0;
746
747         cs->zebra_time.secs=0;
748         cs->zebra_time.nsecs=1;
749         cs->nr_tree=se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "nr_tree");
750         /* microsecond precision */
751         timestamp_set_precision(TS_PREC_AUTO_NSEC);
752
753         /* transient_for top_level */
754         cs->win=dlg_window_new("compare-stat");
755         gtk_window_set_destroy_with_parent (GTK_WINDOW(cs->win), TRUE);
756         gtk_window_set_default_size(GTK_WINDOW(cs->win), 550, 400);
757         comparestat_set_title(cs);
758
759         vbox=gtk_vbox_new(FALSE, 3);
760         gtk_container_add(GTK_CONTAINER(cs->win), vbox);
761         gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
762
763         title_string = g_strdup_printf("Compare two capture files: %s", cf_get_display_name(&cfile));
764         stat_label=gtk_label_new(title_string);
765         g_free(title_string);
766         gtk_box_pack_start(GTK_BOX(vbox), stat_label, FALSE, FALSE, 0);
767
768         filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
769         filter_label=gtk_label_new(filter_string);
770         g_free(filter_string);
771         gtk_label_set_line_wrap(GTK_LABEL(filter_label), TRUE);
772         gtk_box_pack_start(GTK_BOX(vbox), filter_label, FALSE, FALSE, 0);
773
774         /* add statistik info to Window */
775         cs->statis_label=gtk_label_new("Statistics:");
776         gtk_label_set_line_wrap(GTK_LABEL(cs->statis_label), TRUE);
777         gtk_box_pack_start(GTK_BOX(vbox), cs->statis_label, FALSE, FALSE, 0);
778
779         /* we must display TOP LEVEL Widget before calling simple_list_new */
780         gtk_widget_show_all(cs->win);
781
782         cs->treeview=gtk_tree_view_new();
783         setup_tree_view(cs->treeview);
784
785         /* create a newtree model with four columns */
786         cs->simple_list=gtk_tree_store_new(COLUMNS, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_DOUBLE);
787
788         /* add the tree model to the tree view and unreference it so that the model will
789         * be destroyed along with the tree view. */
790         gtk_tree_view_set_model(GTK_TREE_VIEW (cs->treeview), GTK_TREE_MODEL (cs->simple_list));
791         g_object_unref(cs->simple_list);
792
793         /* call this method when row is chosen*/
794         gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(cs->treeview)),GTK_SELECTION_SINGLE);
795         g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(cs->treeview)), "changed", G_CALLBACK(new_tree_view_selection_changed), cs);
796
797         /* list with scrollbar's */
798         cs->scrolled_win=gtk_scrolled_window_new(NULL, NULL);
799         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(cs->scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
800         gtk_container_add(GTK_CONTAINER(cs->scrolled_win), cs->treeview);
801         gtk_box_pack_start(GTK_BOX(vbox), cs->scrolled_win, TRUE, TRUE, 0);
802
803         /* create a Hash to count the packets with the same ip.id */
804         cs->packet_tree=se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "Packet_info_tree");
805
806         error_string=register_tap_listener("ip", cs, filter, 0, comparestat_reset, comparestat_packet, comparestat_draw);
807         if(error_string){
808                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
809                 g_string_free(error_string, TRUE);
810                 gtk_tree_store_clear(cs->simple_list);
811                 g_free(cs);
812                 return;
813         }
814
815         /* button row. */
816         bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
817         gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
818
819         close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
820         window_set_cancel_button(cs->win, close_bt, window_cancel_button_cb);
821
822         help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
823         g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_COMPARE_FILES_DIALOG);
824
825         g_signal_connect(cs->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
826         g_signal_connect(cs->win, "destroy", G_CALLBACK(win_destroy_cb), cs);
827
828         gtk_widget_show_all(cs->win);
829         window_present(cs->win);
830
831         cf_retap_packets(&cfile);
832 }
833
834 static GtkWidget *dlg=NULL;
835 static GtkWidget *filter_entry;
836
837 static void
838 comparestat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
839 {
840         GString *str;
841         const char *filter;
842
843         compare_start=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_start_int));
844         compare_stop=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_stop_int));
845         compare_variance=gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin_var_int));
846         if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_TTL))){
847                 TTL_method=TRUE;
848         } else {
849                 TTL_method=FALSE;
850         }
851         if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio_ON))){
852                 ON_method=TRUE;
853         } else {
854                 ON_method=FALSE;
855         }
856
857         str = g_string_new("compare");
858         g_string_append_printf(str, ",%d,%d,%d,%d,%lf",compare_start, compare_stop, TTL_method, ON_method, compare_variance);
859         filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
860         if(filter[0]!=0){
861                 g_string_append_printf(str, ",%s", filter);
862         }
863
864         if(first_window){
865                 first_window = FALSE;
866                 gtk_comparestat_init(str->str,NULL);
867         } else {
868                 report_failure("cannot open more than one compare of the same type at once");
869         }
870
871         g_string_free(str, TRUE);
872 }
873
874 static void
875 dlg_destroy_cb(GtkWidget *w _U_, gpointer user_data _U_)
876 {
877         dlg=NULL;
878 }
879
880 /* create and show first view of this module
881  */
882 static void
883 gtk_comparestat_cb(GtkWidget *w _U_, gpointer d _U_)
884 {
885         GtkAdjustment *start_integer, *stop_integer, *var_integer;
886         GtkWidget *dlg_box;
887         GtkWidget *spin_start_label, *spin_stop_label, *spin_start_box, *spin_stop_box;
888         GtkWidget *spin_var_box, *spin_var_label;
889         GtkWidget *order_box, *radio_MAC, *order_label;
890         GtkWidget *differ_box, *radio_OFF, *differ_label;
891         GtkWidget *filter_box, *filter_bt;
892         GtkWidget *bbox, *start_button, *cancel_button;
893         const char *filter;
894         static construct_args_t args = {
895           "Compare statistics",
896           TRUE,
897           FALSE,
898           FALSE
899         };
900
901         /* if the window is already open, bring it to front */
902         if(dlg){
903                 gdk_window_raise(dlg->window);
904                 return;
905         }
906
907         dlg=dlg_window_new("Wireshark: Compare two capture files");
908         gtk_window_set_default_size(GTK_WINDOW(dlg), 300, -1);
909
910         dlg_box=gtk_vbox_new(FALSE, 10);
911         gtk_container_set_border_width(GTK_CONTAINER(dlg_box), 10);
912         gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
913         gtk_widget_show(dlg_box);
914
915         /* spin Box */
916         spin_start_box=gtk_hbox_new(FALSE, 10);
917         spin_stop_box=gtk_hbox_new(FALSE, 10);
918
919         /* spin label */
920         gtk_container_set_border_width(GTK_CONTAINER(spin_start_box), 1);
921         spin_start_label=gtk_label_new("Start compare:");
922         gtk_box_pack_start(GTK_BOX(spin_start_box), spin_start_label, FALSE, FALSE, 0);
923         gtk_widget_show(spin_start_label);
924         gtk_container_set_border_width(GTK_CONTAINER(spin_stop_box), 1);
925         spin_stop_label=gtk_label_new("Stop compare: ");
926         gtk_box_pack_start(GTK_BOX(spin_stop_box), spin_stop_label, FALSE, FALSE, 0);
927         gtk_widget_show(spin_stop_label);
928
929         /* create adjustments. Spans between 0 and 100, starting at 0 and
930          * moves in increments of 1 */
931         start_integer=GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 100.0, 1.0, 5.0, 0.0));
932         stop_integer=GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 100.0, 1.0, 5.0, 0.0));
933
934         /* create spin button. Not displaying decimal */
935         spin_start_int=gtk_spin_button_new(start_integer, 1.0, 0);
936         spin_stop_int=gtk_spin_button_new(stop_integer, 1.0, 0);
937
938         /* pack it up */
939         gtk_box_pack_start(GTK_BOX(spin_start_box), spin_start_int, TRUE, TRUE, 0);
940         gtk_box_pack_start(GTK_BOX(spin_stop_box), spin_stop_int,  TRUE, TRUE, 0);
941
942         gtk_box_pack_start(GTK_BOX(dlg_box), spin_start_box, FALSE, FALSE, 0);
943         gtk_widget_show(spin_start_box);
944         gtk_box_pack_start(GTK_BOX(dlg_box), spin_stop_box, FALSE, FALSE, 0);
945         gtk_widget_show(spin_stop_box);
946
947         /* differ Box */
948         differ_box=gtk_hbox_new(FALSE, 10);
949
950         /* radio label */
951         gtk_container_set_border_width(GTK_CONTAINER(differ_box), 1);
952         differ_label=gtk_label_new("Endpoint distinction:");
953         gtk_box_pack_start(GTK_BOX(differ_box), differ_label, FALSE, FALSE, 0);
954         gtk_widget_show(differ_label);
955
956         /* create radio buttons */
957         radio_MAC=gtk_radio_button_new_with_label (NULL, "MAC");
958         radio_TTL=gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON(radio_MAC), "TTL");
959         gtk_box_pack_start(GTK_BOX(differ_box), radio_MAC, TRUE, TRUE, 0);
960         gtk_box_pack_start(GTK_BOX(differ_box), radio_TTL, TRUE, TRUE, 0);
961         gtk_widget_show(radio_MAC);
962         gtk_widget_show(radio_TTL);
963
964         gtk_box_pack_start(GTK_BOX(dlg_box), differ_box, FALSE, FALSE, 0);
965         gtk_widget_show(differ_box);
966
967         /* order Box */
968         order_box=gtk_hbox_new(FALSE, 10);
969
970         /* order label */
971         gtk_container_set_border_width(GTK_CONTAINER(order_box), 1);
972         order_label=gtk_label_new("Check order:    ");
973         gtk_box_pack_start(GTK_BOX(order_box), order_label, FALSE, FALSE, 0);
974         gtk_widget_show(order_label);
975
976         /* create radio buttons */
977         radio_ON=gtk_radio_button_new_with_label (NULL, "On");
978         radio_OFF=gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON(radio_ON), "Off");
979         gtk_box_pack_start(GTK_BOX(order_box), radio_ON, TRUE, TRUE, 0);
980         gtk_box_pack_start(GTK_BOX(order_box), radio_OFF, TRUE, TRUE, 0);
981         gtk_widget_show(radio_ON);
982         gtk_widget_show(radio_OFF);
983
984         gtk_box_pack_start(GTK_BOX(dlg_box), order_box, FALSE, FALSE, 0);
985         gtk_widget_show(order_box);
986
987         /* spin box */
988         spin_var_box=gtk_hbox_new(FALSE, 10);
989
990         /* spin label */
991         gtk_container_set_border_width(GTK_CONTAINER(spin_var_box), 1);
992         spin_var_label=gtk_label_new("Time variance (sec +/-):");
993         gtk_box_pack_start(GTK_BOX(spin_var_box), spin_var_label, FALSE, FALSE, 0);
994         gtk_widget_show(spin_var_label);
995
996         /* create adjustments. Spans between 0 and 100, starting at 0 and
997          * moves in increments of 1 */
998         var_integer=GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 100.0, 1.0, 5.0, 0.0));
999
1000         /* create spin button. Not displaying decimal */
1001         spin_var_int=gtk_spin_button_new(var_integer, 0.0, 2);
1002
1003         /* pack it up */
1004         gtk_box_pack_start(GTK_BOX(spin_var_box), spin_var_int, TRUE, TRUE, 0);
1005         gtk_widget_show(spin_var_int);
1006
1007         gtk_box_pack_start(GTK_BOX(dlg_box), spin_var_box, FALSE, FALSE, 0);
1008         gtk_widget_show(spin_var_box);
1009
1010         /* filter box */
1011         filter_box=gtk_hbox_new(FALSE, 3);
1012
1013         /* filter label */
1014         filter_bt=gtk_button_new_from_stock(WIRESHARK_STOCK_DISPLAY_FILTER_ENTRY);
1015         g_signal_connect(filter_bt, "clicked", G_CALLBACK(display_filter_construct_cb), &args);
1016         gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, TRUE, 0);
1017         gtk_widget_show(filter_bt);
1018
1019         /* filter entry */
1020         filter_entry=gtk_entry_new();
1021         g_signal_connect(filter_entry, "changed",  G_CALLBACK(filter_te_syntax_check_cb), NULL);
1022         g_object_set_data(G_OBJECT(filter_box), E_FILT_AUTOCOMP_PTR_KEY, NULL);
1023         g_signal_connect(filter_entry, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
1024         g_signal_connect(dlg, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
1025
1026         /* filter prefs dialog */
1027         g_object_set_data(G_OBJECT(filter_bt), E_FILT_TE_PTR_KEY, filter_entry);
1028         /* filter prefs dialog */
1029
1030         gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
1031         filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
1032         if(filter){
1033                 gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
1034         }
1035         gtk_widget_show(filter_entry);
1036
1037         gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
1038         gtk_widget_show(filter_box);
1039
1040         /* button box */
1041         bbox = dlg_button_row_new(WIRESHARK_STOCK_CREATE_STAT, GTK_STOCK_CANCEL, NULL);
1042         gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
1043         gtk_widget_show(bbox);
1044
1045         start_button = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_CREATE_STAT);
1046         g_signal_connect_swapped(start_button, "clicked", G_CALLBACK(comparestat_start_button_clicked), NULL);
1047
1048         cancel_button = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1049         window_set_cancel_button(dlg, cancel_button, window_cancel_button_cb);
1050
1051         /* give the initial focus to the "filter" entry box. */
1052         gtk_widget_grab_focus(filter_entry);
1053
1054         gtk_widget_grab_default(start_button );
1055
1056         g_signal_connect(dlg, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1057         g_signal_connect(dlg, "destroy", G_CALLBACK(dlg_destroy_cb), NULL);
1058
1059         gtk_widget_show_all(dlg);
1060         window_present(dlg);
1061 }
1062
1063
1064 void
1065 register_tap_listener_gtkcomparestat(void)
1066 {
1067         register_stat_cmd_arg("compare", gtk_comparestat_init, NULL);
1068
1069         register_stat_menu_item("Compare...", REGISTER_STAT_GROUP_UNSORTED, gtk_comparestat_cb, NULL, NULL, NULL);
1070 }