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"
45 #include "../capture.h"
47 #include "gtk/capture_globals.h"
50 #include "gtk/summary_dlg.h"
51 #include "gtk/dlg_utils.h"
52 #include "gtk/gui_utils.h"
53 #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.0, 0.5);
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.0, 0.5);
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;
111 static const char *titles[] = { "Traffic", "Captured", "Displayed", "Marked" };
113 gchar string_buff[SUM_STR_MAX];
114 gchar string_buff2[SUM_STR_MAX];
115 gchar string_buff3[SUM_STR_MAX];
119 double marked_seconds;
128 unsigned int elapsed_time;
130 /* initial computations */
131 summary_fill_in(&cfile, &summary);
133 summary_fill_in_capture(&global_capture_opts, &summary);
135 seconds = summary.stop_time - summary.start_time;
136 disp_seconds = summary.filtered_stop - summary.filtered_start;
137 marked_seconds = summary.marked_stop - summary.marked_start;
139 sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Wireshark: Summary");
141 /* Container for each row of widgets */
142 main_vb = gtk_vbox_new(FALSE, 12);
143 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 12);
144 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
147 table = gtk_table_new(1, 2, FALSE);
148 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
149 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
150 gtk_container_add(GTK_CONTAINER(main_vb), table);
155 add_string_to_table(table, &row, "File", "");
158 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.filename);
159 add_string_to_table(table, &row, "Name:", string_buff);
162 g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "d bytes", summary.file_length);
163 add_string_to_table(table, &row, "Length:", string_buff);
166 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.file_type));
167 add_string_to_table(table, &row, "Format:", string_buff);
170 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.encap_type));
171 add_string_to_table(table, &row, "Encapsulation:", string_buff);
173 if (summary.has_snap) {
174 /* snapshot length */
175 g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
176 add_string_to_table(table, &row, "Packet size limit:", string_buff);
181 add_string_to_table(table, &row, "", "");
182 add_string_to_table(table, &row, "Time", "");
185 ti_time = (time_t)summary.start_time;
186 ti_tm = localtime(&ti_time);
187 g_snprintf(string_buff, SUM_STR_MAX,
188 "%04d-%02d-%02d %02d:%02d:%02d",
189 ti_tm->tm_year + 1900,
195 add_string_to_table(table, &row, "First packet:", string_buff);
198 ti_time = (time_t)summary.stop_time;
199 ti_tm = localtime(&ti_time);
200 g_snprintf(string_buff, SUM_STR_MAX,
201 "%04d-%02d-%02d %02d:%02d:%02d",
202 ti_tm->tm_year + 1900,
208 add_string_to_table(table, &row, "Last packet:", string_buff);
210 /* elapsed seconds */
211 elapsed_time = (unsigned int)summary.elapsed_time;
212 if(elapsed_time/86400) {
213 g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
214 elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
216 g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
217 elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
219 add_string_to_table(table, &row, "Elapsed:", string_buff);
223 add_string_to_table(table, &row, "", "");
224 add_string_to_table_sensitive(table, &row, "Capture", "", (summary.iface != NULL));
228 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.iface_descr);
230 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
232 add_string_to_table_sensitive(table, &row, "Interface:", string_buff, (summary.iface) != NULL);
235 if (summary.drops_known) {
236 g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.drops);
238 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
240 add_string_to_table_sensitive(table, &row, "Dropped packets:", string_buff, (summary.iface != NULL));
244 if (summary.cfilter && summary.cfilter[0] != '\0') {
245 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.cfilter);
248 g_snprintf(string_buff, SUM_STR_MAX, "none");
250 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
253 add_string_to_table_sensitive(table, &row, "Capture filter:", string_buff, (summary.iface != NULL));
258 add_string_to_table(table, &row, "", "");
259 add_string_to_table(table, &row, "Display", "");
261 if (summary.dfilter) {
263 /* limit each row to some reasonable length */
264 str_dup = g_strdup_printf("%s", summary.dfilter);
265 str_work = g_strdup(str_dup);
268 while(strlen(str_work) > FILTER_SNIP_LEN) {
269 str_work[FILTER_SNIP_LEN] = '\0';
270 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
272 offset+=FILTER_SNIP_LEN;
273 str_work = g_strdup(&str_dup[offset]);
277 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
282 add_string_to_table(table, &row, "Display filter:", "none");
286 list = simple_list_new(4, titles);
287 gtk_container_add(GTK_CONTAINER(main_vb), list);
290 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
291 if (summary.dfilter) {
292 g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
294 g_strlcpy(string_buff2, string_buff, SUM_STR_MAX);
296 g_snprintf(string_buff3, SUM_STR_MAX, "%i", summary.marked_count);
297 add_string_to_list(list, "Packets", string_buff, string_buff2, string_buff3);
299 /* Time between first and last */
301 g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
303 string_buff[0] = '\0';
305 if (summary.dfilter && disp_seconds > 0) {
306 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
308 string_buff2[0] = '\0';
310 if (summary.marked_count && marked_seconds > 0) {
311 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f sec", marked_seconds);
313 string_buff3[0] = '\0';
315 add_string_to_list(list, "Between first and last packet", string_buff, string_buff2, string_buff3);
317 /* Packets per second */
319 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
321 string_buff[0] = '\0';
323 if(summary.dfilter && disp_seconds > 0) {
324 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
326 string_buff2[0] = '\0';
328 if(summary.marked_count && marked_seconds > 0) {
329 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", summary.marked_count/marked_seconds);
331 string_buff3[0] = '\0';
333 add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2, string_buff3);
336 if (summary.packet_count > 1) {
337 g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
338 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
339 (float) ((gint64) summary.bytes)/summary.packet_count);
341 string_buff[0] = '\0';
343 if (summary.dfilter && summary.filtered_count > 1) {
344 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f bytes",
345 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
346 (float) ((gint64) summary.filtered_bytes)/summary.filtered_count);
348 string_buff2[0] = '\0';
350 if (summary.marked_count > 1) {
351 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f bytes",
352 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
353 (float) ((gint64) summary.marked_bytes)/summary.marked_count);
355 string_buff3[0] = '\0';
357 add_string_to_list(list, "Avg. packet size", string_buff, string_buff2, string_buff3);
360 g_snprintf(string_buff, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.bytes);
361 if (summary.dfilter && summary.filtered_count > 0) {
362 g_snprintf(string_buff2, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.filtered_bytes);
364 string_buff2[0] = '\0';
366 if (summary.marked_count) {
367 g_snprintf(string_buff3, SUM_STR_MAX, "%" G_GINT64_MODIFIER "u", summary.marked_bytes);
369 string_buff3[0] = '\0';
371 add_string_to_list(list, "Bytes", string_buff, string_buff2, string_buff3);
373 /* Bytes per second */
375 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
376 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes)/seconds);
378 string_buff[0] = '\0';
380 if (summary.dfilter && disp_seconds > 0) {
381 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
382 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", ((gint64) summary.filtered_bytes)/disp_seconds);
384 string_buff2[0] = '\0';
386 if (summary.marked_count && marked_seconds > 0) {
387 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
388 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f", ((gint64) summary.marked_bytes)/marked_seconds);
390 string_buff3[0] = '\0';
392 add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2, string_buff3);
394 /* MBit per second */
396 g_snprintf(string_buff, SUM_STR_MAX, "%.3f",
397 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
398 ((gint64) summary.bytes) * 8.0 / (seconds * 1000.0 * 1000.0));
400 string_buff[0] = '\0';
402 if (summary.dfilter && disp_seconds > 0) {
403 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
404 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
405 ((gint64) summary.filtered_bytes) * 8.0 / (disp_seconds * 1000.0 * 1000.0));
407 string_buff2[0] = '\0';
409 if (summary.marked_count && marked_seconds > 0) {
410 g_snprintf(string_buff3, SUM_STR_MAX, "%.3f",
411 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
412 ((gint64) summary.marked_bytes) * 8.0 / (marked_seconds * 1000.0 * 1000.0));
414 string_buff3[0] = '\0';
416 add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2, string_buff3);
420 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
421 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
423 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
424 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
426 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
427 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_SUMMARY_DIALOG);
429 gtk_widget_grab_focus(close_bt);
431 g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
433 gtk_widget_show_all(sum_open_w);
434 window_present(sum_open_w);