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>
26 #include <wiretap/wtap_opttypes.h>
27 #include <wiretap/pcapng.h>
29 #include <epan/packet.h>
33 #include "ui/capture_ui_utils.h"
38 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
42 sum_tally->bytes += cur_frame->pkt_len;
43 if (cur_frame->flags.passed_dfilter){
44 sum_tally->filtered_count++;
45 sum_tally->filtered_bytes += cur_frame->pkt_len;
47 if (cur_frame->flags.marked){
48 sum_tally->marked_count++;
49 sum_tally->marked_bytes += cur_frame->pkt_len;
51 if (cur_frame->flags.ignored){
52 sum_tally->ignored_count++;
55 if (cur_frame->flags.has_ts) {
56 /* This packet has a time stamp. */
57 cur_time = nstime_to_sec(&cur_frame->abs_ts);
59 sum_tally->packet_count_ts++;
60 if (cur_time < sum_tally->start_time) {
61 sum_tally->start_time = cur_time;
63 if (cur_time > sum_tally->stop_time){
64 sum_tally->stop_time = cur_time;
66 if (cur_frame->flags.passed_dfilter){
67 sum_tally->filtered_count_ts++;
69 * If we've seen one filtered packet, this is the first
72 if (sum_tally->filtered_count == 1){
73 sum_tally->filtered_start= cur_time;
74 sum_tally->filtered_stop = cur_time;
76 if (cur_time < sum_tally->filtered_start) {
77 sum_tally->filtered_start = cur_time;
79 if (cur_time > sum_tally->filtered_stop) {
80 sum_tally->filtered_stop = cur_time;
84 if (cur_frame->flags.marked){
85 sum_tally->marked_count_ts++;
87 * If we've seen one marked packet, this is the first
90 if (sum_tally->marked_count == 1){
91 sum_tally->marked_start= cur_time;
92 sum_tally->marked_stop = cur_time;
94 if (cur_time < sum_tally->marked_start) {
95 sum_tally->marked_start = cur_time;
97 if (cur_time > sum_tally->marked_stop) {
98 sum_tally->marked_stop = cur_time;
106 summary_fill_in(capture_file *cf, summary_tally *st)
108 frame_data *first_frame, *cur_frame;
112 wtapng_iface_descriptions_t* idb_info;
113 wtap_block_t wtapng_if_descr;
114 wtapng_if_descr_mandatory_t *wtapng_if_descr_mand;
115 wtap_block_t if_stats;
118 wtapng_if_descr_filter_t* if_filter;
120 st->packet_count_ts = 0;
124 st->filtered_count = 0;
125 st->filtered_count_ts = 0;
126 st->filtered_start = 0;
127 st->filtered_stop = 0;
128 st->filtered_bytes = 0;
129 st->marked_count = 0;
130 st->marked_count_ts = 0;
131 st->marked_start = 0;
133 st->marked_bytes = 0;
134 st->ignored_count = 0;
136 /* initialize the tally */
137 if (cf->count != 0) {
138 first_frame = frame_data_sequence_find(cf->frames, 1);
139 st->start_time = nstime_to_sec(&first_frame->abs_ts);
140 st->stop_time = nstime_to_sec(&first_frame->abs_ts);
142 for (framenum = 1; framenum <= cf->count; framenum++) {
143 cur_frame = frame_data_sequence_find(cf->frames, framenum);
144 tally_frame_data(cur_frame, st);
148 st->filename = cf->filename;
149 st->file_length = cf->f_datalen;
150 st->file_type = cf->cd_t;
151 st->iscompressed = cf->iscompressed;
152 st->is_tempfile = cf->is_tempfile;
153 st->file_encap_type = cf->lnk_t;
154 st->packet_encap_types = cf->linktypes;
155 st->has_snap = cf->has_snap;
157 st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
158 st->packet_count = cf->count;
159 st->drops_known = cf->drops_known;
160 st->drops = cf->drops;
161 st->dfilter = cf->dfilter;
163 st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options));
164 idb_info = wtap_file_get_idb_info(cf->wth);
165 for (i = 0; i < idb_info->interface_data->len; i++) {
166 wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, i);
167 wtapng_if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wtapng_if_descr);
168 if (wtap_block_get_custom_option_value(wtapng_if_descr, OPT_IDB_FILTER, (void**)&if_filter) == WTAP_OPTTYPE_SUCCESS) {
169 iface.cfilter = g_strdup(if_filter->if_filter_str);
171 iface.cfilter = NULL;
173 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_NAME, &if_string) == WTAP_OPTTYPE_SUCCESS) {
174 iface.name = g_strdup(if_string);
178 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &if_string) == WTAP_OPTTYPE_SUCCESS) {
179 iface.descr = g_strdup(if_string);
183 iface.drops_known = FALSE;
185 iface.snap = wtapng_if_descr_mand->snap_len;
186 iface.has_snap = (iface.snap != 65535);
187 iface.encap_type = wtapng_if_descr_mand->wtap_encap;
188 iface.isb_comment = NULL;
189 if(wtapng_if_descr_mand->num_stat_entries == 1){
190 /* dumpcap only writes one ISB, only handle that for now */
191 if_stats = g_array_index(wtapng_if_descr_mand->interface_statistics, wtap_block_t, 0);
192 if (wtap_block_get_uint64_option_value(if_stats, OPT_ISB_IFDROP, &isb_ifdrop) == WTAP_OPTTYPE_SUCCESS) {
193 iface.drops_known = TRUE;
194 iface.drops = isb_ifdrop;
196 /* XXX: this doesn't get used, and might need to be g_strdup'ed when it does */
197 /* XXX - support multiple comments */
198 if (wtap_block_get_nth_string_option_value(if_stats, OPT_COMMENT, 0, &iface.isb_comment) != WTAP_OPTTYPE_SUCCESS) {
199 iface.isb_comment = NULL;
202 g_array_append_val(st->ifaces, iface);
209 summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
215 if (st->ifaces->len == 0) {
217 * XXX - do this only if we have a live capture.
219 for (i = 0; i < capture_opts->all_ifaces->len; i++) {
220 device = g_array_index(capture_opts->all_ifaces, interface_t, i);
221 if (!device.selected) {
224 iface.cfilter = g_strdup(device.cfilter);
225 iface.name = g_strdup(device.name);
226 iface.descr = g_strdup(device.display_name);
227 iface.drops_known = cf->drops_known;
228 iface.drops = cf->drops;
229 iface.has_snap = device.has_snaplen;
230 iface.snap = device.snaplen;
231 iface.encap_type = wtap_pcap_encap_to_wtap_encap(device.active_dlt);
232 g_array_append_val(st->ifaces, iface);
239 * Editor modelines - http://www.wireshark.org/tools/modelines.html
244 * indent-tabs-mode: nil
247 * ex: set shiftwidth=2 tabstop=8 expandtab:
248 * :indentSize=2:tabSize=8:noTabs=true: