There's no __solaris__ predefine for Solaris; just use __sun.
[metze/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   sum_tally->bytes += cur_frame->pkt_len;
47   if (cur_frame->flags.passed_dfilter){
48     sum_tally->filtered_count++;
49     sum_tally->filtered_bytes += cur_frame->pkt_len;
50   }
51   if (cur_frame->flags.marked){
52     sum_tally->marked_count++;
53     sum_tally->marked_bytes += cur_frame->pkt_len;
54   }
55   if (cur_frame->flags.ignored){
56     sum_tally->ignored_count++;
57   }
58
59   if (cur_frame->flags.has_ts) {
60     /* This packet has a time stamp. */
61     cur_time = nstime_to_sec(&cur_frame->abs_ts);
62
63     sum_tally->packet_count_ts++;
64     if (cur_time < sum_tally->start_time) {
65       sum_tally->start_time = cur_time;
66     }
67     if (cur_time > sum_tally->stop_time){
68       sum_tally->stop_time = cur_time;
69     }
70     if (cur_frame->flags.passed_dfilter){
71       sum_tally->filtered_count_ts++;
72       /*
73        * If we've seen one filtered packet, this is the first
74        * one.
75        */
76       if (sum_tally->filtered_count == 1){
77         sum_tally->filtered_start= cur_time;
78         sum_tally->filtered_stop = cur_time;
79       } else {
80         if (cur_time < sum_tally->filtered_start) {
81           sum_tally->filtered_start = cur_time;
82         }
83         if (cur_time > sum_tally->filtered_stop) {
84           sum_tally->filtered_stop = cur_time;
85         }
86       }
87     }
88     if (cur_frame->flags.marked){
89       sum_tally->marked_count_ts++;
90       /*
91        * If we've seen one marked packet, this is the first
92        * one.
93        */
94       if (sum_tally->marked_count == 1){
95         sum_tally->marked_start= cur_time;
96         sum_tally->marked_stop = cur_time;
97       } else {
98         if (cur_time < sum_tally->marked_start) {
99           sum_tally->marked_start = cur_time;
100         }
101         if (cur_time > sum_tally->marked_stop) {
102           sum_tally->marked_stop = cur_time;
103         }
104       }
105     }
106   }
107 }
108
109 void
110 summary_fill_in(capture_file *cf, summary_tally *st)
111 {
112
113   frame_data    *first_frame, *cur_frame;
114   guint32        framenum;
115   wtapng_section_t* shb_inf;
116
117   st->packet_count_ts = 0;
118   st->start_time = 0;
119   st->stop_time = 0;
120   st->bytes = 0;
121   st->filtered_count = 0;
122   st->filtered_count_ts = 0;
123   st->filtered_start = 0;
124   st->filtered_stop = 0;
125   st->filtered_bytes = 0;
126   st->marked_count = 0;
127   st->marked_count_ts = 0;
128   st->marked_start = 0;
129   st->marked_stop = 0;
130   st->marked_bytes = 0;
131   st->ignored_count = 0;
132
133   /* initialize the tally */
134   if (cf->count != 0) {
135     first_frame = frame_data_sequence_find(cf->frames, 1);
136     st->start_time = nstime_to_sec(&first_frame->abs_ts);
137     st->stop_time = nstime_to_sec(&first_frame->abs_ts);
138
139     for (framenum = 1; framenum <= cf->count; framenum++) {
140       cur_frame = frame_data_sequence_find(cf->frames, framenum);
141       tally_frame_data(cur_frame, st);
142     }
143   }
144
145   st->filename = cf->filename;
146   st->file_length = cf->f_datalen;
147   st->file_type = cf->cd_t;
148   st->is_tempfile = cf->is_tempfile;
149   st->encap_type = cf->lnk_t;
150   st->has_snap = cf->has_snap;
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   /* Get info from SHB */
159   shb_inf = wtap_file_get_shb_info(cf->wth);
160   if(shb_inf == NULL){
161           st->opt_comment    = NULL;
162           st->shb_hardware   = NULL;
163           st->shb_os         = NULL;
164           st->shb_user_appl  = NULL;
165   }else{
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;
170           g_free(shb_inf);
171   }
172
173   st->ifaces  = g_array_new(FALSE, FALSE, sizeof(iface_options));
174 }
175
176
177 #ifdef HAVE_LIBPCAP
178 void
179 summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
180 {
181   iface_options iface;
182   interface_t device;
183   guint i;
184   wtapng_iface_descriptions_t* idb_info;
185   wtapng_if_descr_t wtapng_if_descr;
186   wtapng_if_stats_t *if_stats;
187
188   while (st->ifaces->len > 0) {
189     iface = g_array_index(st->ifaces, iface_options, 0);
190     st->ifaces = g_array_remove_index(st->ifaces, 0);
191     g_free(iface.name);
192     g_free(iface.descr);
193     g_free(iface.cfilter);
194   }
195   if (st->is_tempfile) {
196     for (i = 0; i < capture_opts->all_ifaces->len; i++) {
197       device = g_array_index(capture_opts->all_ifaces, interface_t, i);
198       if (!device.selected) {
199         continue;
200       }
201       iface.cfilter = g_strdup(device.cfilter);
202       iface.name = g_strdup(device.name);
203       iface.descr = g_strdup(device.display_name);
204       iface.drops_known = cf->drops_known;
205       iface.drops = cf->drops;
206       iface.has_snap = device.has_snaplen;
207       iface.snap = device.snaplen;
208       iface.linktype = device.active_dlt;
209       g_array_append_val(st->ifaces, iface);
210     }
211   } else {
212     idb_info = wtap_file_get_idb_info(cf->wth);
213     for (i = 0; i < idb_info->number_of_interfaces; i++) {
214       wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i);
215       iface.cfilter = g_strdup(wtapng_if_descr.if_filter_str);
216       iface.name = g_strdup(wtapng_if_descr.if_name);
217       iface.descr = g_strdup(wtapng_if_descr.if_description);
218       iface.drops_known = FALSE;
219       iface.drops = 0;
220       iface.snap = wtapng_if_descr.snap_len;
221       iface.has_snap = (iface.snap != 65535);
222       iface.linktype = wtapng_if_descr.link_type;
223           if(wtapng_if_descr.num_stat_entries == 1){
224                   /* dumpcap only writes one ISB, only handle that for now */
225                   if_stats = &g_array_index(wtapng_if_descr.interface_statistics, wtapng_if_stats_t, 0);
226                   iface.drops_known = TRUE;
227                   iface.drops = if_stats->isb_ifdrop;
228                   iface.isb_comment = if_stats->opt_comment;
229           }
230       g_array_append_val(st->ifaces, iface);
231     }
232     g_free(idb_info);
233   }
234 }
235 #endif
236
237 void
238 summary_update_comment(capture_file *cf, gchar *comment)
239 {
240
241   /* Get info from SHB */
242   wtap_write_shb_comment(cf->wth, comment);
243
244 }