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