2 * Routines for capture file summary window
4 * $Id: summary.c,v 1.8 1999/08/10 04:13:36 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.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
45 #ifdef NEED_SNPRINTF_H
51 # include "snprintf.h"
54 #ifdef HAVE_SYS_SOCKIO_H
55 # include <sys/sockio.h>
68 extern capture_file cf;
70 /* File selection data keys */
71 #define E_SUM_PREP_FS_KEY "sum_prep_fs"
72 #define E_SUM_PREP_TE_KEY "sum_prep_te"
74 /* Summary callback data keys */
75 #define E_SUM_IFACE_KEY "sum_iface"
76 #define E_SUM_FILT_KEY "sum_filter"
77 #define E_SUM_COUNT_KEY "sum_count"
78 #define E_SUM_OPEN_KEY "sum_open"
79 #define E_SUM_SNAP_KEY "sum_snap"
81 #define SUM_STR_MAX 1024
83 /* Summary filter key */
84 #define E_SUM_FILT_TE_KEY "sum_filt_te"
87 secs_usecs( guint32 s, guint32 us) {
88 return (us / 1000000.0) + (double)s;
92 tally_frame_data(gpointer cf, gpointer st) {
94 summary_tally * sum_tally = (summary_tally *)st;
95 frame_data *cur_frame = (frame_data *)cf;
97 cur_time = secs_usecs(cur_frame->abs_secs, cur_frame->abs_usecs);
98 if (cur_time < sum_tally->start_time) {
99 sum_tally->start_time = cur_time;
101 if (cur_time > sum_tally->stop_time){
102 sum_tally->stop_time = cur_time;
104 sum_tally->bytes += cur_frame->pkt_len;
105 if (cur_frame->passed_dfilter)
106 sum_tally->filtered_count++;
110 add_string_to_box(gchar *str, GtkWidget *box) {
112 lb = gtk_label_new(str);
113 gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
114 gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
119 summary_prep_cb(GtkWidget *w, gpointer d) {
120 frame_data *first_frame, *cur_frame;
122 GtkWidget *sum_open_w,
123 *main_vb, *file_fr, *data_fr, *capture_fr, *file_box,
127 gchar string_buff[SUM_STR_MAX];
129 guint32 traffic_bytes, i;
131 frame_data *cur_glist;
133 /* initialize the tally */
134 first_frame = cf.plist;
135 st = (summary_tally *)g_malloc(sizeof(summary_tally));
136 st->start_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs)
138 st->stop_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs)
141 st->filtered_count = 0;
142 cur_glist = cf.plist;
144 for (i = 0; i < cf.count; i++){
145 cur_frame = cur_glist;
146 tally_frame_data(cur_frame, st);
147 cur_glist = cur_glist->next;
150 /* traffic_bytes will be computed here */
151 traffic_bytes = st->bytes;
152 seconds = st->stop_time - st->start_time;
153 sum_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
154 gtk_window_set_title(GTK_WINDOW(sum_open_w), "Ethereal: Summary");
156 /* Container for each row of widgets */
157 main_vb = gtk_vbox_new(FALSE, 3);
158 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
159 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
160 gtk_widget_show(main_vb);
163 file_fr = gtk_frame_new("File");
164 gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
165 gtk_widget_show(file_fr);
167 file_box = gtk_vbox_new(FALSE, 3);
168 gtk_container_add(GTK_CONTAINER(file_fr), file_box);
169 gtk_widget_show(file_box);
172 snprintf(string_buff, SUM_STR_MAX, "Name: %s", cf.filename);
173 add_string_to_box(string_buff, file_box);
176 snprintf(string_buff, SUM_STR_MAX, "Length: %lu", cf.f_len);
177 add_string_to_box(string_buff, file_box);
180 snprintf(string_buff, SUM_STR_MAX, "Format: %s", cf.cd_t_desc);
181 add_string_to_box(string_buff, file_box);
183 /* snapshot length */
184 snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", cf.snap);
185 add_string_to_box(string_buff, file_box);
188 data_fr = gtk_frame_new("Data");
189 gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
190 gtk_widget_show(data_fr);
192 data_box = gtk_vbox_new(FALSE, 3);
193 gtk_container_add(GTK_CONTAINER(data_fr), data_box);
194 gtk_widget_show(data_box);
197 snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds",
198 secs_usecs(cf.esec,cf.eusec));
199 add_string_to_box(string_buff, data_box);
201 snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
202 add_string_to_box(string_buff, data_box);
205 snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", cf.count);
206 add_string_to_box(string_buff, data_box);
208 /* Filtered Packet count */
209 snprintf(string_buff, SUM_STR_MAX, "Filtered packet count: %i", st->filtered_count);
210 add_string_to_box(string_buff, data_box);
212 /* Packets per second */
214 snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f",
216 add_string_to_box(string_buff, data_box);
220 snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %i", cf.drops);
221 add_string_to_box(string_buff, data_box);
224 snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d",
226 add_string_to_box(string_buff, data_box);
228 /* Bytes per second */
230 snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f",
231 traffic_bytes/seconds);
232 add_string_to_box(string_buff, data_box);
236 capture_fr = gtk_frame_new("Capture");
237 gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
238 gtk_widget_show(capture_fr);
240 capture_box = gtk_vbox_new(FALSE, 3);
241 gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
242 gtk_widget_show(capture_box);
247 snprintf(string_buff, SUM_STR_MAX, "Interface: %s", cf.iface);
249 sprintf(string_buff, "Interface: unknown");
251 add_string_to_box(string_buff, capture_box);
253 /* Display filter. The situation where cf.dfilter="" and cf.dfcode=NULL can exist,
254 so I'll check for both */
255 if (cf.dfilter && cf.dfcode) {
256 snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", cf.dfilter);
258 sprintf(string_buff, "Display filter: none");
260 add_string_to_box(string_buff, capture_box);
265 snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", cf.cfilter);
267 sprintf(string_buff, "Capture filter: none");
269 add_string_to_box(string_buff, capture_box);
272 gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
273 gtk_widget_show(sum_open_w);
276 /* this is never called
278 summary_prep_close_cb(GtkWidget *w, gpointer win) {
280 gtk_grab_remove(GTK_WIDGET(win));
281 gtk_widget_destroy(GTK_WIDGET(win));