Add redirects to the ICMP filter.
[metze/wireshark/wip.git] / summary.c
1 /* summary.c
2  * Routines for capture file summary info
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <epan/packet.h>
30 #include "cfile.h"
31 #include "summary.h"
32 #ifdef HAVE_LIBPCAP
33 #include "capture_ui_utils.h"
34 #endif
35
36
37 static void
38 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
39 {
40   double cur_time;
41
42   cur_time = nstime_to_sec(&cur_frame->abs_ts);
43
44   if (cur_time < sum_tally->start_time) {
45     sum_tally->start_time = cur_time;
46   }
47   if (cur_time > sum_tally->stop_time){
48     sum_tally->stop_time = cur_time;
49   }
50   sum_tally->bytes += cur_frame->pkt_len;
51   if (cur_frame->flags.passed_dfilter){
52     if (sum_tally->filtered_count==0){
53             sum_tally->filtered_start= cur_time;
54             sum_tally->filtered_stop = cur_time;
55     } else {
56             if (cur_time < sum_tally->filtered_start) {
57                     sum_tally->start_time = cur_time;
58             }
59             if (cur_time > sum_tally->filtered_stop) {
60                     sum_tally->filtered_stop = cur_time;
61             }
62     }
63     sum_tally->filtered_count++;
64     sum_tally->filtered_bytes += cur_frame->pkt_len ;
65   }
66   if (cur_frame->flags.marked)
67     sum_tally->marked_count++;
68
69 }
70
71 void
72 summary_fill_in(capture_file *cf, summary_tally *st)
73 {
74
75   frame_data    *first_frame, *cur_frame;
76   int           i;
77   frame_data    *cur_glist;
78
79   st->start_time = 0;
80   st->stop_time = 0;
81   st->bytes = 0;
82   st->filtered_count = 0;
83   st->filtered_start = 0;
84   st->filtered_stop   = 0;
85   st->filtered_bytes = 0;
86   st->marked_count = 0;
87
88   /* initialize the tally */
89   if (cf->plist != NULL) {
90     first_frame = cf->plist;
91     st->start_time      = nstime_to_sec(&first_frame->abs_ts);
92     st->stop_time = nstime_to_sec(&first_frame->abs_ts);
93     cur_glist = cf->plist;
94
95     for (i = 0; i < cf->count; i++) {
96       cur_frame = cur_glist;
97       tally_frame_data(cur_frame, st);
98       cur_glist = cur_glist->next;
99     }
100   }
101
102   st->filename = cf->filename;
103   st->file_length = cf->f_datalen;
104   st->encap_type = cf->cd_t;
105   st->has_snap = cf->has_snap;
106   st->snap = cf->snap;
107   st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
108   st->packet_count = cf->count;
109   st->drops_known = cf->drops_known;
110   st->drops = cf->drops;
111   st->dfilter = cf->dfilter;
112
113   /* capture related */
114   st->cfilter = NULL;
115   st->iface = NULL;
116   st->iface_descr = NULL;
117 }
118
119
120 #ifdef HAVE_LIBPCAP
121 void
122 summary_fill_in_capture(capture_options *capture_opts, summary_tally *st)
123 {
124   st->cfilter = capture_opts->cfilter;
125   st->iface = capture_opts->iface;
126   if(st->iface) {
127     st->iface_descr = get_interface_descriptive_name(st->iface);
128   } else {
129     st->iface_descr = NULL;
130   }
131 }
132 #endif