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"
48 #include "gtk/capture_globals.h"
51 #include "gtk/summary_dlg.h"
52 #include "gtk/dlg_utils.h"
53 #include "gtk/gui_utils.h"
54 #include "gtk/help_dlg.h"
56 #define SUM_STR_MAX 1024
57 #define FILTER_SNIP_LEN 50
61 add_string_to_table_sensitive(GtkWidget *list, guint *row, const gchar *title, const gchar *value, gboolean sensitive)
66 if(strlen(value) != 0) {
67 indent = g_strdup_printf(" %s", title);
69 indent = g_strdup(title);
71 label = gtk_label_new(indent);
72 if (strlen(value) == 0) {
73 gchar *message = g_strdup_printf("<span weight=\"bold\">%s</span>", title);
74 gtk_label_set_markup(GTK_LABEL(label), message);
78 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
79 gtk_widget_set_sensitive(label, sensitive);
80 gtk_table_attach_defaults(GTK_TABLE(list), label, 0, 1, *row, *row+1);
82 label = gtk_label_new(value);
83 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
84 gtk_widget_set_sensitive(label, sensitive);
85 gtk_table_attach_defaults(GTK_TABLE(list), label, 1, 2, *row, *row+1);
91 add_string_to_table(GtkWidget *list, guint *row, gchar *title, gchar *value)
93 add_string_to_table_sensitive(list, row, title, value, TRUE);
98 add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed, gchar *marked)
100 simple_list_append(list, 0, title, 1, captured, 2, displayed, 3, marked, -1);
104 summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
106 summary_tally summary;
107 GtkWidget *sum_open_w,
108 *main_vb, *bbox, *close_bt, *help_bt;
109 GtkWidget *table, *scrolled_window;
110 GtkWidget *list, *treeview;
113 GtkCellRenderer *renderer;
114 GtkTreeViewColumn *column;
116 const char *dl_description;
118 static const char *titles[] = { "Traffic", "Captured", "Displayed", "Marked" };
120 gchar string_buff[SUM_STR_MAX];
121 gchar string_buff2[SUM_STR_MAX];
122 gchar string_buff3[SUM_STR_MAX];
123 gchar string_buff4[SUM_STR_MAX];
124 gchar string_buff5[SUM_STR_MAX];
128 double marked_seconds;
137 unsigned int elapsed_time;
141 /* initial computations */
142 summary_fill_in(&cfile, &summary);
144 summary_fill_in_capture(&global_capture_opts, &summary);
146 seconds = summary.stop_time - summary.start_time;
147 disp_seconds = summary.filtered_stop - summary.filtered_start;
148 marked_seconds = summary.marked_stop - summary.marked_start;
150 sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Summary");
152 /* Container for each row of widgets */
153 main_vb = gtk_vbox_new(FALSE, 12);
154 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 12);
155 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
158 table = gtk_table_new(1, 2, FALSE);
159 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
160 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
161 gtk_container_add(GTK_CONTAINER(main_vb), table);
166 add_string_to_table(table, &row, "File", "");
169 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.filename);
170 add_string_to_table(table, &row, "Name:", string_buff);
173 g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "d bytes", summary.file_length);
174 add_string_to_table(table, &row, "Length:", string_buff);
177 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.file_type));
178 add_string_to_table(table, &row, "Format:", string_buff);
181 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.encap_type));
182 add_string_to_table(table, &row, "Encapsulation:", string_buff);
184 if (summary.has_snap) {
185 /* snapshot length */
186 g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
187 add_string_to_table(table, &row, "Packet size limit:", string_buff);
192 add_string_to_table(table, &row, "", "");
193 add_string_to_table(table, &row, "Time", "");
196 ti_time = (time_t)summary.start_time;
197 ti_tm = localtime(&ti_time);
198 g_snprintf(string_buff, SUM_STR_MAX,
199 "%04d-%02d-%02d %02d:%02d:%02d",
200 ti_tm->tm_year + 1900,
206 add_string_to_table(table, &row, "First packet:", string_buff);
209 ti_time = (time_t)summary.stop_time;
210 ti_tm = localtime(&ti_time);
211 g_snprintf(string_buff, SUM_STR_MAX,
212 "%04d-%02d-%02d %02d:%02d:%02d",
213 ti_tm->tm_year + 1900,
219 add_string_to_table(table, &row, "Last packet:", string_buff);
221 /* elapsed seconds */
222 elapsed_time = (unsigned int)summary.elapsed_time;
223 if(elapsed_time/86400) {
224 g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
225 elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
227 g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
228 elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
230 add_string_to_table(table, &row, "Elapsed:", string_buff);
234 add_string_to_table(table, &row, "", "");
235 add_string_to_table_sensitive(table, &row, "Capture", "", (summary.ifaces->len > 0));
236 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
237 gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 5);
238 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
239 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
240 gtk_widget_set_size_request(scrolled_window, -1, 120);
242 treeview = gtk_tree_view_new();
243 renderer = gtk_cell_renderer_text_new();
244 column = gtk_tree_view_column_new_with_attributes("Interface", renderer, "text", 0, NULL);
245 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
246 renderer = gtk_cell_renderer_text_new();
247 column = gtk_tree_view_column_new_with_attributes("Dropped Packets", renderer, "text", 1, NULL);
248 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
249 renderer = gtk_cell_renderer_text_new();
250 column = gtk_tree_view_column_new_with_attributes("Capture Filter", renderer, "text", 2, NULL);
251 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
252 renderer = gtk_cell_renderer_text_new();
253 column = gtk_tree_view_column_new_with_attributes("Link type", renderer, "text", 3, NULL);
254 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
255 renderer = gtk_cell_renderer_text_new();
256 column = gtk_tree_view_column_new_with_attributes("Packet size limit", renderer, "text", 4, NULL);
257 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
259 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
260 for (i = 0; i < summary.ifaces->len; i++) {
261 iface = g_array_index(summary.ifaces, iface_options, i);
264 g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.descr);
265 } else if (iface.name) {
266 g_snprintf(string_buff, SUM_STR_MAX, "%s", iface.name);
268 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
271 if (iface.drops_known) {
272 g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", iface.drops);
274 g_snprintf(string_buff2, SUM_STR_MAX, "unknown");
278 if (iface.cfilter && iface.cfilter[0] != '\0') {
279 g_snprintf(string_buff3, SUM_STR_MAX, "%s", iface.cfilter);
282 g_snprintf(string_buff3, SUM_STR_MAX, "none");
284 g_snprintf(string_buff3, SUM_STR_MAX, "unknown");
287 dl_description = pcap_datalink_val_to_description(iface.linktype);
288 if (dl_description != NULL)
289 g_snprintf(string_buff4, SUM_STR_MAX, "%s", dl_description);
291 g_snprintf(string_buff4, SUM_STR_MAX, "DLT %d", iface.linktype);
293 g_snprintf(string_buff3, SUM_STR_MAX, "unknown");
294 g_snprintf(string_buff4, SUM_STR_MAX, "unknown");
296 if (iface.has_snap) {
297 g_snprintf(string_buff5, SUM_STR_MAX, "%u bytes", iface.snap);
299 g_snprintf(string_buff5, SUM_STR_MAX, "unknown");
301 gtk_list_store_append(store, &iter);
302 gtk_list_store_set(store, &iter, 0, string_buff, 1, string_buff2, 2, string_buff3, 3, string_buff4, 4, string_buff5,-1);
304 gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
305 g_object_unref (store);
306 gtk_container_add(GTK_CONTAINER(scrolled_window), treeview);
307 gtk_container_add(GTK_CONTAINER(main_vb),scrolled_window);
308 gtk_widget_show_all (scrolled_window);
309 table = gtk_table_new(1, 2, FALSE);
310 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
311 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
312 gtk_container_add(GTK_CONTAINER(main_vb), table);
317 add_string_to_table(table, &row, "", "");
318 add_string_to_table(table, &row, "Display", "");
320 if (summary.dfilter) {
322 /* limit each row to some reasonable length */
323 str_dup = g_strdup_printf("%s", summary.dfilter);
324 str_work = g_strdup(str_dup);
327 while(strlen(str_work) > FILTER_SNIP_LEN) {
328 str_work[FILTER_SNIP_LEN] = '\0';
329 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
331 offset+=FILTER_SNIP_LEN;
332 str_work = g_strdup(&str_dup[offset]);
336 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
341 add_string_to_table(table, &row, "Display filter:", "none");
344 /* Ignored packet count */
345 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.ignored_count);
346 add_string_to_table(table, &row, "Ignored packets:", string_buff);
349 list = simple_list_new(4, titles);
350 gtk_container_add(GTK_CONTAINER(main_vb), list);
353 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
354 if (summary.dfilter) {
355 g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
357 g_strlcpy(string_buff2, string_buff, SUM_STR_MAX);
359 g_snprintf(string_buff3, SUM_STR_MAX, "%i", summary.marked_count);
360 add_string_to_list(list, "Packets", string_buff, string_buff2, string_buff3);
362 /* Time between first and last */
364 g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
366 string_buff[0] = '\0';
368 if (summary.dfilter && disp_seconds > 0) {
369 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
371 string_buff2[0] = '\0';
373 if (summary.marked_count && marked_seconds > 0) {
374 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f sec", marked_seconds);
376 string_buff3[0] = '\0';
378 add_string_to_list(list, "Between first and last packet", string_buff, string_buff2, string_buff3);
380 /* Packets per second */
382 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
384 string_buff[0] = '\0';
386 if(summary.dfilter && disp_seconds > 0) {
387 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
389 string_buff2[0] = '\0';
391 if(summary.marked_count && marked_seconds > 0) {
392 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", summary.marked_count/marked_seconds);
394 string_buff3[0] = '\0';
396 add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2, string_buff3);
399 if (summary.packet_count > 1) {
400 g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
401 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
402 (float) ((gint64) summary.bytes)/summary.packet_count);
404 string_buff[0] = '\0';
406 if (summary.dfilter && summary.filtered_count > 1) {
407 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f bytes",
408 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
409 (float) ((gint64) summary.filtered_bytes)/summary.filtered_count);
411 string_buff2[0] = '\0';
413 if (summary.marked_count > 1) {
414 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f bytes",
415 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
416 (float) ((gint64) summary.marked_bytes)/summary.marked_count);
418 string_buff3[0] = '\0';
420 add_string_to_list(list, "Avg. packet size", string_buff, string_buff2, string_buff3);
423 g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.bytes);
424 if (summary.dfilter && summary.filtered_count > 0) {
425 g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.filtered_bytes);
427 string_buff2[0] = '\0';
429 if (summary.marked_count) {
430 g_snprintf(string_buff3, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.marked_bytes);
432 string_buff3[0] = '\0';
434 add_string_to_list(list, "Bytes", string_buff, string_buff2, string_buff3);
436 /* Bytes per second */
438 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
439 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes)/seconds);
441 string_buff[0] = '\0';
443 if (summary.dfilter && disp_seconds > 0) {
444 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
445 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", ((gint64) summary.filtered_bytes)/disp_seconds);
447 string_buff2[0] = '\0';
449 if (summary.marked_count && marked_seconds > 0) {
450 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
451 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", ((gint64) summary.marked_bytes)/marked_seconds);
453 string_buff3[0] = '\0';
455 add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2, string_buff3);
457 /* MBit per second */
459 g_snprintf(string_buff, SUM_STR_MAX, "%.3f",
460 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
461 ((gint64) summary.bytes) * 8.0 / (seconds * 1000.0 * 1000.0));
463 string_buff[0] = '\0';
465 if (summary.dfilter && disp_seconds > 0) {
466 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
467 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
468 ((gint64) summary.filtered_bytes) * 8.0 / (disp_seconds * 1000.0 * 1000.0));
470 string_buff2[0] = '\0';
472 if (summary.marked_count && marked_seconds > 0) {
473 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f",
474 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
475 ((gint64) summary.marked_bytes) * 8.0 / (marked_seconds * 1000.0 * 1000.0));
477 string_buff3[0] = '\0';
479 add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2, string_buff3);
483 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
484 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
486 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
487 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
489 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
490 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_SUMMARY_DIALOG);
492 gtk_widget_grab_focus(close_bt);
494 g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
496 gtk_widget_show_all(sum_open_w);
497 window_present(sum_open_w);