[Diameter] Add a couple of command codes from IANA.
[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 #include <wiretap/wtap_opttypes.h>
27 #include <wiretap/pcapng.h>
28
29 #include <epan/packet.h>
30 #include "cfile.h"
31 #include "summary.h"
32
33 static void
34 tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
35 {
36   double cur_time;
37
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;
42   }
43   if (cur_frame->flags.marked){
44     sum_tally->marked_count++;
45     sum_tally->marked_bytes += cur_frame->pkt_len;
46   }
47   if (cur_frame->flags.ignored){
48     sum_tally->ignored_count++;
49   }
50
51   if (cur_frame->flags.has_ts) {
52     /* This packet has a time stamp. */
53     cur_time = nstime_to_sec(&cur_frame->abs_ts);
54
55     sum_tally->packet_count_ts++;
56     if (cur_time < sum_tally->start_time) {
57       sum_tally->start_time = cur_time;
58     }
59     if (cur_time > sum_tally->stop_time){
60       sum_tally->stop_time = cur_time;
61     }
62     if (cur_frame->flags.passed_dfilter){
63       sum_tally->filtered_count_ts++;
64       /*
65        * If we've seen one filtered packet, this is the first
66        * one.
67        */
68       if (sum_tally->filtered_count == 1){
69         sum_tally->filtered_start= cur_time;
70         sum_tally->filtered_stop = cur_time;
71       } else {
72         if (cur_time < sum_tally->filtered_start) {
73           sum_tally->filtered_start = cur_time;
74         }
75         if (cur_time > sum_tally->filtered_stop) {
76           sum_tally->filtered_stop = cur_time;
77         }
78       }
79     }
80     if (cur_frame->flags.marked){
81       sum_tally->marked_count_ts++;
82       /*
83        * If we've seen one marked packet, this is the first
84        * one.
85        */
86       if (sum_tally->marked_count == 1){
87         sum_tally->marked_start= cur_time;
88         sum_tally->marked_stop = cur_time;
89       } else {
90         if (cur_time < sum_tally->marked_start) {
91           sum_tally->marked_start = cur_time;
92         }
93         if (cur_time > sum_tally->marked_stop) {
94           sum_tally->marked_stop = cur_time;
95         }
96       }
97     }
98   }
99 }
100
101 void
102 summary_fill_in(capture_file *cf, summary_tally *st)
103 {
104   frame_data    *first_frame, *cur_frame;
105   guint32        framenum;
106   iface_options iface;
107   guint i;
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;
112   guint64 isb_ifdrop;
113   char* if_string;
114   wtapng_if_descr_filter_t* if_filter;
115
116   st->packet_count_ts = 0;
117   st->start_time = 0;
118   st->stop_time = 0;
119   st->bytes = 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;
128   st->marked_stop = 0;
129   st->marked_bytes = 0;
130   st->ignored_count = 0;
131
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);
137
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);
141     }
142   }
143
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;
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   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);
165     } else {
166       iface.cfilter = NULL;
167     }
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);
170     } else {
171       iface.name = NULL;
172     }
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);
175     } else {
176       iface.descr = NULL;
177     }
178     iface.drops_known = FALSE;
179     iface.drops = 0;
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;
189       }
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;
194       }
195     }
196     g_array_append_val(st->ifaces, iface);
197   }
198   g_free(idb_info);
199 }
200
201 #ifdef HAVE_LIBPCAP
202 void
203 summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
204 {
205   iface_options iface;
206   interface_t device;
207   guint i;
208
209   if (st->ifaces->len == 0) {
210     /*
211      * XXX - do this only if we have a live capture.
212      */
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) {
216         continue;
217       }
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);
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  */