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.
43 #include "summary_dlg.h"
44 #include "dlg_utils.h"
45 #include "gui_utils.h"
46 #include "compat_macros.h"
49 #define SUM_STR_MAX 1024
50 #define FILTER_SNIP_LEN 50
54 add_string_to_table_sensitive(GtkWidget *list, guint *row, gchar *title, gchar *value, gboolean sensitive)
59 if(strlen(value) != 0) {
60 indent = g_strdup_printf(" %s", title);
62 indent = g_strdup(title);
64 label = gtk_label_new(indent);
66 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
67 gtk_widget_set_sensitive(label, sensitive);
68 gtk_table_attach_defaults(GTK_TABLE(list), label, 0, 1, *row, *row+1);
70 label = gtk_label_new(value);
71 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
72 gtk_widget_set_sensitive(label, sensitive);
73 gtk_table_attach_defaults(GTK_TABLE(list), label, 1, 2, *row, *row+1);
79 add_string_to_table(GtkWidget *list, guint *row, gchar *title, gchar *value)
81 add_string_to_table_sensitive(list, row, title, value, TRUE);
86 add_string_to_list(GtkWidget *list, gchar *title, gchar *captured, gchar *displayed)
88 simple_list_append(list, 0, title, 1, captured, 2, displayed, -1);
92 summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
94 summary_tally summary;
95 GtkWidget *sum_open_w,
96 *main_vb, *bbox, *close_bt, *help_bt;
99 static const char *titles[] = { "Traffic", "Captured", "Displayed" };
101 gchar string_buff[SUM_STR_MAX];
102 gchar string_buff2[SUM_STR_MAX];
114 unsigned int elapsed_time;
116 /* initial computations */
117 summary_fill_in(&cfile, &summary);
119 summary_fill_in_capture(capture_opts, &summary);
121 seconds = summary.stop_time - summary.start_time;
122 disp_seconds = summary.filtered_stop - summary.filtered_start;
124 sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: Summary");
126 /* Container for each row of widgets */
127 main_vb = gtk_vbox_new(FALSE, 12);
128 gtk_container_border_width(GTK_CONTAINER(main_vb), 12);
129 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
132 table = gtk_table_new(1, 2, FALSE);
133 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
134 gtk_table_set_row_spacings(GTK_TABLE(table), 3);
135 gtk_container_add(GTK_CONTAINER(main_vb), table);
140 add_string_to_table(table, &row, "File", "");
143 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.filename);
144 add_string_to_table(table, &row, "Name:", string_buff);
147 g_snprintf(string_buff, SUM_STR_MAX, "%lu bytes", summary.file_length);
148 add_string_to_table(table, &row, "Length:", string_buff);
151 g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.encap_type));
152 add_string_to_table(table, &row, "Format:", string_buff);
154 if (summary.has_snap) {
155 /* snapshot length */
156 g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap);
157 add_string_to_table(table, &row, "Packet size limit:", string_buff);
162 add_string_to_table(table, &row, "", "");
163 add_string_to_table(table, &row, "Time", "");
166 ti_time = (time_t)summary.start_time;
167 ti_tm = localtime(&ti_time);
168 g_snprintf(string_buff, SUM_STR_MAX,
169 "%04d-%02d-%02d %02d:%02d:%02d",
170 ti_tm->tm_year + 1900,
176 add_string_to_table(table, &row, "First packet:", string_buff);
179 ti_time = (time_t)summary.stop_time;
180 ti_tm = localtime(&ti_time);
181 g_snprintf(string_buff, SUM_STR_MAX,
182 "%04d-%02d-%02d %02d:%02d:%02d",
183 ti_tm->tm_year + 1900,
189 add_string_to_table(table, &row, "Last packet:", string_buff);
191 /* elapsed seconds */
192 elapsed_time = (unsigned int)summary.elapsed_time;
193 if(elapsed_time/86400) {
194 g_snprintf(string_buff, SUM_STR_MAX, "%02u days %02u:%02u:%02u",
195 elapsed_time/86400, elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
197 g_snprintf(string_buff, SUM_STR_MAX, "%02u:%02u:%02u",
198 elapsed_time%86400/3600, elapsed_time%3600/60, elapsed_time%60);
200 add_string_to_table(table, &row, "Elapsed:", string_buff);
204 add_string_to_table(table, &row, "", "");
205 add_string_to_table_sensitive(table, &row, "Capture", "", (summary.iface != NULL));
209 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.iface_descr);
211 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
213 add_string_to_table_sensitive(table, &row, "Interface:", string_buff, (summary.iface) != NULL);
216 if (summary.drops_known) {
217 g_snprintf(string_buff, SUM_STR_MAX, "%" PRIu64, summary.drops);
219 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
221 add_string_to_table_sensitive(table, &row, "Dropped packets:", string_buff, (summary.iface != NULL));
225 if (summary.cfilter && summary.cfilter[0] != '\0') {
226 g_snprintf(string_buff, SUM_STR_MAX, "%s", summary.cfilter);
229 g_snprintf(string_buff, SUM_STR_MAX, "none");
231 g_snprintf(string_buff, SUM_STR_MAX, "unknown");
234 add_string_to_table_sensitive(table, &row, "Capture filter:", string_buff, (summary.iface != NULL));
239 add_string_to_table(table, &row, "", "");
240 add_string_to_table(table, &row, "Display", "");
242 if (summary.dfilter) {
244 /* limit each row to some reasonable length */
245 str_dup = g_strdup_printf("%s", summary.dfilter);
246 str_work = g_strdup(str_dup);
249 while(strlen(str_work) > FILTER_SNIP_LEN) {
250 str_work[FILTER_SNIP_LEN] = '\0';
251 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
253 offset+=FILTER_SNIP_LEN;
254 str_work = g_strdup(&str_dup[offset]);
258 add_string_to_table(table, &row, (snip == 0) ? "Display filter:" : "", str_work);
263 add_string_to_table(table, &row, "Display filter:", "none");
266 /* Marked Packet count */
267 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.marked_count);
268 add_string_to_table(table, &row, "Marked packets:", string_buff);
272 list = simple_list_new(3, titles);
273 gtk_container_add(GTK_CONTAINER(main_vb), list);
275 g_snprintf(string_buff, SUM_STR_MAX, "%.3f sec", seconds);
276 if(summary.dfilter) {
277 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f sec", disp_seconds);
279 strcpy(string_buff2, "");
281 add_string_to_list(list, "Between first and last packet", string_buff, string_buff2);
284 g_snprintf(string_buff, SUM_STR_MAX, "%i", summary.packet_count);
285 if(summary.dfilter) {
286 g_snprintf(string_buff2, SUM_STR_MAX, "%i", summary.filtered_count);
288 strcpy(string_buff2, "");
290 add_string_to_list(list, "Packets", string_buff, string_buff2);
292 /* Packets per second */
294 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", summary.packet_count/seconds);
296 strcpy(string_buff, "");
298 if(summary.dfilter && disp_seconds > 0){
299 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", summary.filtered_count/disp_seconds);
301 strcpy(string_buff2, "");
303 add_string_to_list(list, "Avg. packets/sec", string_buff, string_buff2);
306 if (summary.packet_count > 0){
307 g_snprintf(string_buff, SUM_STR_MAX, "%.3f bytes",
308 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
309 (float) (gint64) (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 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
316 (float) (gint64) summary.filtered_bytes/summary.filtered_count);
318 strcpy(string_buff2, "");
320 add_string_to_list(list, "Avg. packet size", string_buff, string_buff2);
323 g_snprintf(string_buff, SUM_STR_MAX, "%" PRIu64, summary.bytes);
324 if (summary.dfilter && summary.filtered_count > 0){
325 g_snprintf(string_buff2, SUM_STR_MAX, "%" PRIu64, summary.filtered_bytes);
327 strcpy(string_buff2, "");
329 add_string_to_list(list, "Bytes", string_buff, string_buff2);
331 /* Bytes per second */
333 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
334 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes)/seconds );
336 strcpy(string_buff, "");
338 if (summary.dfilter && disp_seconds > 0){
339 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
340 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f", ((gint64) summary.filtered_bytes)/disp_seconds );
342 strcpy(string_buff2, "");
344 add_string_to_list(list, "Avg. bytes/sec", string_buff, string_buff2);
346 /* MBit per second */
348 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
349 g_snprintf(string_buff, SUM_STR_MAX, "%.3f", ((gint64) summary.bytes) * 8.0 / (seconds * 1000.0 * 1000.0));
351 strcpy(string_buff, "");
353 if (summary.dfilter && disp_seconds > 0){
354 g_snprintf(string_buff2, SUM_STR_MAX, "%.3f",
355 /* MSVC cannot convert from unsigned __int64 to float, so first convert to signed __int64 */
356 ((gint64) summary.filtered_bytes) * 8.0 / (disp_seconds * 1000.0 * 1000.0));
358 strcpy(string_buff2, "");
360 add_string_to_list(list, "Avg. MBit/sec", string_buff, string_buff2);
364 if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
365 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
367 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
369 gtk_container_add(GTK_CONTAINER(main_vb), bbox);
371 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
372 window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
374 if(topic_available(HELP_STATS_SUMMARY_DIALOG)) {
375 help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
376 SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_STATS_SUMMARY_DIALOG);
379 gtk_widget_grab_focus(close_bt);
381 SIGNAL_CONNECT(sum_open_w, "delete_event", window_delete_event_cb, NULL);
383 gtk_widget_show_all(sum_open_w);
384 window_present(sum_open_w);