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.
44 #include "summary_dlg.h"
45 #include "dlg_utils.h"
47 #include "compat_macros.h"
50 #define SUM_STR_MAX 1024
51 #define FILTER_SNIP_LEN 50
55 add_string_to_table_sensitive(GtkWidget *list, guint *row, gchar *title, gchar *value, gboolean sensitive)
60 if(strlen(value) != 0) {
61 indent = g_strdup_printf(" %s", title);
63 indent = g_strdup(title);
65 label = gtk_label_new(indent);
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, 0, 1, *row, *row+1);
71 label = gtk_label_new(value);
72 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
73 gtk_widget_set_sensitive(label, sensitive);
74 gtk_table_attach_defaults(GTK_TABLE(list), label, 1, 2, *row, *row+1);
80 add_string_to_table(GtkWidget *list, guint *row, gchar *title, gchar *value)
82 add_string_to_table_sensitive(list, row, title, value, TRUE);
87 add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed)
89 simple_list_append(list, 0, title, 1, captured, 2, displayed, -1);
93 summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
95 summary_tally summary;
96 GtkWidget *sum_open_w,
97 *main_vb, *bbox, *close_bt, *help_bt;
100 char *titles[] = { "Traffic", "Captured", "Displayed" };
102 gchar string_buff[SUM_STR_MAX];
103 gchar string_buff2[SUM_STR_MAX];
115 unsigned int elapsed_time;
117 /* initial computations */
118 summary_fill_in(&cfile, &summary);
120 summary_fill_in_capture(capture_opts, &summary);
122 seconds = summary.stop_time - summary.start_time;
123 disp_seconds = summary.filtered_stop - summary.filtered_start;
125 sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: Summary");
127 /* Container for each row of widgets */
128 main_vb = gtk_vbox_new(FALSE, 12);
129 gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
130 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
133 table = gtk_table_new(1, 2, FALSE);
134 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
135 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
136 gtk_container_add(GTK_CONTAINER(main_vb), table);
141 add_string_to_table(table, &row, "File", "");
144 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.filename);
145 add_string_to_table(table, &row, "Name:", string_buff);
148 g_snprintf(string_buff, SUM_STR_MAX, "%lu bytes", summary.file_length);
149 add_string_to_table(table, &row, "Length:", string_buff);
152 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.encap_type));
153 add_string_to_table(table, &row, "Format:", string_buff);
155 if (summary.has_snap) {
156 /* snapshot length */
157 g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
158 add_string_to_table(table, &row, "Packet size limit:", string_buff);
163 add_string_to_table(table, &row, "", "");
164 add_string_to_table(table, &row, "Time", "");
167 ti_time = (time_t)summary.start_time;
168 ti_tm = localtime(&ti_time);
169 g_snprintf(string_buff, SUM_STR_MAX,
170 "%04d-%02d-%02d %02d:%02d:%02d",
171 ti_tm->tm_year + 1900,
177 add_string_to_table(table, &row, "First packet:", string_buff);
180 ti_time = (time_t)summary.stop_time;
181 ti_tm = localtime(&ti_time);
182 g_snprintf(string_buff, SUM_STR_MAX,
183 "%04d-%02d-%02d %02d:%02d:%02d",
184 ti_tm->tm_year + 1900,
190 add_string_to_table(table, &row, "Last packet:", string_buff);
192 /* elapsed seconds */
193 elapsed_time = (unsigned int)summary.elapsed_time;
194 if(elapsed_time/86400) {
195 g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
196 elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
198 g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
199 elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
201 add_string_to_table(table, &row, "Elapsed:", string_buff);
205 add_string_to_table(table, &row, "", "");
206 add_string_to_table_sensitive(table, &row, "Capture", "", (summary.iface != NULL));
210 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.iface_descr);
212 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
214 add_string_to_table_sensitive(table, &row, "Interface:", string_buff, (summary.iface) != NULL);
217 if (summary.drops_known) {
218 g_snprintf(string_buff, SUM_STR_MAX, "%u", summary.drops);
220 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
222 add_string_to_table_sensitive(table, &row, "Dropped packets:", string_buff, (summary.iface != NULL));
226 if (summary.cfilter && summary.cfilter[0] != '\0') {
227 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.cfilter);
230 g_snprintf(string_buff, SUM_STR_MAX, "none");
232 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
235 add_string_to_table_sensitive(table, &row, "Capture filter:", string_buff, (summary.iface != NULL));
240 add_string_to_table(table, &row, "", "");
241 add_string_to_table(table, &row, "Display", "");
243 if (summary.dfilter) {
245 /* limit each row to some reasonable length */
246 str_dup = g_strdup_printf("%s", summary.dfilter);
247 str_work = g_strdup(str_dup);
250 while(strlen(str_work) > FILTER_SNIP_LEN) {
251 str_work[FILTER_SNIP_LEN] = '\0';
252 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
254 offset+=FILTER_SNIP_LEN;
255 str_work = g_strdup(&str_dup[offset]);
259 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
264 add_string_to_table(table, &row, "Display filter:", "none");
267 /* Marked Packet count */
268 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.marked_count);
269 add_string_to_table(table, &row, "Marked packets:", string_buff);
273 list = simple_list_new(3, titles);
274 gtk_container_add(GTK_CONTAINER(main_vb), list);
276 g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
277 if(summary.dfilter) {
278 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
280 strcpy(string_buff2, "");
282 add_string_to_list(list, "Between first and last packet", string_buff, string_buff2);
285 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
286 if(summary.dfilter) {
287 g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
289 strcpy(string_buff2, "");
291 add_string_to_list(list, "Packets", string_buff, string_buff2);
293 /* Packets per second */
295 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
297 strcpy(string_buff, "");
299 if(summary.dfilter && disp_seconds > 0){
300 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
302 strcpy(string_buff2, "");
304 add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2);
307 if (summary.packet_count > 0){
308 g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
309 (float)summary.bytes/summary.packet_count);
311 strcpy(string_buff, "");
313 if (summary.dfilter && summary.filtered_count > 0){
314 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f bytes",
315 (float) summary.filtered_bytes/summary.filtered_count);
317 strcpy(string_buff2, "");
319 add_string_to_list(list, "Avg. packet size", string_buff, string_buff2);
322 g_snprintf(string_buff, SUM_STR_MAX, "%d", summary.bytes);
323 if (summary.dfilter && summary.filtered_count > 0){
324 g_snprintf(string_buff2, SUM_STR_MAX, "%d", summary.filtered_bytes);
326 strcpy(string_buff2, "");
328 add_string_to_list(list, "Bytes", string_buff, string_buff2);
330 /* Bytes per second */
332 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.bytes/seconds);
334 strcpy(string_buff, "");
336 if (summary.dfilter && disp_seconds > 0){
337 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_bytes/disp_seconds);
339 strcpy(string_buff2, "");
341 add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2);
343 /* MBit per second */
345 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.bytes * 8.0 / (seconds * 1000.0 * 1000.0));
347 strcpy(string_buff, "");
349 if (summary.dfilter && disp_seconds > 0){
350 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
351 summary.filtered_bytes * 8.0 / (disp_seconds * 1000.0 * 1000.0));
353 strcpy(string_buff2, "");
355 add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2);
359 if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
360 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
362 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
364 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
366 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
367 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
369 if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
370 help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
371 SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_STATS_SUMMARY_DIALOG);
374 gtk_widget_grab_focus(close_bt);
376 SIGNAL_CONNECT(sum_open_w, "delete_event", window_delete_event_cb, NULL);
378 gtk_widget_show_all(sum_open_w);
379 window_present(sum_open_w);