2 * Routines for capture file summary window
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
37 #include <epan/strutil.h>
39 #include <wiretap/wtap.h>
41 #include "../globals.h"
43 #include "../summary.h"
44 #include "../capture-pcap-util.h"
46 #include "../capture.h"
47 #include "ui/gtk/main.h"
48 #include "ui/gtk/capture_globals.h"
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"
56 #define SUM_STR_MAX 1024
57 #define FILTER_SNIP_LEN 50
58 #define SHB_STR_SNIP_LEN 50
62 add_string_to_table_sensitive(GtkWidget *list, guint *row, const gchar *title, const gchar *value, gboolean sensitive)
67 if(strlen(value) != 0) {
68 indent = g_strdup_printf(" %s", title);
70 indent = g_strdup(title);
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);
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);
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);
92 add_string_to_table(GtkWidget *list, guint *row, gchar *title, gchar *value)
94 add_string_to_table_sensitive(list, row, title, value, TRUE);
99 add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed, gchar *marked)
101 simple_list_append(list, 0, title, 1, captured, 2, displayed, 3, marked, -1);
105 time_to_string(char *string_buff, gulong string_buff_size, time_t ti_time)
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) {
117 ti_tm = localtime(&ti_time);
119 g_snprintf(string_buff, string_buff_size, "Not representable");
122 g_snprintf(string_buff, string_buff_size,
123 "%04d-%02d-%02d %02d:%02d:%02d",
124 ti_tm->tm_year + 1900,
133 summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
135 summary_tally summary;
136 GtkWidget *sum_open_w,
137 *main_vb, *bbox, *close_bt, *help_bt;
138 GtkWidget *table, *scrolled_window;
139 GtkWidget *list, *treeview;
142 GtkCellRenderer *renderer;
143 GtkTreeViewColumn *column;
145 const char *dl_description;
147 static const char *titles[] = { "Traffic", "Captured", "Displayed", "Marked" };
149 gchar string_buff[SUM_STR_MAX];
150 gchar string_buff2[SUM_STR_MAX];
151 gchar string_buff3[SUM_STR_MAX];
152 gchar string_buff4[SUM_STR_MAX];
153 gchar string_buff5[SUM_STR_MAX];
157 double marked_seconds;
164 unsigned int elapsed_time;
168 /* initial computations */
169 summary_fill_in(&cfile, &summary);
171 summary_fill_in_capture(&cfile, &global_capture_opts, &summary);
173 seconds = summary.stop_time - summary.start_time;
174 disp_seconds = summary.filtered_stop - summary.filtered_start;
175 marked_seconds = summary.marked_stop - summary.marked_start;
177 sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Summary");
179 /* Container for each row of widgets */
180 main_vb = gtk_vbox_new(FALSE, 12);
181 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 12);
182 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
185 table = gtk_table_new(1, 2, FALSE);
186 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
187 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
188 gtk_container_add(GTK_CONTAINER(main_vb), table);
193 add_string_to_table(table, &row, "File", "");
196 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.filename);
197 add_string_to_table(table, &row, "Name:", string_buff);
200 g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "d bytes", summary.file_length);
201 add_string_to_table(table, &row, "Length:", string_buff);
204 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.file_type));
205 add_string_to_table(table, &row, "Format:", string_buff);
208 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.encap_type));
209 add_string_to_table(table, &row, "Encapsulation:", string_buff);
211 if (summary.has_snap) {
212 /* snapshot length */
213 g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
214 add_string_to_table(table, &row, "Packet size limit:", string_buff);
219 add_string_to_table(table, &row, "", "");
220 add_string_to_table(table, &row, "Time", "");
223 time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.start_time);
224 add_string_to_table(table, &row, "First packet:", string_buff);
227 time_to_string(string_buff, SUM_STR_MAX, (time_t)summary.stop_time);
228 add_string_to_table(table, &row, "Last packet:", string_buff);
230 /* elapsed seconds */
231 elapsed_time = (unsigned int)summary.elapsed_time;
232 if(elapsed_time/86400) {
233 g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
234 elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
236 g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
237 elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
239 add_string_to_table(table, &row, "Elapsed:", string_buff);
243 add_string_to_table(table, &row, "", "");
244 add_string_to_table_sensitive(table, &row, "Capture", "", (summary.ifaces->len > 0));
245 if(summary.shb_hardware){
246 /* trucate the string to a reasonable length */
247 g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_hardware);
248 add_string_to_table(table, &row, "Capture HW:",string_buff);
251 /* trucate the strings to a reasonable length */
252 g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_os);
253 add_string_to_table(table, &row, "OS:", string_buff);
255 if(summary.shb_user_appl){
256 /* trucate the string to a reasonable length */
257 g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s",summary.shb_user_appl);
258 add_string_to_table(table, &row, "Capture application:", string_buff);
260 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
261 gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 5);
262 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
263 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
264 gtk_widget_set_size_request(scrolled_window, -1, 120);
266 treeview = gtk_tree_view_new();
267 renderer = gtk_cell_renderer_text_new();
268 column = gtk_tree_view_column_new_with_attributes("Interface", renderer, "text", 0, NULL);
269 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
270 renderer = gtk_cell_renderer_text_new();
271 column = gtk_tree_view_column_new_with_attributes("Dropped Packets", renderer, "text", 1, NULL);
272 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
273 renderer = gtk_cell_renderer_text_new();
274 column = gtk_tree_view_column_new_with_attributes("Capture Filter", renderer, "text", 2, NULL);
275 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
276 renderer = gtk_cell_renderer_text_new();
277 column = gtk_tree_view_column_new_with_attributes("Link type", renderer, "text", 3, NULL);
278 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
279 renderer = gtk_cell_renderer_text_new();
280 column = gtk_tree_view_column_new_with_attributes("Packet size limit", renderer, "text", 4, NULL);
281 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
283 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
284 for (i = 0; i < summary.ifaces->len; i++) {
285 iface = g_array_index(summary.ifaces, iface_options, i);
288 g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.descr);
289 } else if (iface.name) {
290 g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.name);
292 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
295 if (iface.drops_known) {
296 g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", iface.drops);
298 g_snprintf(string_buff2, SUM_STR_MAX, "unknown");
302 if (iface.cfilter && iface.cfilter[0] != '\0') {
303 g_snprintf(string_buff3, SUM_STR_MAX, "%s", iface.cfilter);
306 g_snprintf(string_buff3, SUM_STR_MAX, "none");
308 g_snprintf(string_buff3, SUM_STR_MAX, "unknown");
311 dl_description = pcap_datalink_val_to_description(iface.linktype);
312 if (dl_description != NULL)
313 g_snprintf(string_buff4, SUM_STR_MAX, "%s", dl_description);
315 g_snprintf(string_buff4, SUM_STR_MAX, "DLT %d", iface.linktype);
317 g_snprintf(string_buff3, SUM_STR_MAX, "unknown");
318 g_snprintf(string_buff4, SUM_STR_MAX, "unknown");
320 g_snprintf(string_buff5, SUM_STR_MAX, "%u bytes", iface.snap);
321 gtk_list_store_append(store, &iter);
322 gtk_list_store_set(store, &iter, 0, string_buff, 1, string_buff2, 2, string_buff3, 3, string_buff4, 4, string_buff5,-1);
324 gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
325 g_object_unref (store);
326 gtk_container_add(GTK_CONTAINER(scrolled_window), treeview);
327 gtk_container_add(GTK_CONTAINER(main_vb),scrolled_window);
328 gtk_widget_show_all (scrolled_window);
329 table = gtk_table_new(1, 2, FALSE);
330 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
331 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
332 gtk_container_add(GTK_CONTAINER(main_vb), table);
337 add_string_to_table(table, &row, "", "");
338 add_string_to_table(table, &row, "Display", "");
340 if (summary.dfilter) {
342 /* limit each row to some reasonable length */
343 str_dup = g_strdup_printf("%s", summary.dfilter);
344 str_work = g_strdup(str_dup);
347 while(strlen(str_work) > FILTER_SNIP_LEN) {
348 str_work[FILTER_SNIP_LEN] = '\0';
349 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
351 offset+=FILTER_SNIP_LEN;
352 str_work = g_strdup(&str_dup[offset]);
356 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
361 add_string_to_table(table, &row, "Display filter:", "none");
364 /* Ignored packet count */
365 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.ignored_count);
366 add_string_to_table(table, &row, "Ignored packets:", string_buff);
369 list = simple_list_new(4, titles);
370 gtk_container_add(GTK_CONTAINER(main_vb), list);
373 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
374 if (summary.dfilter) {
375 g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
377 g_strlcpy(string_buff2, string_buff, SUM_STR_MAX);
379 g_snprintf(string_buff3, SUM_STR_MAX, "%i", summary.marked_count);
380 add_string_to_list(list, "Packets", string_buff, string_buff2, string_buff3);
382 /* Time between first and last */
384 g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
386 string_buff[0] = '\0';
388 if (summary.dfilter && disp_seconds > 0) {
389 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
391 string_buff2[0] = '\0';
393 if (summary.marked_count && marked_seconds > 0) {
394 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f sec", marked_seconds);
396 string_buff3[0] = '\0';
398 add_string_to_list(list, "Between first and last packet", string_buff, string_buff2, string_buff3);
400 /* Packets per second */
402 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
404 string_buff[0] = '\0';
406 if(summary.dfilter && disp_seconds > 0) {
407 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
409 string_buff2[0] = '\0';
411 if(summary.marked_count && marked_seconds > 0) {
412 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", summary.marked_count/marked_seconds);
414 string_buff3[0] = '\0';
416 add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2, string_buff3);
419 if (summary.packet_count > 1) {
420 g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
421 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
422 (float) ((gint64) summary.bytes)/summary.packet_count);
424 string_buff[0] = '\0';
426 if (summary.dfilter && summary.filtered_count > 1) {
427 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f bytes",
428 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
429 (float) ((gint64) summary.filtered_bytes)/summary.filtered_count);
431 string_buff2[0] = '\0';
433 if (summary.marked_count > 1) {
434 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f bytes",
435 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
436 (float) ((gint64) summary.marked_bytes)/summary.marked_count);
438 string_buff3[0] = '\0';
440 add_string_to_list(list, "Avg. packet size", string_buff, string_buff2, string_buff3);
443 g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.bytes);
444 if (summary.dfilter && summary.filtered_count > 0) {
445 g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.filtered_bytes);
447 string_buff2[0] = '\0';
449 if (summary.marked_count) {
450 g_snprintf(string_buff3, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.marked_bytes);
452 string_buff3[0] = '\0';
454 add_string_to_list(list, "Bytes", string_buff, string_buff2, string_buff3);
456 /* Bytes per second */
458 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
459 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes)/seconds);
461 string_buff[0] = '\0';
463 if (summary.dfilter && disp_seconds > 0) {
464 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
465 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", ((gint64) summary.filtered_bytes)/disp_seconds);
467 string_buff2[0] = '\0';
469 if (summary.marked_count && marked_seconds > 0) {
470 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
471 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", ((gint64) summary.marked_bytes)/marked_seconds);
473 string_buff3[0] = '\0';
475 add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2, string_buff3);
477 /* MBit per second */
479 g_snprintf(string_buff, SUM_STR_MAX, "%.3f",
480 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
481 ((gint64) summary.bytes) * 8.0 / (seconds * 1000.0 * 1000.0));
483 string_buff[0] = '\0';
485 if (summary.dfilter && disp_seconds > 0) {
486 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
487 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
488 ((gint64) summary.filtered_bytes) * 8.0 / (disp_seconds * 1000.0 * 1000.0));
490 string_buff2[0] = '\0';
492 if (summary.marked_count && marked_seconds > 0) {
493 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f",
494 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
495 ((gint64) summary.marked_bytes) * 8.0 / (marked_seconds * 1000.0 * 1000.0));
497 string_buff3[0] = '\0';
499 add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2, string_buff3);
503 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
504 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
506 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
507 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
509 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
510 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_SUMMARY_DIALOG);
512 gtk_widget_grab_focus(close_bt);
514 g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
516 gtk_widget_show_all(sum_open_w);
517 window_present(sum_open_w);