2 * Routines for capture file summary window
4 * $Id: summary.c,v 1.3 1999/07/07 22:52:00 gram 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>
43 #ifdef NEED_SNPRINTF_H
49 # include "snprintf.h"
52 #ifdef HAVE_SYS_SOCKIO_H
53 # include <sys/sockio.h>
66 extern capture_file cf;
68 /* File selection data keys */
69 #define E_SUM_PREP_FS_KEY "sum_prep_fs"
70 #define E_SUM_PREP_TE_KEY "sum_prep_te"
72 /* Summary callback data keys */
73 #define E_SUM_IFACE_KEY "sum_iface"
74 #define E_SUM_FILT_KEY "sum_filter"
75 #define E_SUM_COUNT_KEY "sum_count"
76 #define E_SUM_OPEN_KEY "sum_open"
77 #define E_SUM_SNAP_KEY "sum_snap"
79 #define SUM_STR_MAX 1024
81 /* Summary filter key */
82 #define E_SUM_FILT_TE_KEY "sum_filt_te"
84 char * string_for_format(guint16 cd_t){
90 case WTAP_FILE_LANALYZER:
92 case WTAP_FILE_NGSNIFFER:
96 case WTAP_FILE_IPTRACE:
98 case WTAP_FILE_NETMON:
99 return "Network Monitor";
100 case WTAP_FILE_NETXRAY:
101 return "NetXray/Sniffer Pro";
108 secs_usecs( guint32 s, guint32 us) {
109 return (us / 1000000.0) + (double)s;
113 tally_frame_data(gpointer cf, gpointer st) {
115 summary_tally * sum_tally = (summary_tally *)st;
116 frame_data *cur_frame = (frame_data *)cf;
118 cur_time = secs_usecs(cur_frame->abs_secs, cur_frame->abs_usecs);
119 if (cur_time < sum_tally->start_time) {
120 sum_tally->start_time = cur_time;
122 if (cur_time > sum_tally->stop_time){
123 sum_tally->stop_time = cur_time;
125 sum_tally->bytes += cur_frame->pkt_len;
126 if (cur_frame->passed_dfilter)
127 sum_tally->filtered_count++;
131 add_string_to_box(gchar *str, GtkWidget *box) {
133 lb = gtk_label_new(str);
134 gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
135 gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
140 summary_prep_cb(GtkWidget *w, gpointer d) {
141 frame_data *first_frame, *cur_frame;
143 GtkWidget *sum_open_w,
144 *main_vb, *file_fr, *data_fr, *capture_fr, *file_box,
148 gchar string_buff[SUM_STR_MAX];
150 guint32 traffic_bytes, i;
154 /* initialize the tally */
155 first_frame = (frame_data *)(cf.plist->data);
156 st = (summary_tally *)g_malloc(sizeof(summary_tally));
157 st->start_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs)
159 st->stop_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs)
162 st->filtered_count = 0;
163 cur_glist = cf.plist;
165 for (i = 0; i < cf.count; i++){
166 cur_frame = (frame_data *)cur_glist->data;
167 tally_frame_data(cur_frame, st);
168 cur_glist = cur_glist->next;
171 /* g_list_foreach(cf.plist_first, (GFunc)tally_frame_data, st); */
173 /* traffic_bytes will be computed here */
174 traffic_bytes = st->bytes;
175 seconds = st->stop_time - st->start_time;
176 sum_open_w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
177 gtk_window_set_title(GTK_WINDOW(sum_open_w), "Ethereal: Summary");
179 /* Container for each row of widgets */
180 main_vb = gtk_vbox_new(FALSE, 3);
181 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
182 gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
183 gtk_widget_show(main_vb);
186 file_fr = gtk_frame_new("File");
187 gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
188 gtk_widget_show(file_fr);
190 file_box = gtk_vbox_new(FALSE, 3);
191 gtk_container_add(GTK_CONTAINER(file_fr), file_box);
192 gtk_widget_show(file_box);
195 snprintf(string_buff, SUM_STR_MAX, "Name: %s", cf.filename);
196 add_string_to_box(string_buff, file_box);
199 snprintf(string_buff, SUM_STR_MAX, "Length: %lu", cf.f_len);
200 add_string_to_box(string_buff, file_box);
203 snprintf(string_buff, SUM_STR_MAX, "Format: %s",
204 string_for_format(cf.cd_t));
205 add_string_to_box(string_buff, file_box);
208 data_fr = gtk_frame_new("Data");
209 gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
210 gtk_widget_show(data_fr);
212 data_box = gtk_vbox_new(FALSE, 3);
213 gtk_container_add(GTK_CONTAINER(data_fr), data_box);
214 gtk_widget_show(data_box);
217 snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds",
218 secs_usecs(cf.esec,cf.eusec));
219 add_string_to_box(string_buff, data_box);
221 snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f
223 add_string_to_box(string_buff, data_box);
226 snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", cf.count);
227 add_string_to_box(string_buff, data_box);
229 /* Filtered Packet count */
230 snprintf(string_buff, SUM_STR_MAX, "Filtered packet count: %i", st->filtered_count);
231 add_string_to_box(string_buff, data_box);
233 /* Packets per second */
235 snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f",
237 add_string_to_box(string_buff, data_box);
241 snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %i", cf.drops);
242 add_string_to_box(string_buff, data_box);
245 snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d",
247 add_string_to_box(string_buff, data_box);
249 /* Bytes per second */
251 snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f",
252 traffic_bytes/seconds);
253 add_string_to_box(string_buff, data_box);
257 capture_fr = gtk_frame_new("Capture");
258 gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
259 gtk_widget_show(capture_fr);
261 capture_box = gtk_vbox_new(FALSE, 3);
262 gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
263 gtk_widget_show(capture_box);
268 snprintf(string_buff, SUM_STR_MAX, "Interface: %s", cf.iface);
270 sprintf(string_buff, "Interface: unknown");
272 add_string_to_box(string_buff, capture_box);
274 /* Display filter. The situation where cf.dfilter="" and cf.dfcode=NULL can exist,
275 so I'll check for both */
276 if (cf.dfilter && cf.dfcode) {
277 snprintf(string_buff, SUM_STR_MAX, "Display filter: %s", cf.dfilter);
279 sprintf(string_buff, "Display filter: none");
281 add_string_to_box(string_buff, capture_box);
285 snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", cf.cfilter);
287 sprintf(string_buff, "Capture filter: none");
289 add_string_to_box(string_buff, capture_box);
290 gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
291 gtk_widget_show(sum_open_w);
296 summary_prep_close_cb(GtkWidget *w, gpointer win) {
298 #ifdef GTK_HAVE_FEATURES_1_1_0
301 gtk_grab_remove(GTK_WIDGET(win));
302 gtk_widget_destroy(GTK_WIDGET(win));