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