Avoid calling some free() on WIN32 on memory that may be allocated in
[obnox/wireshark/wip.git] / gtk / mcast_stream_dlg.c
1 /* mcast_stream_dlg.c
2  *
3  * Copyright 2006, Iskratel , Slovenia
4  * By Jakob Bratkovic <j.bratkovic@iskratel.si> and
5  * Miha Jemec <m.jemec@iskratel.si>
6  *
7  * $Id$
8  *
9  * based on rtp_stream_dlg.c
10  * Copyright 2003, Alcatel Business Systems
11  * By Lars Ruoff <lars.ruoff@gmx.net>
12  *
13  * Wireshark - Network traffic analyzer
14  * By Gerald Combs <gerald@wireshark.org>
15  * Copyright 1998 Gerald Combs
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License
19  * as published by the Free Software Foundation; either version 2
20  * of the License, or (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation,  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
30  */
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #include "mcast_stream_dlg.h"
37 #include "mcast_stream.h"
38
39 #include "globals.h"
40 #include "epan/filesystem.h"
41
42 #include "../stat_menu.h"
43 #include "gui_stat_menu.h"
44 #include "dlg_utils.h"
45 #include "gui_utils.h"
46 #include "compat_macros.h"
47 #include "gtkglobals.h"
48 #include "simple_dialog.h"
49
50 #include "image/clist_ascend.xpm"
51 #include "image/clist_descend.xpm"
52
53 #include <epan/address.h>
54
55 #include <string.h>
56 #include <locale.h>
57 #include <epan/addr_resolv.h>
58 #include <epan/strutil.h>
59
60 /* Capture callback data keys */
61 #define E_MCAST_ENTRY_1     "burst_interval"
62 #define E_MCAST_ENTRY_2     "burst_alarm"
63 #define E_MCAST_ENTRY_3     "buffer_alarm"
64 #define E_MCAST_ENTRY_4     "stream_speed"
65 #define E_MCAST_ENTRY_5     "total_speed"
66
67 extern guint16 burstint;
68 extern guint32 trigger;
69 extern guint32 bufferalarm;
70 extern gint32 emptyspeed;
71 extern gint32 cumulemptyspeed; 
72
73 static const gchar FWD_LABEL_TEXT[] = "Select a stream with left mouse button";
74 static const gchar PAR_LABEL_TEXT[] = "\nBurst int: ms   Burst alarm: pps    Buffer alarm: KB    Stream empty speed: Mbps    Total empty speed: Mbps\n";
75
76 /****************************************************************************/
77 static GtkWidget *mcast_stream_dlg = NULL;
78 static GtkWidget *mcast_params_dlg = NULL;
79
80 static GtkWidget *clist = NULL;
81 static GtkWidget *top_label = NULL;
82 static GtkWidget *label_fwd = NULL;
83 static GtkWidget *label_par = NULL;
84
85 static mcast_stream_info_t* selected_stream_fwd = NULL;  /* current selection */
86 static GList *last_list = NULL;
87
88 static guint32 streams_nb = 0;     /* number of displayed streams */
89
90 #define NUM_COLS 12
91 static const gchar *titles[NUM_COLS] =  {"Src IP addr", "Src port",  "Dst IP addr", "Dst port", "Packets", "Packets/s", "Avg Bw", "Max Bw", "Max burst", "Burst Alarms", "Max buffer", "Buff Alarms"};
92
93 /****************************************************************************/
94 /* append a line to clist */
95 static void add_to_clist(mcast_stream_info_t* strinfo)
96 {
97         gchar label_text[256];
98         gint added_row;
99         gchar *data[NUM_COLS];
100         int i;
101         char *savelocale;
102
103         /* save the current locale */
104         savelocale = setlocale(LC_NUMERIC, NULL);
105         /* switch to "C" locale to avoid problems with localized decimal separators
106                 in g_snprintf("%f") functions */
107         setlocale(LC_NUMERIC, "C");
108         data[0] = g_strdup(get_addr_name(&(strinfo->src_addr)));
109         data[1] = g_strdup_printf("%u", strinfo->src_port);
110         data[2] = g_strdup(get_addr_name(&(strinfo->dest_addr)));
111         data[3] = g_strdup_printf("%u", strinfo->dest_port);
112         data[4] = g_strdup_printf("%u", strinfo->npackets);
113         data[5] = g_strdup_printf("%u /s", strinfo->apackets);
114         data[6] = g_strdup_printf("%2.1f Mbps", strinfo->average_bw);
115         data[7] = g_strdup_printf("%2.1f Mbps", strinfo->element.maxbw);
116         data[8] = g_strdup_printf("%u / %dms", strinfo->element.topburstsize, burstint);
117         data[9] = g_strdup_printf("%u", strinfo->element.numbursts);
118         data[10] = g_strdup_printf("%.1f KB", (float)strinfo->element.topbuffusage/1000);
119         data[11] = g_strdup_printf("%u", strinfo->element.numbuffalarms);
120
121         /* restore previous locale setting */
122         setlocale(LC_NUMERIC, savelocale);
123
124         added_row = gtk_clist_append(GTK_CLIST(clist), data);
125         for (i = 0; i < NUM_COLS; i++)
126                 g_free(data[i]);
127
128         /* set data pointer of last row to point to user data for that row */
129         gtk_clist_set_row_data(GTK_CLIST(clist), added_row, strinfo);
130
131         /* Update the top label with the number of detected streams */
132         g_snprintf(label_text, 256,
133                 "Detected %d Multicast streams,   Average Bw: %.1f Mbps   Max Bw: %.1f Mbps   Max burst: %d / %dms   Max buffer: %.1f KB",
134                 ++streams_nb, 
135                 mcaststream_get_info()->allstreams->average_bw, mcaststream_get_info()->allstreams->element.maxbw, 
136                 mcaststream_get_info()->allstreams->element.topburstsize, burstint, 
137                 (float)(mcaststream_get_info()->allstreams->element.topbuffusage)/1000);
138         gtk_label_set(GTK_LABEL(top_label), label_text);
139
140         g_snprintf(label_text, 200, "\nBurst int: %u ms   Burst alarm: %u pps   Buffer alarm: %u Bytes   Stream empty speed: %u Kbps   Total empty speed: %u Kbps\n", 
141                 burstint, trigger, bufferalarm, emptyspeed, cumulemptyspeed);
142         gtk_label_set_text(GTK_LABEL(label_par), label_text);
143 }
144
145 /****************************************************************************/
146 /* CALLBACKS                                                                */
147 /****************************************************************************/
148 static void
149 mcaststream_on_destroy                      (GtkObject       *object _U_,
150                                         gpointer         user_data _U_)
151 {
152         /* Remove the stream tap listener */
153         remove_tap_listener_mcast_stream();
154
155         /* Is there a params window open? */
156         if (mcast_params_dlg != NULL)
157                 window_destroy(mcast_params_dlg);
158
159         /* Clean up memory used by stream tap */
160         mcaststream_reset((mcaststream_tapinfo_t*) mcaststream_get_info());
161
162         /* Note that we no longer have a "Mcast Streams" dialog box. */
163         mcast_stream_dlg = NULL;
164 }
165
166
167 /****************************************************************************/
168 static void
169 mcaststream_on_unselect                  (GtkButton       *button _U_,
170                                         gpointer         user_data _U_)
171 {
172         selected_stream_fwd = NULL;
173         gtk_clist_unselect_all(GTK_CLIST(clist));
174         gtk_label_set_text(GTK_LABEL(label_fwd), FWD_LABEL_TEXT);
175 }
176
177
178 /****************************************************************************/
179 static void
180 mcaststream_on_filter                    (GtkButton       *button _U_,
181                                         gpointer         user_data _U_)
182 {
183         gchar *filter_string = NULL;
184         gchar *filter_string_fwd = NULL;
185         gchar ip_version[3];
186
187         if (selected_stream_fwd==NULL)
188                 return;
189
190         if (selected_stream_fwd)
191         {
192                 if (selected_stream_fwd->src_addr.type==AT_IPv6){
193                         g_strlcpy(ip_version,"v6",3);
194                 }               
195                 else{
196                         ip_version[0] = '\0';
197                 }
198                 filter_string_fwd = g_strdup_printf(
199                         "(ip%s.src==%s && udp.srcport==%u && ip%s.dst==%s && udp.dstport==%u)",
200                         ip_version,
201                         address_to_str(&(selected_stream_fwd->src_addr)),
202                         selected_stream_fwd->src_port,
203                         ip_version,
204                         address_to_str(&(selected_stream_fwd->dest_addr)),
205                         selected_stream_fwd->dest_port);
206         filter_string = filter_string_fwd;
207         }
208
209         gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
210         g_free(filter_string);
211
212 /*
213         main_filter_packets(&cfile, filter_string, FALSE);
214         mcaststream_dlg_update(mcaststream_get_info()->strinfo_list);
215 */
216 }
217
218
219 /****************************************************************************/
220 /* when the user selects a row in the stream list */
221 static void
222 mcaststream_on_select_row(GtkCList *clist,
223                                             gint row _U_,
224                                             gint column _U_,
225                                             GdkEventButton *event _U_,
226                                             gpointer user_data _U_)
227 {
228         gchar label_text[80];
229
230         selected_stream_fwd = gtk_clist_get_row_data(GTK_CLIST(clist), row);
231         g_snprintf(label_text, 80, "Selected: %s:%u -> %s:%u",
232                         get_addr_name(&(selected_stream_fwd->src_addr)),
233                         selected_stream_fwd->src_port,
234                         get_addr_name(&(selected_stream_fwd->dest_addr)),
235                         selected_stream_fwd->dest_port
236         );
237         gtk_label_set_text(GTK_LABEL(label_fwd), label_text);
238
239 /*
240         gtk_widget_set_sensitive(filter_bt, TRUE);
241 */
242         /* TODO: activate other buttons when implemented */
243 }
244
245
246 /****************************************************************************/
247 typedef struct column_arrows {
248         GtkWidget *table;
249         GtkWidget *ascend_pm;
250         GtkWidget *descend_pm;
251 } column_arrows;
252
253
254 /****************************************************************************/
255 static void
256 mcaststream_click_column_cb(GtkCList *clist, gint column, gpointer data)
257 {
258         column_arrows *col_arrows = (column_arrows *) data;
259         int i;
260
261         gtk_clist_freeze(clist);
262
263         for (i=0; i<NUM_COLS; i++) {
264                 gtk_widget_hide(col_arrows[i].ascend_pm);
265                 gtk_widget_hide(col_arrows[i].descend_pm);
266         }
267
268         if (column == clist->sort_column) {
269                 if (clist->sort_type == GTK_SORT_ASCENDING) {
270                         clist->sort_type = GTK_SORT_DESCENDING;
271                         gtk_widget_show(col_arrows[column].descend_pm);
272                 } else {
273                         clist->sort_type = GTK_SORT_ASCENDING;
274                         gtk_widget_show(col_arrows[column].ascend_pm);
275                 }
276         } else {
277                 clist->sort_type = GTK_SORT_ASCENDING;
278                 gtk_widget_show(col_arrows[column].ascend_pm);
279                 gtk_clist_set_sort_column(clist, column);
280         }
281         gtk_clist_thaw(clist);
282
283         gtk_clist_sort(clist);
284 }
285
286
287 /****************************************************************************/
288 static gint
289 mcaststream_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
290 {
291         char *text1 = NULL;
292         char *text2 = NULL;
293         int i1, i2;
294
295         const GtkCListRow *row1 = (const GtkCListRow *) ptr1;
296         const GtkCListRow *row2 = (const GtkCListRow *) ptr2;
297
298         text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
299         text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
300
301         switch(clist->sort_column){
302         case 0:
303         case 2:
304                 return strcmp (text1, text2);
305         case 1:
306         case 3:
307         case 4:
308         case 5:
309         case 6:
310         case 7:
311         case 8:
312         case 9:
313         case 10:
314         case 11:
315                 i1=atoi(text1);
316                 i2=atoi(text2);
317                 return i1-i2;
318         }
319         g_assert_not_reached();
320         return 0;
321 }
322
323
324 /****************************************************************************/
325 /* INTERFACE                                                                */
326 /****************************************************************************/
327 static void mcast_params_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
328 {
329         /* Note that we no longer have a mcast params dialog box. */
330         mcast_params_dlg = NULL;
331 }
332
333
334 static void
335 mcast_params_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w)
336 {
337         GtkWidget   *fnumber_te;
338         const gchar *fnumber_text;
339         gint32        fnumber;
340         char        *p;
341
342         fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_MCAST_ENTRY_1);
343         fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
344         fnumber = strtoul(fnumber_text, &p, 10);
345         if ( (p == fnumber_text || *p != '\0') || (fnumber <=0) || (fnumber > 1000) ){
346                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The burst interval should be between 1 and 1000 ms ");
347                 return; }
348         burstint = fnumber;
349
350         fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_MCAST_ENTRY_2);
351         fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
352         fnumber = strtoul(fnumber_text, &p, 10);
353         if ( (p == fnumber_text || *p != '\0') || (fnumber <=0) ){
354                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The burst alarm threshold you entered isn't valid.");
355                 return; }
356         trigger = fnumber;
357
358         fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_MCAST_ENTRY_3);
359         fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
360         fnumber = strtoul(fnumber_text, &p, 10);
361         if ( (p == fnumber_text || *p != '\0') || (fnumber <=0) ){
362                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The buffer alarm treshold you entered isn't valid.");
363                 return; }
364         bufferalarm = fnumber;
365
366         fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_MCAST_ENTRY_4);
367         fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
368         fnumber = strtoul(fnumber_text, &p, 10);
369         if ( (p == fnumber_text || *p != '\0') || (fnumber <=0) || (fnumber > 10000000) ){
370                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The stream empty speed should be between 1 and 10000000");
371                 return; }
372         emptyspeed = fnumber;
373
374         fnumber_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, E_MCAST_ENTRY_5);
375         fnumber_text = gtk_entry_get_text(GTK_ENTRY(fnumber_te));
376         fnumber = strtoul(fnumber_text, &p, 10);
377         if ( (p == fnumber_text || *p != '\0') || (fnumber <=0) || (fnumber > 10000000) ){
378                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The total empty speed should be between 1 and 10000000");
379                 return; }
380         cumulemptyspeed = fnumber; 
381
382         window_destroy(GTK_WIDGET(parent_w));
383
384         /* Clean up memory used by stream tap */
385         mcaststream_reset((mcaststream_tapinfo_t*) mcaststream_get_info());
386         /* retap all packets */
387         cf_retap_packets(&cfile, FALSE);
388
389 }
390
391
392
393 static void
394 mcast_on_params                      (GtkButton       *button _U_,
395                                         gpointer         data _U_)
396 {
397         GtkWidget *main_vb;
398         GtkWidget *label, *hbuttonbox, *table;
399         GtkWidget *ok_bt, *cancel_bt;
400         GtkWidget *entry1, *entry2, *entry3, *entry4, *entry5;
401         gchar label_text[51];
402
403         if (mcast_params_dlg != NULL) {
404                 /* There's already a Params dialog box; reactivate it. */
405                 reactivate_window(mcast_params_dlg);
406                 return;
407         }
408
409         mcast_params_dlg = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Set parameters for Multicast Stream Analysis");
410         gtk_window_set_default_size(GTK_WINDOW(mcast_params_dlg), 210, 210);
411
412         gtk_widget_show(mcast_params_dlg);
413         
414         /* Container for each row of widgets */
415         main_vb = gtk_vbox_new(FALSE, 3);
416         gtk_container_border_width(GTK_CONTAINER(main_vb), 2);
417         gtk_container_add(GTK_CONTAINER(mcast_params_dlg), main_vb);
418         gtk_widget_show(main_vb);
419
420         table = gtk_table_new (6, 2, FALSE);
421         gtk_container_add (GTK_CONTAINER (main_vb), table);
422
423         label = gtk_label_new("  Burst measurement interval (ms)  ");
424         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
425         entry1 = gtk_entry_new();
426         g_snprintf(label_text, 50, "%u", burstint);
427         gtk_entry_set_text(GTK_ENTRY(entry1), label_text);
428         gtk_table_attach_defaults(GTK_TABLE(table), entry1, 1, 2, 0, 1);
429         label = gtk_label_new("  Burst alarm treshold (packets)   ");
430         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
431         entry2 = gtk_entry_new();
432         g_snprintf(label_text, 50, "%u", trigger);
433         gtk_entry_set_text(GTK_ENTRY(entry2), label_text);
434         gtk_table_attach_defaults(GTK_TABLE(table), entry2, 1, 2, 1, 2);
435         label = gtk_label_new("  Buffer alarm treshold (bytes)     ");
436         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
437         entry3 = gtk_entry_new();
438         g_snprintf(label_text, 50, "%u", bufferalarm);
439         gtk_entry_set_text(GTK_ENTRY(entry3), label_text);
440         gtk_table_attach_defaults(GTK_TABLE(table), entry3, 1, 2, 2, 3);
441         label = gtk_label_new("  Stream empty speed (kbit/s)      ");
442         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
443         entry4 = gtk_entry_new();
444         g_snprintf(label_text, 50, "%u", emptyspeed);
445         gtk_entry_set_text(GTK_ENTRY(entry4), label_text);
446         gtk_table_attach_defaults(GTK_TABLE(table), entry4, 1, 2, 3, 4);
447         label = gtk_label_new("  Total empty speed (kbit/s)       ");
448         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5);
449         entry5 = gtk_entry_new();
450         g_snprintf(label_text, 50, "%u", cumulemptyspeed);
451         gtk_entry_set_text(GTK_ENTRY(entry5), label_text);
452         gtk_table_attach_defaults(GTK_TABLE(table), entry5, 1, 2, 4, 5);
453
454         gtk_widget_show (table);
455
456         /* button row */
457         hbuttonbox = gtk_hbutton_box_new ();
458         gtk_table_attach_defaults(GTK_TABLE(table), hbuttonbox, 0, 2, 5, 6);
459         ok_bt = BUTTON_NEW_FROM_STOCK(GTK_STOCK_OK);
460         gtk_container_add (GTK_CONTAINER (hbuttonbox), ok_bt);
461         cancel_bt = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CANCEL);
462         gtk_container_add (GTK_CONTAINER (hbuttonbox), cancel_bt);
463         GTK_WIDGET_SET_FLAGS(cancel_bt, GTK_CAN_DEFAULT);
464         gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
465         gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox), 0);
466         
467         SIGNAL_CONNECT(mcast_params_dlg, "delete_event", window_delete_event_cb, NULL);
468         SIGNAL_CONNECT(mcast_params_dlg, "destroy", mcast_params_destroy_cb, NULL);
469         SIGNAL_CONNECT(ok_bt, "clicked", mcast_params_ok_cb, mcast_params_dlg);
470         window_set_cancel_button(mcast_params_dlg, cancel_bt, window_cancel_button_cb);
471
472         /* Attach pointers to needed widgets */
473         OBJECT_SET_DATA(mcast_params_dlg, E_MCAST_ENTRY_1, entry1);
474         OBJECT_SET_DATA(mcast_params_dlg, E_MCAST_ENTRY_2, entry2);
475         OBJECT_SET_DATA(mcast_params_dlg, E_MCAST_ENTRY_3, entry3);
476         OBJECT_SET_DATA(mcast_params_dlg, E_MCAST_ENTRY_4, entry4);
477         OBJECT_SET_DATA(mcast_params_dlg, E_MCAST_ENTRY_5, entry5);
478
479         gtk_widget_show_all(mcast_params_dlg);
480         window_present(mcast_params_dlg);
481 }
482
483
484
485 static void mcaststream_dlg_create (void)
486 {
487     GtkWidget *mcaststream_dlg_w;
488     GtkWidget *main_vb;
489     GtkWidget *scrolledwindow;
490     GtkWidget *hbuttonbox;
491     /*GtkWidget *bt_unselect;*/
492     GtkWidget *bt_filter;
493     GtkWidget *bt_params;
494     GtkWidget *bt_close;
495     GtkTooltips *tooltips = gtk_tooltips_new();
496
497     column_arrows *col_arrows;
498     GtkWidget *column_lb;
499     int i;
500
501     mcaststream_dlg_w = dlg_window_new("Wireshark: Multicast Streams");
502     gtk_window_set_default_size(GTK_WINDOW(mcaststream_dlg_w), 620, 400);
503
504     main_vb = gtk_vbox_new (FALSE, 0);
505     gtk_container_add(GTK_CONTAINER(mcaststream_dlg_w), main_vb);
506     gtk_container_set_border_width (GTK_CONTAINER (main_vb), 12);
507
508     top_label = gtk_label_new ("Detected 0 Multicast streams");
509     gtk_box_pack_start (GTK_BOX (main_vb), top_label, FALSE, FALSE, 8);
510
511     scrolledwindow = scrolled_window_new (NULL, NULL);
512     gtk_box_pack_start (GTK_BOX (main_vb), scrolledwindow, TRUE, TRUE, 0);
513
514     clist = gtk_clist_new (NUM_COLS);
515     gtk_container_add (GTK_CONTAINER (scrolledwindow), clist);
516
517     gtk_clist_set_column_width (GTK_CLIST (clist), 0, 95);
518     gtk_clist_set_column_width (GTK_CLIST (clist), 1, 55);
519     gtk_clist_set_column_width (GTK_CLIST (clist), 2, 95);
520     gtk_clist_set_column_width (GTK_CLIST (clist), 3, 55);
521     gtk_clist_set_column_width (GTK_CLIST (clist), 4, 70);
522     gtk_clist_set_column_width (GTK_CLIST (clist), 5, 70);
523     gtk_clist_set_column_width (GTK_CLIST (clist), 6, 60);
524     gtk_clist_set_column_width (GTK_CLIST (clist), 7, 60);
525     gtk_clist_set_column_width (GTK_CLIST (clist), 8, 80);
526     gtk_clist_set_column_width (GTK_CLIST (clist), 9, 85);
527     gtk_clist_set_column_width (GTK_CLIST (clist), 10, 80);
528     gtk_clist_set_column_width (GTK_CLIST (clist), 11, 80);
529
530     gtk_clist_set_column_justification(GTK_CLIST(clist), 0, GTK_JUSTIFY_CENTER);
531     gtk_clist_set_column_justification(GTK_CLIST(clist), 1, GTK_JUSTIFY_CENTER);
532     gtk_clist_set_column_justification(GTK_CLIST(clist), 2, GTK_JUSTIFY_CENTER);
533     gtk_clist_set_column_justification(GTK_CLIST(clist), 3, GTK_JUSTIFY_CENTER);
534     gtk_clist_set_column_justification(GTK_CLIST(clist), 4, GTK_JUSTIFY_CENTER);
535     gtk_clist_set_column_justification(GTK_CLIST(clist), 5, GTK_JUSTIFY_CENTER);
536     gtk_clist_set_column_justification(GTK_CLIST(clist), 6, GTK_JUSTIFY_CENTER);
537     gtk_clist_set_column_justification(GTK_CLIST(clist), 7, GTK_JUSTIFY_CENTER);
538     gtk_clist_set_column_justification(GTK_CLIST(clist), 8, GTK_JUSTIFY_CENTER);
539     gtk_clist_set_column_justification(GTK_CLIST(clist), 9, GTK_JUSTIFY_CENTER);
540     gtk_clist_set_column_justification(GTK_CLIST(clist), 10, GTK_JUSTIFY_CENTER);
541     gtk_clist_set_column_justification(GTK_CLIST(clist), 11, GTK_JUSTIFY_CENTER);
542
543     gtk_clist_column_titles_show (GTK_CLIST (clist));
544
545     gtk_clist_set_compare_func(GTK_CLIST(clist), mcaststream_sort_column);
546     gtk_clist_set_sort_column(GTK_CLIST(clist), 0);
547     gtk_clist_set_sort_type(GTK_CLIST(clist), GTK_SORT_ASCENDING);
548
549     gtk_widget_show(mcaststream_dlg_w);
550
551     /* sort by column feature */
552     col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_COLS);
553
554     for (i=0; i<NUM_COLS; i++) {
555         col_arrows[i].table = gtk_table_new(2, 2, FALSE);
556         gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
557         column_lb = gtk_label_new(titles[i]);
558         gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
559         gtk_widget_show(column_lb);
560
561         col_arrows[i].ascend_pm = xpm_to_widget(clist_ascend_xpm);
562         gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
563         col_arrows[i].descend_pm = xpm_to_widget(clist_descend_xpm);
564         gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
565         /* make src-ip be the default sort order */
566         if (i == 0) {
567             gtk_widget_show(col_arrows[i].ascend_pm);
568         }
569         gtk_clist_set_column_widget(GTK_CLIST(clist), i, col_arrows[i].table);
570         gtk_widget_show(col_arrows[i].table);
571     }
572
573     SIGNAL_CONNECT(clist, "click-column", mcaststream_click_column_cb, col_arrows);
574
575     label_fwd = gtk_label_new (FWD_LABEL_TEXT);
576     /*gtk_box_pack_start (GTK_BOX (main_vb), label_fwd, FALSE, FALSE, 0);*/
577
578     label_par = gtk_label_new (PAR_LABEL_TEXT);
579     gtk_box_pack_start (GTK_BOX (main_vb), label_par, FALSE, FALSE, 0);
580
581     /* button row */
582     hbuttonbox = gtk_hbutton_box_new ();
583     gtk_box_pack_start (GTK_BOX (main_vb), hbuttonbox, FALSE, FALSE, 0);
584     gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END);
585     gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox), 0);
586
587     /*bt_unselect = gtk_button_new_with_label ("Unselect");
588     gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_unselect);
589     gtk_tooltips_set_tip (tooltips, bt_unselect, "Undo stream selection", NULL);*/
590
591     bt_params = gtk_button_new_with_label ("Set parameters");
592     gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_params);
593     gtk_tooltips_set_tip (tooltips, bt_params, "Set buffer, limit and speed parameters", NULL);
594
595     bt_filter = gtk_button_new_with_label ("Prepare Filter");
596     gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_filter);
597     gtk_tooltips_set_tip (tooltips, bt_filter, "Prepare a display filter of the selected stream", NULL);
598
599     bt_close = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLOSE);
600     gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_close);
601     gtk_tooltips_set_tip (tooltips, bt_close, "Close this dialog", NULL);
602     GTK_WIDGET_SET_FLAGS(bt_close, GTK_CAN_DEFAULT);
603
604     SIGNAL_CONNECT(clist, "select_row", mcaststream_on_select_row, NULL);
605     /*SIGNAL_CONNECT(bt_unselect, "clicked", mcaststream_on_unselect, NULL);*/
606     SIGNAL_CONNECT(bt_params, "clicked", mcast_on_params, NULL);
607     SIGNAL_CONNECT(bt_filter, "clicked", mcaststream_on_filter, NULL);
608     window_set_cancel_button(mcaststream_dlg_w, bt_close, window_cancel_button_cb);
609
610     SIGNAL_CONNECT(mcaststream_dlg_w, "delete_event", window_delete_event_cb, NULL);
611     SIGNAL_CONNECT(mcaststream_dlg_w, "destroy", mcaststream_on_destroy, NULL);
612
613     gtk_widget_show_all(mcaststream_dlg_w);
614     window_present(mcaststream_dlg_w);
615
616     mcaststream_on_unselect(NULL, NULL);
617
618     mcast_stream_dlg = mcaststream_dlg_w;
619 }
620
621
622 /****************************************************************************/
623 /* PUBLIC                                                                   */
624 /****************************************************************************/
625
626 /****************************************************************************/
627 /* update the contents of the dialog box clist */
628 /* list: pointer to list of mcast_stream_info_t* */
629 void mcaststream_dlg_update(GList *list)
630 {
631         if (mcast_stream_dlg != NULL) {
632                 gtk_clist_clear(GTK_CLIST(clist));
633                 streams_nb = 0;
634
635                 list = g_list_first(list);
636                 while (list)
637                 {
638                         add_to_clist((mcast_stream_info_t*)(list->data));
639                         list = g_list_next(list);
640                 }
641
642                 mcaststream_on_unselect(NULL, NULL);
643         }
644
645         last_list = list;
646 }
647
648
649 /****************************************************************************/
650 /* update the contents of the dialog box clist */
651 /* list: pointer to list of mcast_stream_info_t* */
652 void mcaststream_dlg_show(GList *list)
653 {
654         if (mcast_stream_dlg != NULL) {
655                 /* There's already a dialog box; reactivate it. */
656                 reactivate_window(mcast_stream_dlg);
657                 /* Another list since last call? */
658                 if (list != last_list) {
659                         mcaststream_dlg_update(list);
660                 }
661         }
662         else {
663                 /* Create and show the dialog box */
664                 mcaststream_dlg_create();
665                 mcaststream_dlg_update(list);
666         }
667 }
668
669
670 /****************************************************************************/
671 /* entry point when called via the GTK menu */
672 static void mcaststream_launch(GtkWidget *w _U_, gpointer data _U_)
673 {
674         /* Register the tap listener */
675         register_tap_listener_mcast_stream();
676
677         /* Scan for Mcast streams (redissect all packets) */
678         mcaststream_scan();
679
680         /* Show the dialog box with the list of streams */
681         mcaststream_dlg_show(mcaststream_get_info()->strinfo_list);
682
683         /* Tap listener will be removed and cleaned up in mcaststream_on_destroy */
684 }
685
686 /****************************************************************************/
687 void
688 register_tap_listener_mcast_stream_dlg(void)
689 {
690         register_stat_menu_item("Multicast Streams", REGISTER_STAT_GROUP_NONE,
691             mcaststream_launch, NULL, NULL, NULL);
692 }