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>
34 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
38 sum_tally->bytes += cur_frame->pkt_len;
39 if (cur_frame->flags.passed_dfilter){
40 sum_tally->filtered_count++;
41 sum_tally->filtered_bytes += cur_frame->pkt_len;
43 if (cur_frame->flags.marked){
44 sum_tally->marked_count++;
45 sum_tally->marked_bytes += cur_frame->pkt_len;
47 if (cur_frame->flags.ignored){
48 sum_tally->ignored_count++;
51 if (cur_frame->flags.has_ts) {
52 /* This packet has a time stamp. */
53 cur_time = nstime_to_sec(&cur_frame->abs_ts);
55 sum_tally->packet_count_ts++;
56 if (cur_time < sum_tally->start_time) {
57 sum_tally->start_time = cur_time;
59 if (cur_time > sum_tally->stop_time){
60 sum_tally->stop_time = cur_time;
62 if (cur_frame->flags.passed_dfilter){
63 sum_tally->filtered_count_ts++;
65 * If we've seen one filtered packet, this is the first
68 if (sum_tally->filtered_count == 1){
69 sum_tally->filtered_start= cur_time;
70 sum_tally->filtered_stop = cur_time;
72 if (cur_time < sum_tally->filtered_start) {
73 sum_tally->filtered_start = cur_time;
75 if (cur_time > sum_tally->filtered_stop) {
76 sum_tally->filtered_stop = cur_time;
80 if (cur_frame->flags.marked){
81 sum_tally->marked_count_ts++;
83 * If we've seen one marked packet, this is the first
86 if (sum_tally->marked_count == 1){
87 sum_tally->marked_start= cur_time;
88 sum_tally->marked_stop = cur_time;
90 if (cur_time < sum_tally->marked_start) {
91 sum_tally->marked_start = cur_time;
93 if (cur_time > sum_tally->marked_stop) {
94 sum_tally->marked_stop = cur_time;
102 summary_fill_in(capture_file *cf, summary_tally *st)
104 frame_data *first_frame, *cur_frame;
108 wtapng_iface_descriptions_t* idb_info;
109 wtap_block_t wtapng_if_descr;
110 wtapng_if_descr_mandatory_t *wtapng_if_descr_mand;
111 wtap_block_t if_stats;
114 wtapng_if_descr_filter_t* if_filter;
116 st->packet_count_ts = 0;
120 st->filtered_count = 0;
121 st->filtered_count_ts = 0;
122 st->filtered_start = 0;
123 st->filtered_stop = 0;
124 st->filtered_bytes = 0;
125 st->marked_count = 0;
126 st->marked_count_ts = 0;
127 st->marked_start = 0;
129 st->marked_bytes = 0;
130 st->ignored_count = 0;
132 /* initialize the tally */
133 if (cf->count != 0) {
134 first_frame = frame_data_sequence_find(cf->frames, 1);
135 st->start_time = nstime_to_sec(&first_frame->abs_ts);
136 st->stop_time = nstime_to_sec(&first_frame->abs_ts);
138 for (framenum = 1; framenum <= cf->count; framenum++) {
139 cur_frame = frame_data_sequence_find(cf->frames, framenum);
140 tally_frame_data(cur_frame, st);
144 st->filename = cf->filename;
145 st->file_length = cf->f_datalen;
146 st->file_type = cf->cd_t;
147 st->iscompressed = cf->iscompressed;
148 st->is_tempfile = cf->is_tempfile;
149 st->file_encap_type = cf->lnk_t;
150 st->packet_encap_types = cf->linktypes;
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 st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options));
159 idb_info = wtap_file_get_idb_info(cf->wth);
160 for (i = 0; i < idb_info->interface_data->len; i++) {
161 wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, i);
162 wtapng_if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wtapng_if_descr);
163 if (wtap_block_get_custom_option_value(wtapng_if_descr, OPT_IDB_FILTER, (void**)&if_filter) == WTAP_OPTTYPE_SUCCESS) {
164 iface.cfilter = g_strdup(if_filter->if_filter_str);
166 iface.cfilter = NULL;
168 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_NAME, &if_string) == WTAP_OPTTYPE_SUCCESS) {
169 iface.name = g_strdup(if_string);
173 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &if_string) == WTAP_OPTTYPE_SUCCESS) {
174 iface.descr = g_strdup(if_string);
178 iface.drops_known = FALSE;
180 iface.snap = wtapng_if_descr_mand->snap_len;
181 iface.encap_type = wtapng_if_descr_mand->wtap_encap;
182 iface.isb_comment = NULL;
183 if(wtapng_if_descr_mand->num_stat_entries == 1){
184 /* dumpcap only writes one ISB, only handle that for now */
185 if_stats = g_array_index(wtapng_if_descr_mand->interface_statistics, wtap_block_t, 0);
186 if (wtap_block_get_uint64_option_value(if_stats, OPT_ISB_IFDROP, &isb_ifdrop) == WTAP_OPTTYPE_SUCCESS) {
187 iface.drops_known = TRUE;
188 iface.drops = isb_ifdrop;
190 /* XXX: this doesn't get used, and might need to be g_strdup'ed when it does */
191 /* XXX - support multiple comments */
192 if (wtap_block_get_nth_string_option_value(if_stats, OPT_COMMENT, 0, &iface.isb_comment) != WTAP_OPTTYPE_SUCCESS) {
193 iface.isb_comment = NULL;
196 g_array_append_val(st->ifaces, iface);
203 summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
209 if (st->ifaces->len == 0) {
211 * XXX - do this only if we have a live capture.
213 for (i = 0; i < capture_opts->all_ifaces->len; i++) {
214 device = g_array_index(capture_opts->all_ifaces, interface_t, i);
215 if (!device.selected) {
218 iface.cfilter = g_strdup(device.cfilter);
219 iface.name = g_strdup(device.name);
220 iface.descr = g_strdup(device.display_name);
221 iface.drops_known = cf->drops_known;
222 iface.drops = cf->drops;
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);
232 * Editor modelines - http://www.wireshark.org/tools/modelines.html
237 * indent-tabs-mode: nil
240 * ex: set shiftwidth=2 tabstop=8 expandtab:
241 * :indentSize=2:tabSize=8:noTabs=true: