Trivial warning fixes
[obnox/wireshark/wip.git] / summary.c
1 /* summary.c
2  * Routines for capture file summary info
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
31 #endif
32
33 #include <epan/packet.h>
34 #include "cfile.h"
35 #include "summary.h"
36 #ifdef HAVE_LIBPCAP
37 #include "capture_ui_utils.h"
38 #endif
39
40
41 static void
42 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
43 {
44   double cur_time;
45
46   cur_time = nstime_to_sec(&cur_frame->abs_ts);
47
48   if (cur_time < sum_tally->start_time) {
49     sum_tally->start_time = cur_time;
50   }
51   if (cur_time > sum_tally->stop_time){
52     sum_tally->stop_time = cur_time;
53   }
54   sum_tally->bytes += cur_frame->pkt_len;
55   if (cur_frame->flags.passed_dfilter){
56     if (sum_tally->filtered_count==0){
57             sum_tally->filtered_start= cur_time;
58             sum_tally->filtered_stop = cur_time;
59     } else {
60             if (cur_time < sum_tally->filtered_start) {
61                     sum_tally->filtered_start = cur_time;
62             }
63             if (cur_time > sum_tally->filtered_stop) {
64                     sum_tally->filtered_stop = cur_time;
65             }
66     }
67     sum_tally->filtered_count++;
68     sum_tally->filtered_bytes += cur_frame->pkt_len ;
69   }
70   if (cur_frame->flags.marked){
71     if (sum_tally->marked_count==0){
72             sum_tally->marked_start= cur_time;
73             sum_tally->marked_stop = cur_time;
74     } else {
75             if (cur_time < sum_tally->marked_start) {
76                     sum_tally->marked_start = cur_time;
77             }
78             if (cur_time > sum_tally->marked_stop) {
79                     sum_tally->marked_stop = cur_time;
80             }
81     }
82     sum_tally->marked_count++;
83     sum_tally->marked_bytes += cur_frame->pkt_len ;
84   }
85 }
86
87 void
88 summary_fill_in(capture_file *cf, summary_tally *st)
89 {
90
91   frame_data    *first_frame, *cur_frame;
92   int           i;
93   frame_data    *cur_glist;
94
95   st->start_time = 0;
96   st->stop_time = 0;
97   st->bytes = 0;
98   st->filtered_count = 0;
99   st->filtered_start = 0;
100   st->filtered_stop = 0;
101   st->filtered_bytes = 0;
102   st->marked_count = 0;
103   st->marked_start = 0;
104   st->marked_stop = 0;
105   st->marked_bytes = 0;
106
107   /* initialize the tally */
108   if (cf->plist != NULL) {
109     first_frame = cf->plist;
110     st->start_time      = nstime_to_sec(&first_frame->abs_ts);
111     st->stop_time = nstime_to_sec(&first_frame->abs_ts);
112     cur_glist = cf->plist;
113
114     for (i = 0; i < cf->count; i++) {
115       cur_frame = cur_glist;
116       tally_frame_data(cur_frame, st);
117       cur_glist = cur_glist->next;
118     }
119   }
120
121   st->filename = cf->filename;
122   st->file_length = cf->f_datalen;
123   st->file_type = cf->cd_t;
124   st->encap_type = cf->lnk_t;
125   st->has_snap = cf->has_snap;
126   st->snap = cf->snap;
127   st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
128   st->packet_count = cf->count;
129   st->drops_known = cf->drops_known;
130   st->drops = cf->drops;
131   st->dfilter = cf->dfilter;
132
133   /* capture related */
134   st->cfilter = NULL;
135   st->iface = NULL;
136   st->iface_descr = NULL;
137 }
138
139
140 #ifdef HAVE_LIBPCAP
141 void
142 summary_fill_in_capture(capture_options *capture_opts, summary_tally *st)
143 {
144   st->cfilter = capture_opts->cfilter;
145   st->iface = capture_opts->iface;
146   st->iface_descr = get_iface_description(capture_opts);
147 }
148 #endif