0a303783ca335c616222b8fe75799bf2b05f8b15
[obnox/wireshark/wip.git] / ui / gtk / summary_dlg.c
1 /* summary_dlg.c
2  * Routines for capture file summary window
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
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
31 #endif
32 #include <string.h>
33 #include <time.h>
34
35 #include <gtk/gtk.h>
36
37 #include <epan/strutil.h>
38
39 #include <wiretap/wtap.h>
40
41 #include "../globals.h"
42 #include "../file.h"
43 #include "../summary.h"
44 #include "../capture-pcap-util.h"
45 #ifdef HAVE_LIBPCAP
46 #include "../capture.h"
47 #include "ui/gtk/main.h"
48 #include "ui/gtk/capture_globals.h"
49 #endif
50
51 #include "ui/gtk/summary_dlg.h"
52 #include "ui/gtk/dlg_utils.h"
53 #include "ui/gtk/gui_utils.h"
54 #include "ui/gtk/help_dlg.h"
55
56 #define SUM_STR_MAX     1024
57 #define FILTER_SNIP_LEN 50
58 #define SHB_STR_SNIP_LEN 50
59
60
61 static void
62 add_string_to_table_sensitive(GtkWidget *list, guint *row, const gchar *title, const gchar *value, gboolean sensitive)
63 {
64     GtkWidget *label;
65     gchar     *indent;
66
67     if(strlen(value) != 0) {
68         indent = g_strdup_printf("   %s", title);
69     } else {
70         indent = g_strdup(title);
71     }
72     label = gtk_label_new(indent);
73     if (strlen(value) == 0) {
74       gchar *message = g_strdup_printf("<span weight=\"bold\">%s</span>", title);
75       gtk_label_set_markup(GTK_LABEL(label), message);
76       g_free (message);
77     }
78     g_free(indent);
79     gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
80     gtk_widget_set_sensitive(label, sensitive);
81     gtk_table_attach_defaults(GTK_TABLE(list), label, 0, 1, *row, *row+1);
82
83     label = gtk_label_new(value);
84     gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
85     gtk_widget_set_sensitive(label, sensitive);
86     gtk_table_attach_defaults(GTK_TABLE(list), label, 1, 2, *row, *row+1);
87
88     *row = *row + 1;
89 }
90
91 static void
92 add_string_to_table(GtkWidget *list, guint *row, gchar *title, gchar *value)
93 {
94     add_string_to_table_sensitive(list, row, title, value, TRUE);
95 }
96
97
98 static void
99 add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed, gchar *marked)
100 {
101     simple_list_append(list, 0, title, 1, captured, 2, displayed, 3, marked, -1);
102 }
103
104 static void
105 time_to_string(char *string_buff, gulong string_buff_size, time_t ti_time)
106 {
107   struct tm *ti_tm;
108
109 #ifdef _MSC_VER
110   /* calling localtime() on MSVC 2005 with huge values causes it to crash */
111   /* XXX - find the exact value that still does work */
112   /* XXX - using _USE_32BIT_TIME_T might be another way to circumvent this problem */
113   if (ti_time > 2000000000) {
114       ti_tm = NULL;
115   } else
116 #endif
117   ti_tm = localtime(&ti_time);
118   if (ti_tm == NULL) {
119     g_snprintf(string_buff, string_buff_size, "Not representable");
120     return;
121   }
122   g_snprintf(string_buff, string_buff_size,
123              "%04d-%02d-%02d %02d:%02d:%02d",
124              ti_tm->tm_year + 1900,
125              ti_tm->tm_mon + 1,
126              ti_tm->tm_mday,
127              ti_tm->tm_hour,
128              ti_tm->tm_min,
129              ti_tm->tm_sec);
130 }
131
132 static void
133 summary_comment_text_buff_save_cb(GtkWidget *w _U_, GtkWidget *view)
134 {
135   GtkTextBuffer *buffer;
136   GtkTextIter start_iter;
137   GtkTextIter end_iter;
138   gchar *new_comment = NULL;
139
140   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
141   gtk_text_buffer_get_start_iter (buffer, &start_iter);
142   gtk_text_buffer_get_end_iter (buffer, &end_iter);
143
144   new_comment = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE /* whether to include invisible text */);  
145
146   /*g_warning("The new comment is '%s'",new_packet_comment);*/
147
148   summary_update_comment(&cfile, new_comment);
149
150 }
151
152 static void
153 summary_comment_text_buff_clear_cb(GtkWidget *w _U_, GtkWidget *view)
154 {
155   GtkTextBuffer *buffer;
156
157   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
158   gtk_text_buffer_set_text (buffer, "", -1);
159
160 }
161
162 void
163 summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
164 {
165   summary_tally summary;
166   GtkWidget     *sum_open_w,
167                 *main_vb, *bbox, *close_bt, *help_bt;
168   GtkWidget     *table, *scrolled_window;
169   GtkWidget     *list, *treeview;
170   GtkListStore  *store;
171   GtkTreeIter    iter;
172   GtkCellRenderer *renderer;
173   GtkTreeViewColumn *column;
174 #ifdef HAVE_LIBPCAP
175   const char    *dl_description;
176 #endif
177   static const char *titles[] = { "Traffic", "Captured", "Displayed", "Marked" };
178
179   gchar         string_buff[SUM_STR_MAX];
180   gchar         string_buff2[SUM_STR_MAX];
181   gchar         string_buff3[SUM_STR_MAX];
182   gchar         string_buff4[SUM_STR_MAX];
183   gchar         string_buff5[SUM_STR_MAX];
184
185   double        seconds;
186   double        disp_seconds;
187   double        marked_seconds;
188   guint         offset;
189   guint         snip;
190   guint         row;
191   gchar        *str_dup;
192   gchar        *str_work;
193
194   unsigned int  elapsed_time;
195   iface_options iface;
196   unsigned int  i;
197
198   /* initial computations */
199   summary_fill_in(&cfile, &summary);
200 #ifdef HAVE_LIBPCAP
201   summary_fill_in_capture(&cfile, &global_capture_opts, &summary);
202 #endif
203   /*
204    * Note: the start and stop times are initialized to 0, so if we
205    * have zero or one packets of the type in question that have
206    * time stamps, the elapsed times will be zero, just as if we
207    * have both start and stop time stamps but they're the same.
208    * That means we can avoid some checks for whether we have more
209    * than one packet of the type in question with time stamps.
210    */
211   seconds = summary.stop_time - summary.start_time;
212   disp_seconds = summary.filtered_stop - summary.filtered_start;
213   marked_seconds = summary.marked_stop - summary.marked_start;
214
215   sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Summary");
216
217   /* Container for each row of widgets */
218   main_vb = gtk_vbox_new(FALSE, 12);
219   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 12);
220   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
221
222   /* table */
223   table = gtk_table_new(1, 2, FALSE);
224   gtk_table_set_col_spacings(GTK_TABLE(table), 6);
225   gtk_table_set_row_spacings(GTK_TABLE(table), 3);
226   gtk_container_add(GTK_CONTAINER(main_vb), table);
227   row = 0;
228
229
230   /* File */
231   add_string_to_table(table, &row, "File", "");
232
233   /* filename */
234   g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.filename);
235   add_string_to_table(table, &row, "Name:", string_buff);
236
237   /* length */
238   g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "d bytes", summary.file_length);
239   add_string_to_table(table, &row, "Length:", string_buff);
240
241   /* format */
242   g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.file_type));
243   add_string_to_table(table, &row, "Format:", string_buff);
244
245   /* encapsulation */
246   g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.encap_type));
247   add_string_to_table(table, &row, "Encapsulation:", string_buff);
248
249   if (summary.has_snap) {
250     /* snapshot length */
251     g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
252     add_string_to_table(table, &row, "Packet size limit:", string_buff);
253   }
254
255   /* Only allow editing of comment if filetype is PCAPNG */
256   if(summary.file_type == WTAP_FILE_PCAPNG){
257           GtkWidget *comment_vbox;
258           GtkWidget *view;
259           GtkTextBuffer *buffer = NULL;
260           const gchar *buf_str;
261           GtkWidget *save_bt, *clear_bt;
262
263           comment_vbox = gtk_vbox_new (FALSE, 0);
264           gtk_container_add (GTK_CONTAINER (main_vb), comment_vbox);
265           gtk_widget_show (comment_vbox);
266
267           view = gtk_text_view_new ();
268           buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
269           if(summary.opt_comment == NULL){
270                   buf_str = g_strdup_printf("[None]");
271           }else{
272                   buf_str = g_strdup_printf("%s", summary.opt_comment);
273           }
274           gtk_text_buffer_set_text (buffer, buf_str, -1);
275           gtk_container_add(GTK_CONTAINER(comment_vbox), view);
276           gtk_widget_show (view);
277
278           /* Button row. */
279           bbox = dlg_button_row_new (GTK_STOCK_SAVE, GTK_STOCK_CLEAR, NULL);
280           gtk_box_pack_end (GTK_BOX(comment_vbox), bbox, FALSE, FALSE, 0);
281
282           save_bt = g_object_get_data (G_OBJECT(bbox), GTK_STOCK_SAVE);
283           g_signal_connect (save_bt, "clicked", G_CALLBACK(summary_comment_text_buff_save_cb), view);
284           gtk_widget_set_sensitive (save_bt, TRUE);
285           gtk_widget_set_tooltip_text(save_bt,
286                              "You need to save the the capture file as well to save the updated comment");
287
288
289           clear_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLEAR);
290           g_signal_connect(clear_bt, "clicked", G_CALLBACK(summary_comment_text_buff_clear_cb), view);
291           gtk_widget_set_tooltip_text(clear_bt,
292                              "Clears the text from the box, not the capture");
293
294           gtk_widget_grab_default (save_bt);
295
296   }else{
297           if (summary.opt_comment != NULL) {
298                 /* comment */
299                 add_string_to_table(table, &row, "Comment:", summary.opt_comment);
300           }
301  }
302
303   /*
304    * We must have no un-time-stamped packets (i.e., the number of
305    * time-stamped packets must be the same as the number of packets),
306    * and at least one time-stamped packet, in order for the start
307    * and stop times to be valid.
308    */
309   if (summary.packet_count_ts == summary.packet_count &&
310       summary.packet_count >= 1) {
311     /* Time */
312     add_string_to_table(table, &row, "", "");
313     add_string_to_table(table, &row, "Time", "");
314
315     /* start time */
316     time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.start_time);
317     add_string_to_table(table, &row, "First packet:", string_buff);
318
319     /* stop time */
320     time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.stop_time);
321     add_string_to_table(table, &row, "Last packet:", string_buff);
322
323     /*
324      * We must have at least two time-stamped packets for the elapsed time
325      * to be valid.
326      */
327     if (summary.packet_count_ts >= 2) {
328       /* elapsed seconds */
329       elapsed_time = (unsigned int)summary.elapsed_time;
330       if(elapsed_time/86400) {
331           g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
332             elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
333       } else {
334           g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
335             elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
336       }
337       add_string_to_table(table, &row, "Elapsed:", string_buff);
338     }
339   }
340
341   /* Capture */
342   add_string_to_table(table, &row, "", "");
343   add_string_to_table_sensitive(table, &row, "Capture", "", (summary.ifaces->len > 0));
344   if(summary.shb_hardware){
345           /* trucate the string to a reasonable length */
346           g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_hardware);
347       add_string_to_table(table, &row, "Capture HW:",string_buff);
348   }
349   if(summary.shb_os){
350           /* trucate the strings to a reasonable length */
351           g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_os);
352       add_string_to_table(table, &row, "OS:", string_buff);
353   }
354   if(summary.shb_user_appl){
355           /* trucate the string to a reasonable length */
356           g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_user_appl);
357       add_string_to_table(table, &row, "Capture application:", string_buff);
358   }
359   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
360   gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 5);
361   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
362                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
363   gtk_widget_set_size_request(scrolled_window, -1, 120);
364
365   treeview = gtk_tree_view_new();
366   renderer = gtk_cell_renderer_text_new();
367   column = gtk_tree_view_column_new_with_attributes("Interface", renderer, "text", 0, NULL);
368   gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
369   renderer = gtk_cell_renderer_text_new();
370   column = gtk_tree_view_column_new_with_attributes("Dropped Packets", renderer, "text", 1, NULL);
371   gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
372   renderer = gtk_cell_renderer_text_new();
373   column = gtk_tree_view_column_new_with_attributes("Capture Filter", renderer, "text", 2, NULL);
374   gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
375   renderer = gtk_cell_renderer_text_new();
376   column = gtk_tree_view_column_new_with_attributes("Link type", renderer, "text", 3, NULL);
377   gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
378   renderer = gtk_cell_renderer_text_new();
379   column = gtk_tree_view_column_new_with_attributes("Packet size limit", renderer, "text", 4, NULL);
380   gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
381       
382   store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
383   for (i = 0; i < summary.ifaces->len; i++) {
384     iface = g_array_index(summary.ifaces, iface_options, i);
385     /* interface */
386     if (iface.descr) {
387       g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.descr);
388     } else if (iface.name) {
389       g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.name);
390     } else {
391       g_snprintf(string_buff, SUM_STR_MAX, "unknown");
392     }
393     /* Dropped count */
394     if (iface.drops_known) {
395       g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", iface.drops);
396     } else {
397       g_snprintf(string_buff2, SUM_STR_MAX, "unknown");
398     }
399 #ifdef HAVE_LIBPCAP
400     /* Capture filter */
401     if (iface.cfilter && iface.cfilter[0] != '\0') {
402       g_snprintf(string_buff3, SUM_STR_MAX, "%s", iface.cfilter);
403     } else {
404       if (iface.name) {
405         g_snprintf(string_buff3, SUM_STR_MAX, "none");
406       } else {
407         g_snprintf(string_buff3, SUM_STR_MAX, "unknown");
408       }
409     }
410     dl_description = pcap_datalink_val_to_description(iface.linktype);
411     if (dl_description != NULL)
412       g_snprintf(string_buff4, SUM_STR_MAX, "%s", dl_description);
413     else
414       g_snprintf(string_buff4, SUM_STR_MAX, "DLT %d", iface.linktype);
415 #else
416     g_snprintf(string_buff3, SUM_STR_MAX, "unknown");
417     g_snprintf(string_buff4, SUM_STR_MAX, "unknown");
418 #endif
419     g_snprintf(string_buff5, SUM_STR_MAX, "%u bytes", iface.snap);
420     gtk_list_store_append(store, &iter);
421     gtk_list_store_set(store, &iter, 0, string_buff, 1, string_buff2, 2, string_buff3, 3, string_buff4, 4, string_buff5,-1);
422   }
423   gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
424   g_object_unref (store);
425   gtk_container_add(GTK_CONTAINER(scrolled_window), treeview);
426   gtk_container_add(GTK_CONTAINER(main_vb),scrolled_window);
427   gtk_widget_show_all (scrolled_window);
428   table = gtk_table_new(1, 2, FALSE);
429   gtk_table_set_col_spacings(GTK_TABLE(table), 6);
430   gtk_table_set_row_spacings(GTK_TABLE(table), 3);
431   gtk_container_add(GTK_CONTAINER(main_vb), table);
432   row = 0;
433
434
435   /* Data */
436   add_string_to_table(table, &row, "", "");
437   add_string_to_table(table, &row, "Display", "");
438
439   if (summary.dfilter) {
440     /* Display filter */
441     /* limit each row to some reasonable length */
442     str_dup = g_strdup_printf("%s", summary.dfilter);
443     str_work = g_strdup(str_dup);
444     offset = 0;
445     snip = 0;
446     while(strlen(str_work) > FILTER_SNIP_LEN) {
447         str_work[FILTER_SNIP_LEN] = '\0';
448         add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
449         g_free(str_work);
450         offset+=FILTER_SNIP_LEN;
451         str_work = g_strdup(&str_dup[offset]);
452         snip++;
453     }
454
455     add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
456     g_free(str_work);
457     g_free(str_dup);
458   } else {
459     /* Display filter */
460     add_string_to_table(table, &row, "Display filter:", "none");
461   }
462
463   /* Ignored packet count */
464   g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.ignored_count);
465   add_string_to_table(table, &row, "Ignored packets:", string_buff);
466
467   /* Traffic */
468   list = simple_list_new(4, titles);
469   gtk_container_add(GTK_CONTAINER(main_vb), list);
470
471   /* Packet count */
472   g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
473   if (summary.dfilter) {
474     g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
475   } else {
476     g_strlcpy(string_buff2, string_buff, SUM_STR_MAX);
477   }
478   g_snprintf(string_buff3, SUM_STR_MAX, "%i", summary.marked_count);
479   add_string_to_list(list, "Packets", string_buff, string_buff2, string_buff3);
480
481   /* Time between first and last */
482   if (seconds > 0) {
483     g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
484   } else {
485     string_buff[0] = '\0';
486   }
487   if (summary.dfilter && disp_seconds > 0) {
488     g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
489   } else {
490     string_buff2[0] = '\0';
491   }
492   if (summary.marked_count && marked_seconds > 0) {
493     g_snprintf(string_buff3, SUM_STR_MAX, "%.3f sec", marked_seconds);
494   } else {
495     string_buff3[0] = '\0';
496   }
497   if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0')
498     add_string_to_list(list, "Between first and last packet", string_buff, string_buff2, string_buff3);
499
500   /* Packets per second */
501   if (seconds > 0) {
502     g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
503   } else {
504     string_buff[0] = '\0';
505   }
506   if(summary.dfilter && disp_seconds > 0) {
507     g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
508   } else {
509     string_buff2[0] = '\0';
510   }
511   if(summary.marked_count && marked_seconds > 0) {
512     g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", summary.marked_count/marked_seconds);
513   } else {
514     string_buff3[0] = '\0';
515   }
516   if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0')
517   add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2, string_buff3);
518
519   /* Packet size */
520   if (summary.packet_count > 1) {
521     g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
522                /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
523                (float) ((gint64) summary.bytes)/summary.packet_count);
524   } else {
525     string_buff[0] = '\0';
526   }
527   if (summary.dfilter && summary.filtered_count > 1) {
528     g_snprintf(string_buff2, SUM_STR_MAX, "%.3f bytes",
529                /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
530                (float) ((gint64) summary.filtered_bytes)/summary.filtered_count);
531   } else {
532     string_buff2[0] = '\0';
533   }
534   if (summary.marked_count > 1) {
535     g_snprintf(string_buff3, SUM_STR_MAX, "%.3f bytes",
536                /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
537                (float) ((gint64) summary.marked_bytes)/summary.marked_count);
538   } else {
539     string_buff3[0] = '\0';
540   }
541   if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0')
542     add_string_to_list(list, "Avg. packet size", string_buff, string_buff2, string_buff3);
543
544   /* Byte count */
545   g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.bytes);
546   if (summary.dfilter && summary.filtered_count > 0) {
547     g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.filtered_bytes);
548   } else {
549     string_buff2[0] = '\0';
550   }
551   if (summary.marked_count) {
552     g_snprintf(string_buff3, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.marked_bytes);
553   } else {
554     string_buff3[0] = '\0';
555   }
556   if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0')
557     add_string_to_list(list, "Bytes", string_buff, string_buff2, string_buff3);
558
559   /* Bytes per second */
560   if (seconds > 0){
561     /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
562     g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes)/seconds);
563   } else {
564     string_buff[0] = '\0';
565   }
566   if (summary.dfilter && disp_seconds > 0) {
567     /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
568     g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", ((gint64) summary.filtered_bytes)/disp_seconds);
569   } else {
570     string_buff2[0] = '\0';
571   }
572   if (summary.marked_count && marked_seconds > 0) {
573     /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
574     g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", ((gint64) summary.marked_bytes)/marked_seconds);
575   } else {
576     string_buff3[0] = '\0';
577   }
578   if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0')
579     add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2, string_buff3);
580
581   /* MBit per second */
582   if (seconds > 0) {
583     g_snprintf(string_buff, SUM_STR_MAX, "%.3f",
584                /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
585                ((gint64) summary.bytes) * 8.0 / (seconds * 1000.0 * 1000.0));
586   } else {
587     string_buff[0] = '\0';
588   }
589   if (summary.dfilter && disp_seconds > 0) {
590     g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
591                /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
592                ((gint64) summary.filtered_bytes) * 8.0 / (disp_seconds * 1000.0 * 1000.0));
593   } else {
594     string_buff2[0] = '\0';
595   }
596   if (summary.marked_count && marked_seconds > 0) {
597     g_snprintf(string_buff3, SUM_STR_MAX, "%.3f",
598                /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
599                ((gint64) summary.marked_bytes) * 8.0 / (marked_seconds * 1000.0 * 1000.0));
600   } else {
601     string_buff3[0] = '\0';
602   }
603   if (string_buff[0] != '\0' || string_buff2[0] != '\0' || string_buff3[0] != '\0')
604     add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2, string_buff3);
605
606
607   /* Button row. */
608   bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
609   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
610
611   close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
612   window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
613
614   help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
615   g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_SUMMARY_DIALOG);
616
617   gtk_widget_grab_focus(close_bt);
618
619   g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
620
621   gtk_widget_show_all(sum_open_w);
622   window_present(sum_open_w);
623 }