2 * Routines for capture file summary window
4 * $Id: summary_dlg.c,v 1.5 2000/07/05 06:19:27 guy 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.
37 #ifdef NEED_SNPRINTF_H
43 # include "snprintf.h"
47 #include "summary_dlg.h"
48 #include "dlg_utils.h"
50 #define SUM_STR_MAX 1024
54 add_string_to_box(gchar *str, GtkWidget *box)
57 lb = gtk_label_new(str);
58 gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
59 gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
65 summary_open_cb(GtkWidget *w, gpointer d)
67 summary_tally summary;
68 GtkWidget *sum_open_w,
69 *main_vb, *file_fr, *data_fr, *capture_fr, *file_box,
70 *data_box, *capture_box, *bbox, *close_bt;
72 gchar string_buff[SUM_STR_MAX];
76 /* initialize the tally */
77 summary_fill_in(&summary);
79 /* initial compututations */
80 seconds = summary.stop_time - summary.start_time;
81 sum_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
82 gtk_window_set_title(GTK_WINDOW(sum_open_w), "Ethereal: Summary");
84 /* Container for each row of widgets */
85 main_vb = gtk_vbox_new(FALSE, 3);
86 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
87 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
88 gtk_widget_show(main_vb);
91 file_fr = gtk_frame_new("File");
92 gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
93 gtk_widget_show(file_fr);
95 file_box = gtk_vbox_new(FALSE, 3);
96 gtk_container_add(GTK_CONTAINER(file_fr), file_box);
97 gtk_widget_show(file_box);
100 snprintf(string_buff, SUM_STR_MAX, "Name: %s", summary.filename);
101 add_string_to_box(string_buff, file_box);
104 snprintf(string_buff, SUM_STR_MAX, "Length: %lu", summary.file_length);
105 add_string_to_box(string_buff, file_box);
108 snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.encap_type));
109 add_string_to_box(string_buff, file_box);
111 /* snapshot length */
112 snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
113 add_string_to_box(string_buff, file_box);
116 data_fr = gtk_frame_new("Data");
117 gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
118 gtk_widget_show(data_fr);
120 data_box = gtk_vbox_new(FALSE, 3);
121 gtk_container_add(GTK_CONTAINER(data_fr), data_box);
122 gtk_widget_show(data_box);
125 snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
126 add_string_to_box(string_buff, data_box);
128 snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
129 add_string_to_box(string_buff, data_box);
132 snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
133 add_string_to_box(string_buff, data_box);
135 /* Filtered Packet count */
136 snprintf(string_buff, SUM_STR_MAX, "Filtered packet count: %i", summary.filtered_count);
137 add_string_to_box(string_buff, data_box);
139 /* Packets per second */
141 snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f", summary.packet_count/seconds);
142 add_string_to_box(string_buff, data_box);
146 snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %i", summary.drops);
147 add_string_to_box(string_buff, data_box);
150 snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d", summary.bytes);
151 add_string_to_box(string_buff, data_box);
153 /* Bytes per second */
155 snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f", summary.bytes/seconds);
156 add_string_to_box(string_buff, data_box);
160 capture_fr = gtk_frame_new("Capture");
161 gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
162 gtk_widget_show(capture_fr);
164 capture_box = gtk_vbox_new(FALSE, 3);
165 gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
166 gtk_widget_show(capture_box);
171 snprintf(string_buff, SUM_STR_MAX, "Interface: %s", summary.iface);
173 sprintf(string_buff, "Interface: unknown");
175 add_string_to_box(string_buff, capture_box);
178 if (summary.dfilter) {
179 snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", summary.dfilter);
181 sprintf(string_buff, "Display filter: none");
183 add_string_to_box(string_buff, capture_box);
187 if (summary.cfilter && summary.cfilter[0] != '\0') {
188 snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", summary.cfilter);
190 sprintf(string_buff, "Capture filter: none");
192 add_string_to_box(string_buff, capture_box);
195 /* Button row: close button.
196 (We put it in an HButtonBox, even though there's only one of them,
197 so that it doesn't expand to the width of the window. */
198 bbox = gtk_hbutton_box_new();
199 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
200 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
201 gtk_widget_show(bbox);
203 /* Create Close Button */
204 close_bt = gtk_button_new_with_label("Close");
205 gtk_signal_connect_object(GTK_OBJECT(close_bt), "clicked",
206 GTK_SIGNAL_FUNC(gtk_widget_destroy),
207 GTK_OBJECT(sum_open_w));
208 GTK_WIDGET_SET_FLAGS(close_bt, GTK_CAN_DEFAULT);
209 gtk_box_pack_start(GTK_BOX(bbox), close_bt, FALSE,FALSE, 0);
210 gtk_widget_grab_default(close_bt);
211 gtk_widget_show(close_bt);
213 /* Catch the "key_press_event" signal in the window, so that we can catch
214 the ESC key being pressed and act as if the "Close" button had
216 dlg_set_cancel(sum_open_w, close_bt);
218 gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
219 gtk_widget_show(sum_open_w);