2 * Routines for capture file summary window
4 * $Id: summary_dlg.c,v 1.16 2002/11/03 17:38:34 oabad Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef NEED_SNPRINTF_H
36 # include "snprintf.h"
40 #include "summary_dlg.h"
41 #include "dlg_utils.h"
44 #define SUM_STR_MAX 1024
48 add_string_to_box(gchar *str, GtkWidget *box)
51 lb = gtk_label_new(str);
52 gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
53 gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
59 summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
61 summary_tally summary;
62 GtkWidget *sum_open_w,
63 *main_vb, *file_fr, *data_fr, *capture_fr, *file_box,
64 *data_box, *capture_box, *bbox, *close_bt;
66 gchar string_buff[SUM_STR_MAX];
70 /* initialize the tally */
71 summary_fill_in(&summary);
73 /* initial compututations */
74 seconds = summary.stop_time - summary.start_time;
75 sum_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
76 gtk_window_set_title(GTK_WINDOW(sum_open_w), "Ethereal: Summary");
77 #if GTK_MAJOR_VERSION < 2
78 gtk_signal_connect(GTK_OBJECT(sum_open_w), "realize",
79 GTK_SIGNAL_FUNC(window_icon_realize_cb), NULL);
81 g_signal_connect(G_OBJECT(sum_open_w), "realize",
82 G_CALLBACK(window_icon_realize_cb), NULL);
85 /* Container for each row of widgets */
86 main_vb = gtk_vbox_new(FALSE, 3);
87 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
88 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
89 gtk_widget_show(main_vb);
92 file_fr = gtk_frame_new("File");
93 gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
94 gtk_widget_show(file_fr);
96 file_box = gtk_vbox_new(FALSE, 3);
97 gtk_container_add(GTK_CONTAINER(file_fr), file_box);
98 gtk_widget_show(file_box);
101 snprintf(string_buff, SUM_STR_MAX, "Name: %s", summary.filename);
102 add_string_to_box(string_buff, file_box);
105 snprintf(string_buff, SUM_STR_MAX, "Length: %lu", summary.file_length);
106 add_string_to_box(string_buff, file_box);
109 snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.encap_type));
110 add_string_to_box(string_buff, file_box);
112 if (summary.has_snap) {
113 /* snapshot length */
114 snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
115 add_string_to_box(string_buff, file_box);
119 data_fr = gtk_frame_new("Data");
120 gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
121 gtk_widget_show(data_fr);
123 data_box = gtk_vbox_new(FALSE, 3);
124 gtk_container_add(GTK_CONTAINER(data_fr), data_box);
125 gtk_widget_show(data_box);
128 snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
129 add_string_to_box(string_buff, data_box);
131 snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
132 add_string_to_box(string_buff, data_box);
135 snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
136 add_string_to_box(string_buff, data_box);
138 /* Filtered Packet count */
139 snprintf(string_buff, SUM_STR_MAX, "Filtered packet count: %i", summary.filtered_count);
140 add_string_to_box(string_buff, data_box);
142 /* Marked Packet count */
143 snprintf(string_buff, SUM_STR_MAX, "Marked packet count: %i", summary.marked_count);
144 add_string_to_box(string_buff, data_box);
146 /* Packets per second */
148 snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f", summary.packet_count/seconds);
149 add_string_to_box(string_buff, data_box);
153 if (summary.drops_known) {
154 snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %u", summary.drops);
155 add_string_to_box(string_buff, data_box);
159 snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d", summary.bytes);
160 add_string_to_box(string_buff, data_box);
162 /* Bytes per second */
164 snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f", summary.bytes/seconds);
165 add_string_to_box(string_buff, data_box);
167 /* MBit per second */
168 snprintf(string_buff, SUM_STR_MAX, "Avg. Mbit/sec: %.3f",
169 summary.bytes * 8.0 / (seconds * 1000.0 * 1000.0));
170 add_string_to_box(string_buff, data_box);
174 capture_fr = gtk_frame_new("Capture");
175 gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
176 gtk_widget_show(capture_fr);
178 capture_box = gtk_vbox_new(FALSE, 3);
179 gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
180 gtk_widget_show(capture_box);
185 snprintf(string_buff, SUM_STR_MAX, "Interface: %s", summary.iface);
187 sprintf(string_buff, "Interface: unknown");
189 add_string_to_box(string_buff, capture_box);
192 if (summary.dfilter) {
193 snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", summary.dfilter);
195 sprintf(string_buff, "Display filter: none");
197 add_string_to_box(string_buff, capture_box);
201 if (summary.cfilter && summary.cfilter[0] != '\0') {
202 snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", summary.cfilter);
204 sprintf(string_buff, "Capture filter: none");
206 add_string_to_box(string_buff, capture_box);
209 /* Button row: close button.
210 (We put it in an HButtonBox, even though there's only one of them,
211 so that it doesn't expand to the width of the window. */
212 bbox = gtk_hbutton_box_new();
213 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
214 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
215 gtk_widget_show(bbox);
217 /* Create Close Button */
218 #if GTK_MAJOR_VERSION < 2
219 close_bt = gtk_button_new_with_label("Close");
220 gtk_signal_connect_object(GTK_OBJECT(close_bt), "clicked",
221 GTK_SIGNAL_FUNC(gtk_widget_destroy),
222 GTK_OBJECT(sum_open_w));
224 close_bt = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
225 g_signal_connect_swapped(G_OBJECT(close_bt), "clicked",
226 G_CALLBACK(gtk_widget_destroy),
227 G_OBJECT(sum_open_w));
229 GTK_WIDGET_SET_FLAGS(close_bt, GTK_CAN_DEFAULT);
230 gtk_box_pack_start(GTK_BOX(bbox), close_bt, FALSE,FALSE, 0);
231 gtk_widget_grab_default(close_bt);
232 gtk_widget_show(close_bt);
234 /* Catch the "key_press_event" signal in the window, so that we can catch
235 the ESC key being pressed and act as if the "Close" button had
237 dlg_set_cancel(sum_open_w, close_bt);
239 gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
240 gtk_widget_show(sum_open_w);