Fix the wireless settings button for AirPCap devices in the
[obnox/wireshark/wip.git] / gtk / sctp_stat_dlg.c
1 /*
2  * Copyright 2004, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28 #include <string.h>
29
30 #include <gtk/gtk.h>
31
32 #include "epan/filesystem.h"
33
34 #include "../globals.h"
35 #include "../stat_menu.h"
36
37 #include "gtk/gui_stat_menu.h"
38 #include "gtk/dlg_utils.h"
39 #include "gtk/gui_utils.h"
40 #include "gtk/main.h"
41 #include "gtk/sctp_stat.h"
42 #include "gtk/gtkglobals.h"
43
44 #include "gtk/old-gtk-compat.h"
45
46 static GtkWidget *sctp_stat_dlg=NULL;
47 static GtkWidget *clist = NULL;
48 static GList *last_list = NULL;
49 static gchar *filter_string = NULL;
50 static sctp_assoc_info_t* selected_stream=NULL;  /* current selection */
51 static sctp_allassocs_info_t *sctp_assocs=NULL;
52 static guint16 n_children=0;
53 static GtkWidget *bt_afilter = NULL, *bt_unselect=NULL, *bt_analyse=NULL, *bt_filter=NULL;
54 static gboolean prevent_update = FALSE, filter_applied = FALSE;
55
56 enum
57 {
58         PORT1_COLUMN,
59         PORT2_COLUMN,
60         PACKETS_COLUMN,
61         CHECKSUM_TYPE_COLUMN,
62         CHECKSUM_ERRORS_COLUMN,
63         DATA_CHUNKS_COLUMN,
64         DATA_BYTES_COLUMN,
65         VTAG1_COLUMN,
66         VTAG2_COLUMN,
67         N_COLUMN
68 };
69
70
71 static void
72 sctp_stat_on_select_row(GtkTreeSelection *sel, gpointer user_data _U_)
73 {
74         GtkTreeModel *model;
75         GtkTreeIter iter;
76         GList *list;
77         sctp_assoc_info_t* assoc;
78         gboolean stream_found=FALSE;
79         guint32 port2, port1;
80         guint32 checksum, data_chunks, data_bytes, packets, vtag1, vtag2;
81
82         if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
83                 gtk_tree_model_get(model, &iter,
84                         PORT1_COLUMN, &port1,
85                         PORT2_COLUMN, &port2,
86                         PACKETS_COLUMN, &packets,
87                         CHECKSUM_ERRORS_COLUMN, &checksum,
88                         DATA_CHUNKS_COLUMN, &data_chunks,
89                         DATA_BYTES_COLUMN, &data_bytes,
90                         VTAG1_COLUMN, &vtag1,
91                         VTAG2_COLUMN, &vtag2,
92                         -1);
93         } else {
94                 /* Nothing selected */
95                 return;
96         }
97
98         list = g_list_first(sctp_assocs->assoc_info_list);
99
100         while (list)
101         {
102                 assoc = (sctp_assoc_info_t*)(list->data);
103                 if (assoc->port1==port1 && assoc->port2==port2
104                 && assoc->n_packets==packets && assoc->n_data_chunks==data_chunks && assoc->n_data_bytes==data_bytes
105                 && assoc->verification_tag1==vtag1 && assoc->verification_tag2==vtag2)
106                 {
107                         selected_stream=assoc;
108                         stream_found=TRUE;
109                         break;
110                 }
111                 list=g_list_next(list);
112         }
113
114         if (!stream_found)
115                 selected_stream = NULL;
116
117         gtk_widget_set_sensitive(bt_unselect,TRUE);
118         gtk_widget_set_sensitive(bt_analyse,TRUE);
119         gtk_widget_set_sensitive(bt_filter,TRUE);
120 }
121
122 static
123 GtkWidget *create_list(void)
124 {
125         GtkListStore *list_store;
126         GtkWidget * list;
127         GtkTreeViewColumn *column;
128         GtkCellRenderer *renderer;
129         GtkTreeView *list_view;
130         GtkTreeSelection *selection;
131
132         list_store = gtk_list_store_new(N_COLUMN,
133                 G_TYPE_UINT, /* Port1*/
134                 G_TYPE_UINT, /* Port2*/
135                 G_TYPE_UINT, /* number of packets */
136                 G_TYPE_STRING, /* checksum type */
137                 G_TYPE_UINT, /* number of checksum errors */
138                 G_TYPE_UINT, /* number of data chunks */
139                 G_TYPE_UINT, /* number of data bytes */
140                 G_TYPE_UINT, /* vtag1 */
141                 G_TYPE_UINT); /* vtag2 */
142
143         /* Create a view */
144         list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
145
146         list_view = GTK_TREE_VIEW(list);
147
148         /* Speed up the list display */
149         gtk_tree_view_set_fixed_height_mode(list_view, TRUE);
150
151         gtk_tree_view_set_headers_clickable(list_view, TRUE);
152
153         /* The view now holds a reference.  We can get rid of our own reference */
154         g_object_unref (G_OBJECT (list_store));
155
156         /*
157          * Create the first column packet, associating the "text" attribute of the
158          * cell_renderer to the first column of the model
159          */
160         /* 1:st column */
161         renderer = gtk_cell_renderer_text_new ();
162         column = gtk_tree_view_column_new_with_attributes ("Port 1", renderer,
163                 "text", PORT1_COLUMN,
164                 NULL);
165
166         gtk_tree_view_column_set_sort_column_id(column, PORT1_COLUMN);
167         gtk_tree_view_column_set_resizable(column, TRUE);
168         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
169         gtk_tree_view_column_set_min_width(column, 80);
170
171         /* Add the column to the view. */
172         gtk_tree_view_append_column (list_view, column);
173
174         /* 2:nd column... */
175         renderer = gtk_cell_renderer_text_new ();
176         column = gtk_tree_view_column_new_with_attributes ("Port 2", renderer,
177                     "text", PORT2_COLUMN,
178                     NULL);
179         gtk_tree_view_column_set_sort_column_id(column, PORT2_COLUMN);
180         gtk_tree_view_column_set_resizable(column, TRUE);
181         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
182         gtk_tree_view_column_set_min_width(column, 80);
183         gtk_tree_view_append_column (list_view, column);
184
185         /* 3:d column... */
186         renderer = gtk_cell_renderer_text_new ();
187         column = gtk_tree_view_column_new_with_attributes ("No of Packets", renderer,
188                     "text", PACKETS_COLUMN,
189                     NULL);
190         gtk_tree_view_column_set_sort_column_id(column, PACKETS_COLUMN);
191         gtk_tree_view_column_set_resizable(column, TRUE);
192         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
193         gtk_tree_view_column_set_min_width(column, 120);
194         gtk_tree_view_append_column (list_view, column);
195
196         /* 4:th column... */
197         renderer = gtk_cell_renderer_text_new ();
198         column = gtk_tree_view_column_new_with_attributes ("Checksum", renderer,
199                     "text", CHECKSUM_TYPE_COLUMN,
200                     NULL);
201         gtk_tree_view_column_set_sort_column_id(column, CHECKSUM_TYPE_COLUMN);
202         gtk_tree_view_column_set_resizable(column, TRUE);
203         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
204         gtk_tree_view_column_set_min_width(column, 120);
205         gtk_tree_view_append_column (list_view, column);
206
207         /* 5:th column... */
208         renderer = gtk_cell_renderer_text_new ();
209         column = gtk_tree_view_column_new_with_attributes ("No of Errors", renderer,
210                     "text", CHECKSUM_ERRORS_COLUMN,
211                     NULL);
212         gtk_tree_view_column_set_sort_column_id(column, CHECKSUM_ERRORS_COLUMN);
213         gtk_tree_view_column_set_resizable(column, TRUE);
214         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
215         gtk_tree_view_column_set_min_width(column, 120);
216         gtk_tree_view_append_column (list_view, column);
217
218         /* 6:th column... */
219         renderer = gtk_cell_renderer_text_new ();
220         column = gtk_tree_view_column_new_with_attributes ("Data Chunks", renderer,
221                     "text", DATA_CHUNKS_COLUMN,
222                     NULL);
223         gtk_tree_view_column_set_sort_column_id(column, DATA_CHUNKS_COLUMN);
224         gtk_tree_view_column_set_resizable(column, TRUE);
225         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
226         gtk_tree_view_column_set_min_width(column, 120);
227         gtk_tree_view_append_column (list_view, column);
228
229         /* 7:th column... */
230         renderer = gtk_cell_renderer_text_new ();
231         column = gtk_tree_view_column_new_with_attributes ("Data Bytes", renderer,
232                     "text", DATA_BYTES_COLUMN,
233                     NULL);
234         gtk_tree_view_column_set_sort_column_id(column, DATA_BYTES_COLUMN);
235         gtk_tree_view_column_set_resizable(column, TRUE);
236         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
237         gtk_tree_view_column_set_min_width(column, 120);
238         gtk_tree_view_append_column (list_view, column);
239
240         /* 8:th column... */
241         renderer = gtk_cell_renderer_text_new ();
242         column = gtk_tree_view_column_new_with_attributes ("VTag 1", renderer,
243                     "text", VTAG1_COLUMN,
244                     NULL);
245         gtk_tree_view_column_set_sort_column_id(column, VTAG1_COLUMN);
246         gtk_tree_view_column_set_resizable(column, TRUE);
247         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
248         gtk_tree_view_column_set_min_width(column, 120);
249         gtk_tree_view_append_column (list_view, column);
250
251
252         /* 9:th column... */
253         renderer = gtk_cell_renderer_text_new ();
254         column = gtk_tree_view_column_new_with_attributes ("VTag 2", renderer,
255                     "text", VTAG2_COLUMN,
256                     NULL);
257         gtk_tree_view_column_set_sort_column_id(column, VTAG2_COLUMN);
258         gtk_tree_view_column_set_resizable(column, TRUE);
259         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
260         gtk_tree_view_column_set_min_width(column, 120);
261         gtk_tree_view_append_column (list_view, column);
262
263         /* Now enable the sorting of each column */
264         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view), TRUE);
265         gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(list_view), TRUE);
266
267         /* Setup the selection handler */
268         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
269         gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
270         g_signal_connect(selection, "changed", G_CALLBACK(sctp_stat_on_select_row), NULL);
271         return list;
272 }
273
274 static void
275 dlg_destroy(GtkWidget *w _U_, gpointer user_data _U_)
276 {
277         guint32 i, j;
278         GList *list;
279         struct sctp_analyse *child_data;
280
281         j=n_children;
282         for (i=0; i<j; i++)
283         {
284                 list=g_list_last(sctp_assocs->children);
285                 child_data=(struct sctp_analyse *)list->data;
286                 gtk_grab_remove(GTK_WIDGET(child_data->window));
287                 gtk_widget_destroy(GTK_WIDGET(child_data->window));
288         }
289         g_list_free(sctp_assocs->children);
290         sctp_assocs->children = NULL;
291         sctp_stat_dlg = NULL;
292         prevent_update = FALSE;
293         filter_applied = FALSE;
294 }
295
296 void
297 decrease_analyse_childcount(void)
298 {
299         n_children--;
300 }
301
302 void
303 increase_analyse_childcount(void)
304 {
305         n_children++;
306 }
307
308 void
309 set_analyse_child(struct sctp_analyse *child)
310 {
311         sctp_assocs->children=g_list_append(sctp_assocs->children, child);
312 }
313
314 void
315 remove_analyse_child(struct sctp_analyse *child)
316 {
317         sctp_assocs->children=g_list_remove(sctp_assocs->children, child);
318 }
319
320
321
322 static void add_to_clist(sctp_assoc_info_t* assinfo)
323 {
324     GtkListStore *list_store = NULL;
325     GtkTreeIter  iter;
326
327     list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW (clist))); /* Get store */
328
329     gtk_list_store_insert_with_values( list_store , &iter, G_MAXINT,
330                 PORT1_COLUMN,                   (guint32)assinfo->port1,
331                 PORT2_COLUMN,                   (guint32)assinfo->port2,
332                 PACKETS_COLUMN,                 assinfo->n_packets,
333                 CHECKSUM_TYPE_COLUMN,   assinfo->checksum_type,
334                 CHECKSUM_ERRORS_COLUMN, assinfo->n_checksum_errors,
335                 DATA_CHUNKS_COLUMN,             assinfo->n_data_chunks,
336                 DATA_BYTES_COLUMN,              assinfo->n_data_bytes,
337                 VTAG1_COLUMN,                   assinfo->verification_tag1,
338                 VTAG2_COLUMN,                   assinfo->verification_tag2,
339          -1);
340 }
341
342 static void
343 sctp_stat_on_unselect(GtkButton *button _U_, gpointer user_data _U_)
344 {
345         if (filter_string != NULL) {
346                 g_free(filter_string);
347                 filter_string = NULL;
348         }
349
350         selected_stream = NULL;
351         gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), "");
352         main_filter_packets(&cfile, "", FALSE);
353         gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(GTK_TREE_VIEW(clist)));
354         gtk_widget_set_sensitive(bt_unselect,FALSE);
355         gtk_widget_set_sensitive(bt_filter,FALSE);
356         gtk_widget_set_sensitive(bt_analyse,FALSE);
357         gtk_widget_set_sensitive(bt_afilter,FALSE);
358         prevent_update = FALSE;
359         filter_applied = FALSE;
360 }
361
362 void sctp_stat_dlg_update(void)
363 {
364         GList *list;
365
366         list=(sctp_stat_get_info()->assoc_info_list);
367         if (sctp_stat_dlg != NULL && !prevent_update)
368         {
369                 gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(clist))));
370                 list = g_list_first(sctp_stat_get_info()->assoc_info_list);
371
372                 while (list)
373                 {
374                         add_to_clist((sctp_assoc_info_t*)(list->data));
375                         list = g_list_next(list);
376                 }
377         }
378         last_list = list;
379 }
380
381
382
383 static void
384 sctp_stat_on_apply_filter (GtkButton *button _U_, gpointer user_data _U_)
385 {
386         GList *list;
387         sctp_assoc_info_t* assoc;
388         guint16 port1, port2;
389         guint32 data_chunks, data_bytes, packets, vtag1, vtag2;
390
391         if (filter_string != NULL)
392         {
393                 port1 = selected_stream->port1;
394                 port2 = selected_stream->port2;
395                 data_chunks = selected_stream->n_data_chunks;
396                 data_bytes = selected_stream->n_data_bytes;
397                 packets = selected_stream->n_packets;
398                 vtag1 = selected_stream->verification_tag1;
399                 vtag2 = selected_stream->verification_tag2;
400                 main_filter_packets(&cfile, filter_string, FALSE);
401                 list = g_list_first(sctp_assocs->assoc_info_list);
402
403                 while (list)
404                 {
405                         assoc = (sctp_assoc_info_t*)(list->data);
406                         if (assoc->port1==port1 && assoc->port2==port2
407                         && assoc->n_packets==packets && assoc->n_data_chunks==data_chunks && assoc->n_data_bytes==data_bytes
408                         && assoc->verification_tag1==vtag1 && assoc->verification_tag2==vtag2)
409                         {
410                                 selected_stream=assoc;
411                                 break;
412                         }
413                         list=g_list_next(list);
414                 }
415                 gtk_widget_set_sensitive(bt_afilter,FALSE);
416                 prevent_update=TRUE;
417                 filter_applied = TRUE;
418         }
419 }
420
421 static void
422 sctp_stat_on_filter (GtkButton *button _U_, gpointer user_data _U_)
423 {
424         gchar *f_string = NULL;
425         GList *srclist, *dstlist;
426         gchar *str=NULL;
427         GString *gstring=NULL;
428         struct sockaddr_in *infosrc=NULL;
429         struct sockaddr_in *infodst=NULL;
430
431         if (selected_stream==NULL) {
432                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), "");
433                 return;
434         }
435
436         if (selected_stream->check_address==FALSE)
437         {
438                 f_string = g_strdup_printf("((sctp.srcport==%u && sctp.dstport==%u && "
439                         "((sctp.verification_tag==0x%x && sctp.verification_tag!=0x0) || "
440                         "(sctp.verification_tag==0x0 && sctp.initiate_tag==0x%x) || "
441                         "(sctp.verification_tag==0x%x && (sctp.abort_t_bit==1 || "
442                         "sctp.shutdown_complete_t_bit==1)))) ||"
443                         "(sctp.srcport==%u && sctp.dstport==%u && ((sctp.verification_tag==0x%x "
444                         "&& sctp.verification_tag!=0x0) || "
445                         "(sctp.verification_tag==0x0 && sctp.initiate_tag==0x%x) ||"
446                         "(sctp.verification_tag==0x%x && (sctp.abort_t_bit==1 ||"
447                         " sctp.shutdown_complete_t_bit==1)))))",
448                 selected_stream->port1,
449                 selected_stream->port2,
450                 selected_stream->verification_tag1,
451                 selected_stream->initiate_tag,
452                 selected_stream->verification_tag2,
453                 selected_stream->port2,
454                 selected_stream->port1,
455                 selected_stream->verification_tag2,
456                 selected_stream->initiate_tag,
457                 selected_stream->verification_tag1);
458                 filter_string = f_string;
459         }
460         else
461         {
462
463                 srclist = g_list_first(selected_stream->addr1);
464                 infosrc=(struct sockaddr_in *) (srclist->data);
465                 gstring = g_string_new(g_strdup_printf("((sctp.srcport==%u && sctp.dstport==%u && (ip.src==%s",
466                         selected_stream->port1, selected_stream->port2, ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr))));
467                 srclist= g_list_next(srclist);
468
469                 while (srclist)
470                 {
471                         infosrc=(struct sockaddr_in *) (srclist->data);
472                         str =g_strdup_printf("|| ip.src==%s",ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr)));
473                         g_string_append(gstring, str);
474                         srclist= g_list_next(srclist);
475                 }
476                 dstlist = g_list_first(selected_stream->addr2);
477                 infodst=(struct sockaddr_in *) (dstlist->data);
478                 str = g_strdup_printf(") && (ip.dst==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
479                 g_string_append(gstring, str);
480                 dstlist= g_list_next(dstlist);
481                 while (dstlist)
482                 {
483                         infodst=(struct sockaddr_in *) (dstlist->data);
484                         str =g_strdup_printf("|| ip.dst==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
485                         g_string_append(gstring, str);
486                         dstlist= g_list_next(dstlist);
487                 }
488                 srclist = g_list_first(selected_stream->addr1);
489                 infosrc=(struct sockaddr_in *) (srclist->data);
490                 str = g_strdup_printf(")) || (sctp.dstport==%u && sctp.srcport==%u && (ip.dst==%s",
491                         selected_stream->port1, selected_stream->port2, ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr)));
492                 g_string_append(gstring, str);
493                 srclist= g_list_next(srclist);
494
495                 while (srclist)
496                 {
497                         infosrc=(struct sockaddr_in *) (srclist->data);
498                         str =g_strdup_printf("|| ip.dst==%s",ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr)));
499                         g_string_append(gstring, str);
500                         srclist= g_list_next(srclist);
501                 }
502
503                 dstlist = g_list_first(selected_stream->addr2);
504                 infodst=(struct sockaddr_in *) (dstlist->data);
505                 str = g_strdup_printf(") && (ip.src==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
506                 g_string_append(gstring, str);
507                 dstlist= g_list_next(dstlist);
508                 while (dstlist)
509                 {
510                         infodst=(struct sockaddr_in *) (dstlist->data);
511                         str =g_strdup_printf("|| ip.src==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
512                         g_string_append(gstring, str);
513                         dstlist= g_list_next(dstlist);
514                 }
515                 str = g_strdup_printf(")))");
516                 g_string_append(gstring, str);
517                 filter_string = gstring->str;
518                 g_string_free(gstring,FALSE);
519         }
520
521         if (filter_string != NULL) {
522                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
523         } else {
524                 g_assert_not_reached();
525         }
526         gtk_widget_set_sensitive(bt_afilter,TRUE);
527         gtk_widget_set_sensitive(bt_filter,FALSE);
528         prevent_update = TRUE;
529         filter_applied = FALSE;
530 }
531
532
533 static void
534 sctp_stat_on_close (GtkWidget *button _U_, gpointer user_data _U_)
535 {
536         gtk_grab_remove(sctp_stat_dlg);
537         gtk_widget_destroy(sctp_stat_dlg);
538         prevent_update = FALSE;
539         filter_applied = FALSE;
540 }
541
542 static void
543 sctp_stat_on_analyse (GtkButton *button _U_, gpointer user_data _U_)
544 {
545         if (selected_stream==NULL)
546                 return;
547         else
548                 assoc_analyse(selected_stream);
549         gtk_widget_set_sensitive(bt_analyse,FALSE);
550         if (!filter_applied)
551                 gtk_widget_set_sensitive(bt_filter,TRUE);
552         prevent_update = TRUE;
553 }
554
555
556 static void
557 gtk_sctpstat_dlg(void)
558 {
559         GtkWidget *sctp_stat_dlg_w;
560         GtkWidget *vbox1;
561         GtkWidget *scrolledwindow1;
562         GtkWidget *hbuttonbox2;
563         GtkWidget *bt_close;
564
565         sctp_stat_dlg_w = window_new (GTK_WINDOW_TOPLEVEL, "Wireshark: SCTP Associations");
566         gtk_window_set_position (GTK_WINDOW (sctp_stat_dlg_w), GTK_WIN_POS_CENTER);
567         g_signal_connect(sctp_stat_dlg_w, "destroy", G_CALLBACK(dlg_destroy), NULL);
568
569         /* Container for each row of widgets */
570         vbox1 = gtk_vbox_new(FALSE, 2);
571         gtk_container_set_border_width(GTK_CONTAINER(vbox1), 8);
572         gtk_container_add(GTK_CONTAINER(sctp_stat_dlg_w), vbox1);
573         gtk_widget_show(vbox1);
574
575         scrolledwindow1 = scrolled_window_new (NULL, NULL);
576         gtk_widget_show (scrolledwindow1);
577         gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
578
579         clist = create_list();
580         gtk_widget_show (clist);
581         gtk_container_add (GTK_CONTAINER (scrolledwindow1), clist);
582         gtk_widget_set_size_request(clist, 1050, 200);
583
584         gtk_widget_show(sctp_stat_dlg_w);
585
586         hbuttonbox2 = gtk_hbutton_box_new();
587         gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox2, FALSE, FALSE, 0);
588         gtk_container_set_border_width(GTK_CONTAINER(hbuttonbox2), 10);
589         gtk_button_box_set_layout(GTK_BUTTON_BOX (hbuttonbox2), GTK_BUTTONBOX_SPREAD);
590         gtk_box_set_spacing(GTK_BOX (hbuttonbox2), 0);
591         gtk_widget_show(hbuttonbox2);
592
593         bt_unselect = gtk_button_new_with_label ("Unselect");
594         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_unselect);
595         gtk_widget_show (bt_unselect);
596         gtk_widget_set_sensitive(bt_unselect,FALSE);
597
598         bt_filter = gtk_button_new_with_label ("Set filter");
599         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_filter);
600         gtk_widget_show (bt_filter);
601         gtk_widget_set_sensitive(bt_filter,FALSE);
602
603         bt_afilter = gtk_button_new_with_label ("Apply filter");
604         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_afilter);
605         gtk_widget_show (bt_afilter);
606         gtk_widget_set_sensitive(bt_afilter,FALSE);
607
608         bt_analyse = gtk_button_new_with_label ("Analyse");
609         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_analyse);
610         gtk_widget_show (bt_analyse);
611         gtk_widget_set_sensitive(bt_analyse,FALSE);
612
613         bt_close = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
614         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_close);
615 #if GTK_CHECK_VERSION(2,18,0)
616         gtk_widget_set_can_default(bt_close, TRUE);
617 #else
618         GTK_WIDGET_SET_FLAGS(bt_close, GTK_CAN_DEFAULT);
619 #endif
620         window_set_cancel_button( sctp_stat_dlg_w, bt_close, sctp_stat_on_close);
621         gtk_widget_grab_focus(bt_close);
622         gtk_widget_show (bt_close);
623
624         g_signal_connect(sctp_stat_dlg_w, "destroy", G_CALLBACK(dlg_destroy), NULL);
625         g_signal_connect(bt_unselect, "clicked", G_CALLBACK(sctp_stat_on_unselect), NULL);
626         g_signal_connect(bt_filter, "clicked", G_CALLBACK(sctp_stat_on_filter), NULL);
627         g_signal_connect(bt_afilter, "clicked", G_CALLBACK(sctp_stat_on_apply_filter), NULL);
628         g_signal_connect(bt_analyse, "clicked", G_CALLBACK(sctp_stat_on_analyse), NULL);
629
630         sctp_stat_dlg = sctp_stat_dlg_w;
631         cf_retap_packets(&cfile);
632         gdk_window_raise(gtk_widget_get_window(sctp_stat_dlg_w));
633
634 }
635
636 static void sctp_stat_dlg_show(void)
637 {
638         if (sctp_stat_dlg != NULL)
639         {
640                 /* There's already a dialog box; reactivate it. */
641                 reactivate_window(sctp_stat_dlg);
642                 /* Another list since last call? */
643                 if ((sctp_stat_get_info()->assoc_info_list) != last_list)
644                         sctp_stat_dlg_update();
645         }
646         else
647         {
648                 /* Create and show the dialog box */
649                 gtk_sctpstat_dlg();
650                 sctp_stat_dlg_update();
651         }
652 }
653
654
655 #ifdef MAIN_MENU_USE_UIMANAGER
656 void sctp_stat_start(GtkAction *action _U_, gpointer user_data _U_)
657 #else
658 static void sctp_stat_start(GtkWidget *w _U_, gpointer data _U_)
659 #endif
660 {
661         prevent_update = FALSE;
662         filter_applied = FALSE;
663         sctp_assocs = g_malloc(sizeof(sctp_allassocs_info_t));
664         sctp_assocs = (sctp_allassocs_info_t*)sctp_stat_get_info();
665         /* Register the tap listener */
666         if (sctp_stat_get_info()->is_registered==FALSE)
667         register_tap_listener_sctp_stat();
668         /*  (redissect all packets) */
669         sctp_stat_scan();
670
671         /* Show the dialog box with the list of streams */
672         sctp_stat_dlg_show();
673 }
674
675 /****************************************************************************/
676 void
677 register_tap_listener_sctp_stat_dlg(void)
678 {
679 #ifdef MAIN_MENU_USE_UIMANAGER
680 #else
681         register_stat_menu_item("S_CTP/Show All Associations...", REGISTER_STAT_GROUP_TELEPHONY,
682             sctp_stat_start, NULL, NULL, NULL);
683 #endif
684 }
685
686
687 GtkWidget* get_stat_dlg(void)
688 {
689         return sctp_stat_dlg;
690 }