Add a "register_dfilter_stat()", to register stats that take a display
[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  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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
29 #include <gtk/gtk.h>
30 #include <string.h>
31
32 #include "globals.h"
33 #include "epan/filesystem.h"
34
35 #include "image/clist_ascend.xpm"
36 #include "image/clist_descend.xpm"
37
38 #include "../stat_menu.h"
39 #include "gtk_stat_menu.h"
40 #include "dlg_utils.h"
41 #include "gui_utils.h"
42 #include "main.h"
43 #include "compat_macros.h"
44
45 #include "sctp_stat.h"
46 #include "gtkglobals.h"
47
48
49 static GtkWidget *sctp_stat_dlg=NULL;
50 static GtkWidget *clist = NULL;
51 static GList *last_list = NULL;
52 static gchar *filter_string = NULL;
53 static sctp_assoc_info_t* selected_stream = NULL;  /* current selection */
54 static sctp_allassocs_info_t *sctp_assocs=NULL;
55 static guint16 n_children=0;
56 static GtkWidget *bt_afilter = NULL, *bt_unselect=NULL, *bt_analyse=NULL, *bt_filter=NULL;
57
58 #define NUM_COLS    7
59 #define FRAME_LIMIT 8
60
61 typedef struct column_arrows {
62         GtkWidget *table;
63         GtkWidget *ascend_pm;
64         GtkWidget *descend_pm;
65 } column_arrows;
66
67
68 static void
69 dlg_destroy(void)
70 {
71         guint32 i, j;
72         GList *list;
73         struct sctp_analyse *child_data;
74
75         j=n_children;
76         for (i=0; i<j; i++)
77         {
78                 list=g_list_last(sctp_assocs->children);
79                 child_data=(struct sctp_analyse *)list->data;
80                 gtk_grab_remove(GTK_WIDGET(child_data->window));
81                 gtk_widget_destroy(GTK_WIDGET(child_data->window));
82                 list=g_list_previous(list);
83         }
84         g_list_free(sctp_assocs->children);
85         sctp_assocs->children = NULL;
86         sctp_stat_dlg = NULL;
87 }
88
89 void
90 decrease_analyse_childcount()
91 {
92         n_children--;
93 }
94
95 void
96 increase_analyse_childcount()
97 {
98         n_children++;
99 }
100
101 void
102 set_analyse_child(struct sctp_analyse *child)
103 {
104         sctp_assocs->children=g_list_append(sctp_assocs->children, child);
105 }
106
107 void
108 remove_analyse_child(struct sctp_analyse *child)
109 {
110         sctp_assocs->children=g_list_remove(sctp_assocs->children, child);
111 }
112
113
114 static void add_to_clist(sctp_assoc_info_t* assinfo)
115 {
116         gint added_row, i;
117         gchar *data[NUM_COLS];
118         gchar field[NUM_COLS][30];
119
120         for (i=0; i<NUM_COLS; i++)
121                 data[i]=&field[i][0];
122
123         g_snprintf(field[0], 20, "%u", assinfo->port1);
124         g_snprintf(field[1], 20, "%u", assinfo->port2);
125         g_snprintf(field[2], 20, "%u", assinfo->n_packets);
126         g_snprintf(field[3], 20, "%s", assinfo->checksum_type);
127         g_snprintf(field[4], 20, "%u", assinfo->n_checksum_errors);
128         g_snprintf(field[5], 20, "%u", assinfo->n_data_chunks);
129         g_snprintf(field[6], 20, "%u", assinfo->n_data_bytes);
130
131         added_row = gtk_clist_append(GTK_CLIST(clist), data);
132         gtk_clist_set_row_data(GTK_CLIST(clist), added_row, assinfo);
133 }
134
135 static void
136 sctp_stat_on_unselect(GtkButton *button _U_, gpointer user_data _U_)
137 {
138         if (filter_string != NULL) {
139                 g_free(filter_string);
140                 filter_string = NULL;
141         }
142
143         selected_stream = NULL;
144         gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), "");
145         gtk_clist_unselect_all(GTK_CLIST(clist));
146         gtk_widget_set_sensitive(bt_unselect,FALSE);
147         gtk_widget_set_sensitive(bt_filter,FALSE);
148         gtk_widget_set_sensitive(bt_analyse,FALSE);
149         gtk_widget_set_sensitive(bt_afilter,FALSE);
150 }
151
152 void sctp_stat_dlg_update(void)
153 {
154         GList *list;
155
156         list=(sctp_stat_get_info()->assoc_info_list);
157         if (sctp_stat_dlg != NULL)
158         {
159                 gtk_clist_clear(GTK_CLIST(clist));
160
161                 list = g_list_first(sctp_stat_get_info()->assoc_info_list);
162
163                 while (list)
164                 {
165                         add_to_clist((sctp_assoc_info_t*)(list->data));
166                         list = g_list_next(list);
167                 }
168
169                 sctp_stat_on_unselect(NULL, NULL);
170         }
171         last_list = list;
172 }
173
174 static void
175 sctp_stat_on_select_row(GtkCList *clist, gint row, gint column _U_,
176                         GdkEventButton *event _U_, gpointer user_data _U_)
177 {
178         gchar *text[1];
179         guint16 port1, port2;
180         guint32 checksum, data_chunks, data_bytes, packets;
181         GList *list;
182         sctp_assoc_info_t* assoc;
183
184         selected_stream = gtk_clist_get_row_data(GTK_CLIST(clist), row);
185
186         gtk_clist_get_text(GTK_CLIST(clist), row, 0, text);
187         port1=atoi(text[0]);
188         gtk_clist_get_text(GTK_CLIST(clist), row, 1, text);
189         port2=atoi(text[0]);
190         gtk_clist_get_text(GTK_CLIST(clist), row, 2, text);
191         packets=atoi(text[0]);
192         gtk_clist_get_text(GTK_CLIST(clist), row, 4, text);
193         checksum=atoi(text[0]);
194         gtk_clist_get_text(GTK_CLIST(clist), row, 5, text);
195         data_chunks=atoi(text[0]);
196
197         gtk_clist_get_text(GTK_CLIST(clist), row, 6, text);
198         data_bytes=atoi(text[0]);
199
200         list = g_list_first(sctp_assocs->assoc_info_list);
201
202         while (list)
203         {
204                 assoc = (sctp_assoc_info_t*)(list->data);
205                 if (assoc->port1==port1 && assoc->port2==port2 &&
206                 assoc->n_packets==packets && assoc->n_checksum_errors==checksum
207                 && assoc->n_data_chunks==data_chunks && assoc->n_data_bytes==data_bytes)
208                 {
209                         selected_stream=assoc;
210                         break;
211                 }
212                 list=g_list_next(list);
213         }
214         gtk_widget_set_sensitive(bt_unselect,TRUE);
215         gtk_widget_set_sensitive(bt_analyse,TRUE);
216         gtk_widget_set_sensitive(bt_filter,TRUE);
217 }
218
219 static void
220 sctp_stat_on_apply_filter (GtkButton *button _U_, gpointer user_data _U_)
221 {
222         if (filter_string != NULL)
223         {
224                 main_filter_packets(&cfile, filter_string, FALSE);
225         }
226 }
227
228 static void
229 sctp_stat_on_filter (GtkButton *button _U_, gpointer user_data _U_)
230 {
231         gchar *f_string = NULL;
232         guint32 framenumber=0;
233         GList *list, *srclist, *dstlist;
234         gchar *str=NULL;
235         GString *gstring=NULL;
236         struct sockaddr_in *infosrc=NULL;
237         struct sockaddr_in *infodst=NULL;
238
239         if (selected_stream==NULL) {
240                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), "");
241                 return;
242         }
243
244         if (selected_stream->n_packets>FRAME_LIMIT)
245         {
246                 if (selected_stream->check_address==FALSE)
247                 {
248                         f_string = g_strdup_printf("((sctp.srcport==%u && sctp.dstport==%u && ((sctp.verification_tag==0x%x && sctp.verification_tag!=0x0) || "
249                                                    "(sctp.verification_tag==0x0 && sctp.initiate_tag==0x%x) || "
250                                                    "(sctp.verification_tag==0x%x && (sctp.abort_t_bit==1 || sctp.shutdown_complete_t_bit==1)))) ||"
251                                                    "(sctp.srcport==%u && sctp.dstport==%u && ((sctp.verification_tag==0x%x && sctp.verification_tag!=0x0) || "
252                                                    "(sctp.verification_tag==0x0 && sctp.initiate_tag==0x%x) ||"
253                                                    "(sctp.verification_tag==0x%x && (sctp.abort_t_bit==1 || sctp.shutdown_complete_t_bit==1)))))",
254                         selected_stream->port1,
255                         selected_stream->port2,
256                         selected_stream->verification_tag1,
257                         selected_stream->verification_tag2,
258                         selected_stream->verification_tag2,
259                         selected_stream->port2,
260                         selected_stream->port1,
261                         selected_stream->verification_tag2,
262                         selected_stream->verification_tag1,
263                         selected_stream->verification_tag1);
264                         filter_string = f_string;
265                 }
266                 else
267                 {
268                         srclist = g_list_first(selected_stream->addr1);
269                         infosrc=(struct sockaddr_in *) (srclist->data);
270                         gstring = g_string_new(g_strdup_printf("((sctp.srcport==%u && sctp.dstport==%u && (ip.src==%s",
271                                 selected_stream->port1, selected_stream->port2, ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr))));
272                         srclist= g_list_next(srclist);
273
274                         while (srclist)
275                         {
276                                 infosrc=(struct sockaddr_in *) (srclist->data);
277                                 str =g_strdup_printf("|| ip.src==%s",ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr)));
278                                 g_string_append(gstring, str);
279                                 srclist= g_list_next(srclist);
280                         }
281
282                         dstlist = g_list_first(selected_stream->addr2);
283                         infodst=(struct sockaddr_in *) (dstlist->data);
284                         str = g_strdup_printf(") && (ip.dst==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
285                         g_string_append(gstring, str);
286                         dstlist= g_list_next(dstlist);
287                         while (dstlist)
288                         {
289                                 infodst=(struct sockaddr_in *) (dstlist->data);
290                                 str =g_strdup_printf("|| ip.dst==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
291                                 g_string_append(gstring, str);
292                                 dstlist= g_list_next(dstlist);
293                         }
294
295                         srclist = g_list_first(selected_stream->addr1);
296                         infosrc=(struct sockaddr_in *) (srclist->data);
297                         str = g_strdup_printf(")) || (sctp.dstport==%u && sctp.srcport==%u && (ip.dst==%s",
298                                 selected_stream->port1, selected_stream->port2, ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr)));
299                         g_string_append(gstring, str);
300                         srclist= g_list_next(srclist);
301
302                         while (srclist)
303                         {
304                                 infosrc=(struct sockaddr_in *) (srclist->data);
305                                 str =g_strdup_printf("|| ip.dst==%s",ip_to_str((const guint8 *)&(infosrc->sin_addr.s_addr)));
306                                 g_string_append(gstring, str);
307                                 srclist= g_list_next(srclist);
308                         }
309
310                         dstlist = g_list_first(selected_stream->addr2);
311                         infodst=(struct sockaddr_in *) (dstlist->data);
312                         str = g_strdup_printf(") && (ip.src==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
313                         g_string_append(gstring, str);
314                         dstlist= g_list_next(dstlist);
315                         while (dstlist)
316                         {
317                                 infodst=(struct sockaddr_in *) (dstlist->data);
318                                 str =g_strdup_printf("|| ip.src==%s",ip_to_str((const guint8 *)&(infodst->sin_addr.s_addr)));
319                                 g_string_append(gstring, str);
320                                 dstlist= g_list_next(dstlist);
321                         }
322                         str = g_strdup_printf(")))");
323                         g_string_append(gstring, str);
324                         filter_string = gstring->str;
325                         g_string_free(gstring,FALSE);
326                 }
327         }
328         else
329         {
330                 list = g_list_first(selected_stream->frame_numbers);
331                 framenumber = *((guint32 *)(list->data));
332                 gstring = g_string_new(g_strdup_printf("frame.number==%u",framenumber));
333                 list = g_list_next(list);
334                 while (list)
335                 {
336                         framenumber = *((guint32 *)(list->data));
337                         str =g_strdup_printf(" || frame.number==%u",framenumber);
338                         g_string_append(gstring, str);
339                         list = g_list_next(list);
340                 }
341                 filter_string = gstring->str;
342                 g_string_free(gstring,FALSE);
343         }
344         
345         if (filter_string != NULL) {
346                 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
347         } else {
348                 g_assert_not_reached();
349         }
350         gtk_widget_set_sensitive(bt_afilter,TRUE);
351 }
352
353
354 static void
355 sctp_stat_on_close (GtkButton *button _U_, gpointer user_data _U_)
356 {
357         gtk_grab_remove(sctp_stat_dlg);
358         gtk_widget_destroy(sctp_stat_dlg);
359 }
360
361 static void
362 sctp_stat_on_analyse (GtkButton *button _U_, gpointer user_data _U_)
363 {
364         if (selected_stream==NULL)
365                 return;
366
367         if (selected_stream)
368                 assoc_analyse(selected_stream);
369         gtk_widget_set_sensitive(bt_analyse,FALSE);
370 }
371
372 static gint
373 clist_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
374 {
375         char *text1 = NULL;
376         char *text2 = NULL;
377         int i1, i2;
378
379         GtkCListRow *row1 = (GtkCListRow *) ptr1;
380         GtkCListRow *row2 = (GtkCListRow *) ptr2;
381
382         text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
383         text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
384
385         switch(clist->sort_column){
386         case 0:
387         case 2:
388                 return strcmp (text1, text2);
389         case 1:
390         case 3:
391         case 4:
392         case 5:
393         case 6:
394         case 7:
395                 i1=atoi(text1);
396                 i2=atoi(text2);
397                 return i1-i2;
398         }
399         g_assert_not_reached();
400         return 0;
401 }
402
403 static void
404 clist_click_column_cb(GtkCList *list, gint column, gpointer data)
405 {
406         column_arrows *col_arrows = (column_arrows *) data;
407         int i;
408         gtk_clist_freeze(list);
409
410         for (i = 0; i < NUM_COLS; i++) {
411                 gtk_widget_hide(col_arrows[i].ascend_pm);
412                 gtk_widget_hide(col_arrows[i].descend_pm);
413         }
414
415         if (column == list->sort_column) {
416                 if (list->sort_type == GTK_SORT_ASCENDING) {
417                         list->sort_type = GTK_SORT_DESCENDING;
418                         gtk_widget_show(col_arrows[column].descend_pm);
419                 } else {
420                         list->sort_type = GTK_SORT_ASCENDING;
421                         gtk_widget_show(col_arrows[column].ascend_pm);
422                 }
423         } else {
424                 list->sort_type = GTK_SORT_DESCENDING;
425                 gtk_widget_show(col_arrows[column].descend_pm);
426                 gtk_clist_set_sort_column(list, column);
427         }
428         gtk_clist_thaw(list);
429
430         gtk_clist_sort(list);
431 }
432
433 static void
434 gtk_sctpstat_dlg(void)
435 {
436         GtkWidget *sctp_stat_dlg_w;
437         GtkWidget *vbox1;
438         GtkWidget *scrolledwindow1;
439         GtkWidget *hbuttonbox2;
440         GtkWidget *bt_close;
441
442         const gchar *titles[NUM_COLS] =  {"Port 1","Port 2", "No of Packets", "Checksum", "No of Errors", "Data Chunks", "Data Bytes"};
443         column_arrows *col_arrows;
444         GdkBitmap *ascend_bm, *descend_bm;
445         GdkPixmap *ascend_pm, *descend_pm;
446         GtkStyle *win_style;
447         GtkWidget *column_lb;
448         gint i;
449
450         sctp_stat_dlg_w = window_new (GTK_WINDOW_TOPLEVEL, "Ethereal: SCTP Associations");
451         gtk_window_set_position (GTK_WINDOW (sctp_stat_dlg_w), GTK_WIN_POS_CENTER);
452         SIGNAL_CONNECT(sctp_stat_dlg_w, "destroy", dlg_destroy,NULL);
453
454         /* Container for each row of widgets */
455         vbox1 = gtk_vbox_new(FALSE, 2);
456         gtk_container_border_width(GTK_CONTAINER(vbox1), 8);
457         gtk_container_add(GTK_CONTAINER(sctp_stat_dlg_w), vbox1);
458         gtk_widget_show(vbox1);
459
460         scrolledwindow1 = scrolled_window_new (NULL, NULL);
461         gtk_widget_show (scrolledwindow1);
462         gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
463
464         clist = gtk_clist_new (NUM_COLS);
465         gtk_widget_show (clist);
466         gtk_container_add (GTK_CONTAINER (scrolledwindow1), clist);
467         WIDGET_SET_SIZE(clist, 700, 200);
468
469         gtk_clist_set_column_width (GTK_CLIST (clist), 0, 50);
470         gtk_clist_set_column_width (GTK_CLIST (clist), 1, 50);
471         gtk_clist_set_column_width (GTK_CLIST (clist), 2, 100);
472         gtk_clist_set_column_width (GTK_CLIST (clist), 3, 100);
473         gtk_clist_set_column_width (GTK_CLIST (clist), 4, 100);
474         gtk_clist_set_column_width (GTK_CLIST (clist), 5, 100);
475         gtk_clist_set_column_width (GTK_CLIST (clist), 6, 100);
476
477
478         gtk_clist_set_column_justification(GTK_CLIST(clist), 0, GTK_JUSTIFY_CENTER);
479         gtk_clist_set_column_justification(GTK_CLIST(clist), 1, GTK_JUSTIFY_CENTER);
480         gtk_clist_set_column_justification(GTK_CLIST(clist), 2, GTK_JUSTIFY_CENTER);
481         gtk_clist_set_column_justification(GTK_CLIST(clist), 3, GTK_JUSTIFY_CENTER);
482         gtk_clist_set_column_justification(GTK_CLIST(clist), 4, GTK_JUSTIFY_CENTER);
483         gtk_clist_set_column_justification(GTK_CLIST(clist), 5, GTK_JUSTIFY_CENTER);
484         gtk_clist_set_column_justification(GTK_CLIST(clist), 6, GTK_JUSTIFY_CENTER);
485         gtk_clist_column_titles_show (GTK_CLIST (clist));
486
487         gtk_clist_set_compare_func(GTK_CLIST(clist), clist_sort_column);
488         gtk_clist_set_sort_column(GTK_CLIST(clist), 0);
489         gtk_clist_set_sort_type(GTK_CLIST(clist), GTK_SORT_ASCENDING);
490
491         gtk_widget_show(sctp_stat_dlg_w);
492
493         col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_COLS);
494         win_style = gtk_widget_get_style(scrolledwindow1);
495
496         ascend_pm = gdk_pixmap_create_from_xpm_d(scrolledwindow1->window,
497                                                  &ascend_bm,
498                                                  &win_style->bg[GTK_STATE_NORMAL],
499                                                  (gchar **)clist_ascend_xpm);
500         descend_pm = gdk_pixmap_create_from_xpm_d(scrolledwindow1->window,
501                                                   &descend_bm,
502                                                   &win_style->bg[GTK_STATE_NORMAL],
503                                                   (gchar **)clist_descend_xpm);
504         for (i=0; i<NUM_COLS; i++)
505         {
506                 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
507                 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
508                 column_lb = gtk_label_new(titles[i]);
509                 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
510                 gtk_widget_show(column_lb);
511                 col_arrows[i].ascend_pm = gtk_pixmap_new(ascend_pm, ascend_bm);
512                 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
513                 col_arrows[i].descend_pm = gtk_pixmap_new(descend_pm, descend_bm);
514                 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
515                 /* make src-ip be the default sort order */
516                 if (i == 0)
517                 {
518                         gtk_widget_show(col_arrows[i].ascend_pm);
519                 }
520
521                 gtk_clist_set_column_widget(GTK_CLIST(clist), i, col_arrows[i].table);
522                 gtk_widget_show(col_arrows[i].table);
523         }
524
525         SIGNAL_CONNECT(clist, "click-column", clist_click_column_cb, col_arrows);
526
527         hbuttonbox2 = gtk_hbutton_box_new();
528         gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox2, FALSE, FALSE, 0);
529         gtk_container_set_border_width(GTK_CONTAINER(hbuttonbox2), 10);
530         gtk_button_box_set_layout(GTK_BUTTON_BOX (hbuttonbox2), GTK_BUTTONBOX_SPREAD);
531         gtk_button_box_set_spacing(GTK_BUTTON_BOX (hbuttonbox2), 0);
532         gtk_button_box_set_child_ipadding(GTK_BUTTON_BOX (hbuttonbox2), 4, 0);
533         gtk_widget_show(hbuttonbox2);
534
535         bt_unselect = gtk_button_new_with_label ("Unselect");
536         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_unselect);
537         gtk_widget_show (bt_unselect);
538         gtk_widget_set_sensitive(bt_unselect,FALSE);
539
540         bt_filter = gtk_button_new_with_label ("Set filter");
541         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_filter);
542         gtk_widget_show (bt_filter);
543         gtk_widget_set_sensitive(bt_filter,FALSE);
544
545         bt_afilter = gtk_button_new_with_label ("Apply filter");
546         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_afilter);
547         gtk_widget_show (bt_afilter);
548         gtk_widget_set_sensitive(bt_afilter,FALSE);
549
550         bt_analyse = gtk_button_new_with_label ("Analyse");
551         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_analyse);
552         gtk_widget_show (bt_analyse);
553         gtk_widget_set_sensitive(bt_analyse,FALSE);
554
555         bt_close = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
556         gtk_container_add (GTK_CONTAINER (hbuttonbox2), bt_close);
557         gtk_widget_show (bt_close);
558
559         SIGNAL_CONNECT(sctp_stat_dlg_w, "destroy", dlg_destroy, NULL);
560         SIGNAL_CONNECT(clist, "select_row", sctp_stat_on_select_row, NULL);
561         SIGNAL_CONNECT(bt_unselect, "clicked", sctp_stat_on_unselect, NULL);
562         SIGNAL_CONNECT(bt_filter, "clicked", sctp_stat_on_filter, NULL);
563         SIGNAL_CONNECT(bt_afilter, "clicked", sctp_stat_on_apply_filter, NULL);
564         SIGNAL_CONNECT(bt_analyse, "clicked", sctp_stat_on_analyse, NULL);
565         SIGNAL_CONNECT(bt_close, "clicked", sctp_stat_on_close, NULL);
566
567         sctp_stat_dlg = sctp_stat_dlg_w;
568         cf_retap_packets(&cfile);
569
570 }
571
572 static void sctp_stat_dlg_show(void)
573 {
574         if (sctp_stat_dlg != NULL)
575         {
576                 /* There's already a dialog box; reactivate it. */
577                 reactivate_window(sctp_stat_dlg);
578                 /* Another list since last call? */
579                 if ((sctp_stat_get_info()->assoc_info_list) != last_list)
580                         sctp_stat_dlg_update();
581         }
582         else
583         {
584                 /* Create and show the dialog box */
585                 gtk_sctpstat_dlg();
586                 sctp_stat_dlg_update();
587         }
588 }
589
590
591 static void sctp_stat_start(GtkWidget *w _U_, gpointer data _U_)
592 {
593
594         sctp_assocs = g_malloc(sizeof(sctp_allassocs_info_t));
595         sctp_assocs = (sctp_allassocs_info_t*)sctp_stat_get_info();
596         /* Register the tap listener */
597         if (sctp_stat_get_info()->is_registered==FALSE)
598         register_tap_listener_sctp_stat();
599         /*  (redissect all packets) */
600         sctp_stat_scan();
601
602         /* Show the dialog box with the list of streams */
603         /* sctp_stat_dlg_show(sctp_stat_get_info()->assoc_info_list); */
604         sctp_stat_dlg_show();
605 }
606
607 /****************************************************************************/
608 void
609 register_tap_listener_sctp_stat_dlg(void)
610 {
611         register_stat_menu_item("SCTP/Show All Associations...", REGISTER_STAT_GROUP_TELEPHONY,
612             sctp_stat_start, NULL, NULL, NULL);
613 }
614
615
616 GtkWidget* get_stat_dlg(void)
617 {
618         return sctp_stat_dlg;
619 }