More constification of arrays.
[obnox/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 "globals.h"
31 #include "summary.h"
32
33
34 static double
35 secs_usecs( guint32 s, guint32 us)
36 {
37   return (us / 1000000.0) + (double)s;
38 }
39
40 static void
41 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
42 {
43   double cur_time;
44
45   cur_time = secs_usecs(cur_frame->abs_secs, cur_frame->abs_usecs);
46
47   if (cur_time < sum_tally->start_time) {
48     sum_tally->start_time = cur_time;
49   }
50   if (cur_time > sum_tally->stop_time){
51     sum_tally->stop_time = cur_time;
52   }
53   sum_tally->bytes += cur_frame->pkt_len;
54   if (cur_frame->flags.passed_dfilter){
55     if (sum_tally->filtered_count==0){
56             sum_tally->filtered_start= cur_time;
57             sum_tally->filtered_stop = cur_time;
58     } else {
59             if (cur_time < sum_tally->filtered_start) {
60                     sum_tally->start_time = cur_time;
61             }
62             if (cur_time > sum_tally->filtered_stop) {
63                     sum_tally->filtered_stop = cur_time;
64             }
65     }
66     sum_tally->filtered_count++;
67     sum_tally->filtered_bytes += cur_frame->pkt_len ;
68   }
69   if (cur_frame->flags.marked)
70     sum_tally->marked_count++;
71
72 }
73
74 void
75 summary_fill_in(summary_tally *st)
76 {
77
78   frame_data    *first_frame, *cur_frame;
79   int           i;
80   frame_data    *cur_glist;
81
82   st->start_time = 0;
83   st->stop_time = 0;
84   st->bytes = 0;
85   st->filtered_count = 0;
86   st->filtered_start = 0;
87   st->filtered_stop   = 0;
88   st->filtered_bytes = 0;
89   st->marked_count = 0;
90
91   /* initialize the tally */
92   if (cfile.plist != NULL) {
93     first_frame = cfile.plist;
94     st->start_time      = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs);
95     st->stop_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs);
96     cur_glist = cfile.plist;
97
98     for (i = 0; i < cfile.count; i++) {
99       cur_frame = cur_glist;
100       tally_frame_data(cur_frame, st);
101       cur_glist = cur_glist->next;
102     }
103   }
104
105   st->filename = cfile.filename;
106   st->file_length = cfile.f_len;
107   st->encap_type = cfile.cd_t;
108   st->has_snap = cfile.has_snap;
109   st->snap = cfile.snap;
110   st->elapsed_time = secs_usecs(cfile.esec, cfile.eusec);
111   st->packet_count = cfile.count;
112   st->drops_known = cfile.drops_known;
113   st->drops = cfile.drops;
114   st->iface = cfile.iface;
115   st->dfilter = cfile.dfilter;
116
117 #ifdef HAVE_LIBPCAP
118   st->cfilter = cfile.cfilter;
119 #else
120   st->cfilter = NULL;
121 #endif
122 }