Add a presence flag field to the packet information structure filled in
[obnox/wireshark/wip.git] / summary.c
1 /* summary.c
2  * Routines for capture file summary info
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
31 #endif
32
33 #include <epan/packet.h>
34 #include "cfile.h"
35 #include "summary.h"
36 #ifdef HAVE_LIBPCAP
37 #include "capture_ui_utils.h"
38 #endif
39
40
41 static void
42 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
43 {
44   double cur_time;
45
46   cur_time = nstime_to_sec(&cur_frame->abs_ts);
47
48   if (cur_time < sum_tally->start_time) {
49     sum_tally->start_time = cur_time;
50   }
51   if (cur_time > sum_tally->stop_time){
52     sum_tally->stop_time = cur_time;
53   }
54   sum_tally->bytes += cur_frame->pkt_len;
55   if (cur_frame->flags.passed_dfilter){
56     if (sum_tally->filtered_count==0){
57             sum_tally->filtered_start= cur_time;
58             sum_tally->filtered_stop = cur_time;
59     } else {
60             if (cur_time < sum_tally->filtered_start) {
61                     sum_tally->filtered_start = cur_time;
62             }
63             if (cur_time > sum_tally->filtered_stop) {
64                     sum_tally->filtered_stop = cur_time;
65             }
66     }
67     sum_tally->filtered_count++;
68     sum_tally->filtered_bytes += cur_frame->pkt_len ;
69   }
70   if (cur_frame->flags.marked){
71     if (sum_tally->marked_count==0){
72             sum_tally->marked_start= cur_time;
73             sum_tally->marked_stop = cur_time;
74     } else {
75             if (cur_time < sum_tally->marked_start) {
76                     sum_tally->marked_start = cur_time;
77             }
78             if (cur_time > sum_tally->marked_stop) {
79                     sum_tally->marked_stop = cur_time;
80             }
81     }
82     sum_tally->marked_count++;
83     sum_tally->marked_bytes += cur_frame->pkt_len ;
84   }
85   if (cur_frame->flags.ignored){
86     sum_tally->ignored_count++;
87   }
88 }
89
90 void
91 summary_fill_in(capture_file *cf, summary_tally *st)
92 {
93
94   frame_data    *first_frame, *cur_frame;
95   guint32        framenum;
96   wtapng_section_t* shb_inf;
97
98   st->start_time = 0;
99   st->stop_time = 0;
100   st->bytes = 0;
101   st->filtered_count = 0;
102   st->filtered_start = 0;
103   st->filtered_stop = 0;
104   st->filtered_bytes = 0;
105   st->marked_count = 0;
106   st->marked_start = 0;
107   st->marked_stop = 0;
108   st->marked_bytes = 0;
109   st->ignored_count = 0;
110
111   /* initialize the tally */
112   if (cf->count != 0) {
113     first_frame = frame_data_sequence_find(cf->frames, 1);
114     st->start_time = nstime_to_sec(&first_frame->abs_ts);
115     st->stop_time = nstime_to_sec(&first_frame->abs_ts);
116
117     for (framenum = 1; framenum <= cf->count; framenum++) {
118       cur_frame = frame_data_sequence_find(cf->frames, framenum);
119       tally_frame_data(cur_frame, st);
120     }
121   }
122
123   st->filename = cf->filename;
124   st->file_length = cf->f_datalen;
125   st->file_type = cf->cd_t;
126   st->is_tempfile = cf->is_tempfile;
127   st->encap_type = cf->lnk_t;
128   st->has_snap = cf->has_snap;
129   st->snap = cf->snap;
130   st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
131   st->packet_count = cf->count;
132   st->drops_known = cf->drops_known;
133   st->drops = cf->drops;
134   st->dfilter = cf->dfilter;
135
136   /* Get info from SHB */
137   shb_inf = wtap_file_get_shb_info(cf->wth);
138
139   shb_inf = wtap_file_get_shb_info(cf->wth);
140   st->opt_comment    = shb_inf->opt_comment;
141   st->shb_hardware   = shb_inf->shb_hardware;
142   st->shb_os         = shb_inf->shb_os;
143   st->shb_user_appl  = shb_inf->shb_user_appl;
144   g_free(shb_inf);
145
146   st->ifaces  = g_array_new(FALSE, FALSE, sizeof(iface_options));
147 }
148
149
150 #ifdef HAVE_LIBPCAP
151 void
152 summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
153 {
154   iface_options iface;
155   interface_t device;
156   guint i;
157   wtapng_iface_descriptions_t* idb_info;
158   wtapng_if_descr_t wtapng_if_descr;
159
160   while (st->ifaces->len > 0) {
161     iface = g_array_index(st->ifaces, iface_options, 0);
162     st->ifaces = g_array_remove_index(st->ifaces, 0);
163     g_free(iface.name);
164     g_free(iface.descr);
165     g_free(iface.cfilter);
166   }
167   if (st->is_tempfile) {
168     for (i = 0; i < capture_opts->all_ifaces->len; i++) {
169       device = g_array_index(capture_opts->all_ifaces, interface_t, i);
170       if (!device.selected) {
171         continue;
172       }
173       iface.cfilter = g_strdup(device.cfilter);
174       iface.name = g_strdup(device.name);
175       iface.descr = g_strdup(device.display_name);
176       iface.drops_known = cf->drops_known;
177       iface.drops = cf->drops;
178       iface.has_snap = device.has_snaplen;
179       iface.snap = device.snaplen;
180       iface.linktype = device.active_dlt;
181       g_array_append_val(st->ifaces, iface);
182     }
183   } else {
184     idb_info = wtap_file_get_idb_info(cf->wth);
185     for (i = 0; i < idb_info->number_of_interfaces; i++) {
186       wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i);
187       iface.cfilter = g_strdup(wtapng_if_descr.if_filter);
188       iface.name = g_strdup(wtapng_if_descr.if_name);
189       iface.descr = g_strdup(wtapng_if_descr.if_description);
190       iface.drops_known = FALSE;
191       iface.drops = 0;
192       iface.snap = wtapng_if_descr.snap_len;
193       iface.has_snap = (iface.snap != 65535);
194       iface.linktype = wtapng_if_descr.link_type;
195       g_array_append_val(st->ifaces, iface);
196     }
197         g_free(idb_info);
198   }
199 }
200 #endif