2 * Routines for capture file summary window
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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.
39 #include "summary_dlg.h"
40 #include "dlg_utils.h"
42 #include "compat_macros.h"
45 #define SUM_STR_MAX 1024
46 #define FILTER_SNIP_LEN 50
50 add_string_to_table_sensitive(GtkWidget *list, guint *row, gchar *title, gchar *value, gboolean sensitive)
55 if(strlen(value) != 0) {
56 indent = g_strdup_printf(" %s", title);
58 indent = g_strdup(title);
60 label = gtk_label_new(indent);
62 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
63 gtk_widget_set_sensitive(label, sensitive);
64 gtk_table_attach_defaults(GTK_TABLE(list), label, 0, 1, *row, *row+1);
66 label = gtk_label_new(value);
67 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
68 gtk_widget_set_sensitive(label, sensitive);
69 gtk_table_attach_defaults(GTK_TABLE(list), label, 1, 2, *row, *row+1);
75 add_string_to_table(GtkWidget *list, guint *row, gchar *title, gchar *value)
77 add_string_to_table_sensitive(list, row, title, value, TRUE);
82 add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed)
84 simple_list_append(list, 0, title, 1, captured, 2, displayed, -1);
88 summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
90 summary_tally summary;
91 GtkWidget *sum_open_w,
92 *main_vb, *bbox, *close_bt, *help_bt;
95 char *titles[] = { "Traffic", "Captured", "Displayed" };
97 gchar string_buff[SUM_STR_MAX];
98 gchar string_buff2[SUM_STR_MAX];
110 unsigned int elapsed_time;
112 /* initial computations */
113 summary_fill_in(&cfile, &summary);
114 seconds = summary.stop_time - summary.start_time;
115 disp_seconds = summary.filtered_stop - summary.filtered_start;
117 sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: Summary");
119 /* Container for each row of widgets */
120 main_vb = gtk_vbox_new(FALSE, 12);
121 gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
122 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
125 table = gtk_table_new(1, 2, FALSE);
126 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
127 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
128 gtk_container_add(GTK_CONTAINER(main_vb), table);
133 add_string_to_table(table, &row, "File", "");
136 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.filename);
137 add_string_to_table(table, &row, "Name:", string_buff);
140 g_snprintf(string_buff, SUM_STR_MAX, "%lu bytes", summary.file_length);
141 add_string_to_table(table, &row, "Length:", string_buff);
144 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.encap_type));
145 add_string_to_table(table, &row, "Format:", string_buff);
147 if (summary.has_snap) {
148 /* snapshot length */
149 g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
150 add_string_to_table(table, &row, "Packet size limit:", string_buff);
155 add_string_to_table(table, &row, "", "");
156 add_string_to_table(table, &row, "Time", "");
159 ti_time = (time_t)summary.start_time;
160 ti_tm = localtime(&ti_time);
161 g_snprintf(string_buff, SUM_STR_MAX,
162 "%04d-%02d-%02d %02d:%02d:%02d",
163 ti_tm->tm_year + 1900,
169 add_string_to_table(table, &row, "First packet:", string_buff);
172 ti_time = (time_t)summary.stop_time;
173 ti_tm = localtime(&ti_time);
174 g_snprintf(string_buff, SUM_STR_MAX,
175 "%04d-%02d-%02d %02d:%02d:%02d",
176 ti_tm->tm_year + 1900,
182 add_string_to_table(table, &row, "Last packet:", string_buff);
184 /* elapsed seconds */
185 elapsed_time = (unsigned int)summary.elapsed_time;
186 if(elapsed_time/86400) {
187 g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
188 elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
190 g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
191 elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
193 add_string_to_table(table, &row, "Elapsed:", string_buff);
197 add_string_to_table(table, &row, "", "");
198 add_string_to_table_sensitive(table, &row, "Capture", "", (summary.iface != NULL));
202 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.iface);
204 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
206 add_string_to_table_sensitive(table, &row, "Interface:", string_buff, (summary.iface) != NULL);
209 if (summary.drops_known) {
210 g_snprintf(string_buff, SUM_STR_MAX, "%u", summary.drops);
212 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
214 add_string_to_table_sensitive(table, &row, "Dropped packets:", string_buff, (summary.iface != NULL));
218 if (summary.cfilter && summary.cfilter[0] != '\0') {
219 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.cfilter);
222 g_snprintf(string_buff, SUM_STR_MAX, "none");
224 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
227 add_string_to_table_sensitive(table, &row, "Capture filter:", string_buff, (summary.iface != NULL));
232 add_string_to_table(table, &row, "", "");
233 add_string_to_table(table, &row, "Display", "");
235 if (summary.dfilter) {
237 /* limit each row to some reasonable length */
238 str_dup = g_strdup_printf("%s", summary.dfilter);
239 str_work = g_strdup(str_dup);
242 while(strlen(str_work) > FILTER_SNIP_LEN) {
243 str_work[FILTER_SNIP_LEN] = '\0';
244 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
246 offset+=FILTER_SNIP_LEN;
247 str_work = g_strdup(&str_dup[offset]);
251 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
256 add_string_to_table(table, &row, "Display filter:", "none");
259 /* Marked Packet count */
260 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.marked_count);
261 add_string_to_table(table, &row, "Marked packets:", string_buff);
265 list = simple_list_new(3, titles);
266 gtk_container_add(GTK_CONTAINER(main_vb), list);
268 g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
269 if(summary.dfilter) {
270 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
272 strcpy(string_buff2, "");
274 add_string_to_list(list, "Between first and last packet", string_buff, string_buff2);
277 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
278 if(summary.dfilter) {
279 g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
281 strcpy(string_buff2, "");
283 add_string_to_list(list, "Packets", string_buff, string_buff2);
285 /* Packets per second */
287 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
289 strcpy(string_buff, "");
291 if(summary.dfilter && disp_seconds > 0){
292 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
294 strcpy(string_buff2, "");
296 add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2);
299 if (summary.packet_count > 0){
300 g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
301 (float)summary.bytes/summary.packet_count);
303 strcpy(string_buff, "");
305 if (summary.dfilter && summary.filtered_count > 0){
306 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f bytes",
307 (float) summary.filtered_bytes/summary.filtered_count);
309 strcpy(string_buff2, "");
311 add_string_to_list(list, "Avg. packet size", string_buff, string_buff2);
314 g_snprintf(string_buff, SUM_STR_MAX, "%d", summary.bytes);
315 if (summary.dfilter && summary.filtered_count > 0){
316 g_snprintf(string_buff2, SUM_STR_MAX, "%d", summary.filtered_bytes);
318 strcpy(string_buff2, "");
320 add_string_to_list(list, "Bytes", string_buff, string_buff2);
322 /* Bytes per second */
324 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.bytes/seconds);
326 strcpy(string_buff, "");
328 if (summary.dfilter && disp_seconds > 0){
329 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_bytes/disp_seconds);
331 strcpy(string_buff2, "");
333 add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2);
335 /* MBit per second */
337 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.bytes * 8.0 / (seconds * 1000.0 * 1000.0));
339 strcpy(string_buff, "");
341 if (summary.dfilter && disp_seconds > 0){
342 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
343 summary.filtered_bytes * 8.0 / (disp_seconds * 1000.0 * 1000.0));
345 strcpy(string_buff2, "");
347 add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2);
351 if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
352 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
354 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
356 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
358 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
359 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
361 if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
362 help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
363 SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_STATS_SUMMARY_DIALOG);
366 gtk_widget_grab_focus(close_bt);
368 SIGNAL_CONNECT(sum_open_w, "delete_event", window_delete_event_cb, NULL);
370 gtk_widget_show_all(sum_open_w);
371 window_present(sum_open_w);