ssl: fix RSA key matching with Client certs
[metze/wireshark/wip.git] / summary.c
1 /* summary.c
2  * Routines for capture file summary info
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include <config.h>
24
25 #include <wiretap/pcap-encap.h>
26
27 #include <epan/packet.h>
28 #include "cfile.h"
29 #include "summary.h"
30 #if 0
31 #include "ui/capture_ui_utils.h"
32 #endif
33
34
35 static void
36 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
37 {
38   double cur_time;
39
40   sum_tally->bytes += cur_frame->pkt_len;
41   if (cur_frame->flags.passed_dfilter){
42     sum_tally->filtered_count++;
43     sum_tally->filtered_bytes += cur_frame->pkt_len;
44   }
45   if (cur_frame->flags.marked){
46     sum_tally->marked_count++;
47     sum_tally->marked_bytes += cur_frame->pkt_len;
48   }
49   if (cur_frame->flags.ignored){
50     sum_tally->ignored_count++;
51   }
52
53   if (cur_frame->flags.has_ts) {
54     /* This packet has a time stamp. */
55     cur_time = nstime_to_sec(&cur_frame->abs_ts);
56
57     sum_tally->packet_count_ts++;
58     if (cur_time < sum_tally->start_time) {
59       sum_tally->start_time = cur_time;
60     }
61     if (cur_time > sum_tally->stop_time){
62       sum_tally->stop_time = cur_time;
63     }
64     if (cur_frame->flags.passed_dfilter){
65       sum_tally->filtered_count_ts++;
66       /*
67        * If we've seen one filtered packet, this is the first
68        * one.
69        */
70       if (sum_tally->filtered_count == 1){
71         sum_tally->filtered_start= cur_time;
72         sum_tally->filtered_stop = cur_time;
73       } else {
74         if (cur_time < sum_tally->filtered_start) {
75           sum_tally->filtered_start = cur_time;
76         }
77         if (cur_time > sum_tally->filtered_stop) {
78           sum_tally->filtered_stop = cur_time;
79         }
80       }
81     }
82     if (cur_frame->flags.marked){
83       sum_tally->marked_count_ts++;
84       /*
85        * If we've seen one marked packet, this is the first
86        * one.
87        */
88       if (sum_tally->marked_count == 1){
89         sum_tally->marked_start= cur_time;
90         sum_tally->marked_stop = cur_time;
91       } else {
92         if (cur_time < sum_tally->marked_start) {
93           sum_tally->marked_start = cur_time;
94         }
95         if (cur_time > sum_tally->marked_stop) {
96           sum_tally->marked_stop = cur_time;
97         }
98       }
99     }
100   }
101 }
102
103 void
104 summary_fill_in(capture_file *cf, summary_tally *st)
105 {
106   frame_data    *first_frame, *cur_frame;
107   guint32        framenum;
108   const wtapng_section_t* shb_inf;
109   iface_options iface;
110   guint i;
111   wtapng_iface_descriptions_t* idb_info;
112   wtapng_if_descr_t wtapng_if_descr;
113   wtapng_if_stats_t *if_stats;
114
115   st->packet_count_ts = 0;
116   st->start_time = 0;
117   st->stop_time = 0;
118   st->bytes = 0;
119   st->filtered_count = 0;
120   st->filtered_count_ts = 0;
121   st->filtered_start = 0;
122   st->filtered_stop = 0;
123   st->filtered_bytes = 0;
124   st->marked_count = 0;
125   st->marked_count_ts = 0;
126   st->marked_start = 0;
127   st->marked_stop = 0;
128   st->marked_bytes = 0;
129   st->ignored_count = 0;
130
131   /* initialize the tally */
132   if (cf->count != 0) {
133     first_frame = frame_data_sequence_find(cf->frames, 1);
134     st->start_time = nstime_to_sec(&first_frame->abs_ts);
135     st->stop_time = nstime_to_sec(&first_frame->abs_ts);
136
137     for (framenum = 1; framenum <= cf->count; framenum++) {
138       cur_frame = frame_data_sequence_find(cf->frames, framenum);
139       tally_frame_data(cur_frame, st);
140     }
141   }
142
143   st->filename = cf->filename;
144   st->file_length = cf->f_datalen;
145   st->file_type = cf->cd_t;
146   st->iscompressed = cf->iscompressed;
147   st->is_tempfile = cf->is_tempfile;
148   st->file_encap_type = cf->lnk_t;
149   st->packet_encap_types = cf->linktypes;
150   st->has_snap = cf->has_snap;
151   st->snap = cf->snap;
152   st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
153   st->packet_count = cf->count;
154   st->drops_known = cf->drops_known;
155   st->drops = cf->drops;
156   st->dfilter = cf->dfilter;
157
158   /* Get info from SHB */
159   shb_inf = wtap_file_get_shb(cf->wth);
160   if(shb_inf == NULL){
161     st->opt_comment    = NULL;
162     st->shb_hardware   = NULL;
163     st->shb_os         = NULL;
164     st->shb_user_appl  = NULL;
165   }else{
166     st->opt_comment    = shb_inf->opt_comment;
167     st->shb_hardware   = shb_inf->shb_hardware;
168     st->shb_os         = shb_inf->shb_os;
169     st->shb_user_appl  = shb_inf->shb_user_appl;
170   }
171
172   st->ifaces  = g_array_new(FALSE, FALSE, sizeof(iface_options));
173   idb_info = wtap_file_get_idb_info(cf->wth);
174   for (i = 0; i < idb_info->interface_data->len; i++) {
175     wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i);
176     iface.cfilter = g_strdup(wtapng_if_descr.if_filter_str);
177     iface.name = g_strdup(wtapng_if_descr.if_name);
178     iface.descr = g_strdup(wtapng_if_descr.if_description);
179     iface.drops_known = FALSE;
180     iface.drops = 0;
181     iface.snap = wtapng_if_descr.snap_len;
182     iface.has_snap = (iface.snap != 65535);
183     iface.encap_type = wtapng_if_descr.wtap_encap;
184     iface.isb_comment = NULL;
185     if(wtapng_if_descr.num_stat_entries == 1){
186       /* dumpcap only writes one ISB, only handle that for now */
187       if_stats = &g_array_index(wtapng_if_descr.interface_statistics, wtapng_if_stats_t, 0);
188       if (if_stats->isb_ifdrop != G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF)) {
189         iface.drops_known = TRUE;
190         iface.drops = if_stats->isb_ifdrop;
191       }
192       /* XXX: this doesn't get used, and might need to be g_strdup'ed when it does */
193       iface.isb_comment = if_stats->opt_comment;
194     }
195     g_array_append_val(st->ifaces, iface);
196   }
197   g_free(idb_info);
198 }
199
200 #ifdef HAVE_LIBPCAP
201 void
202 summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
203 {
204   iface_options iface;
205   interface_t device;
206   guint i;
207
208   if (st->ifaces->len == 0) {
209     /*
210      * XXX - do this only if we have a live capture.
211      */
212     for (i = 0; i < capture_opts->all_ifaces->len; i++) {
213       device = g_array_index(capture_opts->all_ifaces, interface_t, i);
214       if (!device.selected) {
215         continue;
216       }
217       iface.cfilter = g_strdup(device.cfilter);
218       iface.name = g_strdup(device.name);
219       iface.descr = g_strdup(device.display_name);
220       iface.drops_known = cf->drops_known;
221       iface.drops = cf->drops;
222       iface.has_snap = device.has_snaplen;
223       iface.snap = device.snaplen;
224       iface.encap_type = wtap_pcap_encap_to_wtap_encap(device.active_dlt);
225       g_array_append_val(st->ifaces, iface);
226     }
227   }
228 }
229 #endif
230
231 /*
232  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
233  *
234  * Local Variables:
235  * c-basic-offset: 2
236  * tab-width: 8
237  * indent-tabs-mode: nil
238  * End:
239  *
240  * ex: set shiftwidth=2 tabstop=8 expandtab:
241  * :indentSize=2:tabSize=8:noTabs=true:
242  */