2 * Routines for capture file summary info
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
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.
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.
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.
25 #include <wiretap/pcap-encap.h>
27 #include <epan/packet.h>
31 #include "ui/capture_ui_utils.h"
36 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
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;
45 if (cur_frame->flags.marked){
46 sum_tally->marked_count++;
47 sum_tally->marked_bytes += cur_frame->pkt_len;
49 if (cur_frame->flags.ignored){
50 sum_tally->ignored_count++;
53 if (cur_frame->flags.has_ts) {
54 /* This packet has a time stamp. */
55 cur_time = nstime_to_sec(&cur_frame->abs_ts);
57 sum_tally->packet_count_ts++;
58 if (cur_time < sum_tally->start_time) {
59 sum_tally->start_time = cur_time;
61 if (cur_time > sum_tally->stop_time){
62 sum_tally->stop_time = cur_time;
64 if (cur_frame->flags.passed_dfilter){
65 sum_tally->filtered_count_ts++;
67 * If we've seen one filtered packet, this is the first
70 if (sum_tally->filtered_count == 1){
71 sum_tally->filtered_start= cur_time;
72 sum_tally->filtered_stop = cur_time;
74 if (cur_time < sum_tally->filtered_start) {
75 sum_tally->filtered_start = cur_time;
77 if (cur_time > sum_tally->filtered_stop) {
78 sum_tally->filtered_stop = cur_time;
82 if (cur_frame->flags.marked){
83 sum_tally->marked_count_ts++;
85 * If we've seen one marked packet, this is the first
88 if (sum_tally->marked_count == 1){
89 sum_tally->marked_start= cur_time;
90 sum_tally->marked_stop = cur_time;
92 if (cur_time < sum_tally->marked_start) {
93 sum_tally->marked_start = cur_time;
95 if (cur_time > sum_tally->marked_stop) {
96 sum_tally->marked_stop = cur_time;
104 summary_fill_in(capture_file *cf, summary_tally *st)
106 frame_data *first_frame, *cur_frame;
108 wtapng_section_t* shb_inf;
111 wtapng_iface_descriptions_t* idb_info;
112 wtapng_if_descr_t wtapng_if_descr;
113 wtapng_if_stats_t *if_stats;
115 st->packet_count_ts = 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;
128 st->marked_bytes = 0;
129 st->ignored_count = 0;
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);
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);
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;
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;
158 /* Get info from SHB */
159 shb_inf = wtap_file_get_shb_info(cf->wth);
161 st->opt_comment = NULL;
162 st->shb_hardware = NULL;
164 st->shb_user_appl = NULL;
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;
173 st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options));
174 idb_info = wtap_file_get_idb_info(cf->wth);
175 for (i = 0; i < idb_info->interface_data->len; i++) {
176 wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i);
177 iface.cfilter = g_strdup(wtapng_if_descr.if_filter_str);
178 iface.name = g_strdup(wtapng_if_descr.if_name);
179 iface.descr = g_strdup(wtapng_if_descr.if_description);
180 iface.drops_known = FALSE;
182 iface.snap = wtapng_if_descr.snap_len;
183 iface.has_snap = (iface.snap != 65535);
184 iface.encap_type = wtapng_if_descr.wtap_encap;
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 iface.drops_known = TRUE;
189 iface.drops = if_stats->isb_ifdrop;
190 iface.isb_comment = if_stats->opt_comment;
192 g_array_append_val(st->ifaces, iface);
199 summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
205 if (st->ifaces->len == 0) {
207 * XXX - do this only if we have a live capture.
209 for (i = 0; i < capture_opts->all_ifaces->len; i++) {
210 device = g_array_index(capture_opts->all_ifaces, interface_t, i);
211 if (!device.selected) {
214 iface.cfilter = g_strdup(device.cfilter);
215 iface.name = g_strdup(device.name);
216 iface.descr = g_strdup(device.display_name);
217 iface.drops_known = cf->drops_known;
218 iface.drops = cf->drops;
219 iface.has_snap = device.has_snaplen;
220 iface.snap = device.snaplen;
221 iface.encap_type = wtap_pcap_encap_to_wtap_encap(device.active_dlt);
222 g_array_append_val(st->ifaces, iface);
229 * Editor modelines - http://www.wireshark.org/tools/modelines.html
234 * indent-tabs-mode: nil
237 * ex: set shiftwidth=2 tabstop=8 expandtab:
238 * :indentSize=2:tabSize=8:noTabs=true: