aboutsummaryrefslogtreecommitdiffstats
path: root/summary.c
blob: 0fe058c7e6bac157b2325c094610a4c6dbd52fda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* summary.c
 * Routines for capture file summary info
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#include <epan/packet.h>
#include "cfile.h"
#include "summary.h"
#ifdef HAVE_LIBPCAP
#include "capture_ui_utils.h"
#endif


static void
tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
{
  double cur_time;

  cur_time = nstime_to_sec(&cur_frame->abs_ts);

  if (cur_time < sum_tally->start_time) {
    sum_tally->start_time = cur_time;
  }
  if (cur_time > sum_tally->stop_time){
    sum_tally->stop_time = cur_time;
  }
  sum_tally->bytes += cur_frame->pkt_len;
  if (cur_frame->flags.passed_dfilter){
    if (sum_tally->filtered_count==0){
	    sum_tally->filtered_start= cur_time;
	    sum_tally->filtered_stop = cur_time;
    } else {
	    if (cur_time < sum_tally->filtered_start) {
		    sum_tally->filtered_start = cur_time;
	    }
	    if (cur_time > sum_tally->filtered_stop) {
		    sum_tally->filtered_stop = cur_time;
	    }
    }
    sum_tally->filtered_count++;
    sum_tally->filtered_bytes += cur_frame->pkt_len ;
  }
  if (cur_frame->flags.marked){
    if (sum_tally->marked_count==0){
	    sum_tally->marked_start= cur_time;
	    sum_tally->marked_stop = cur_time;
    } else {
	    if (cur_time < sum_tally->marked_start) {
		    sum_tally->marked_start = cur_time;
	    }
	    if (cur_time > sum_tally->marked_stop) {
		    sum_tally->marked_stop = cur_time;
	    }
    }
    sum_tally->marked_count++;
    sum_tally->marked_bytes += cur_frame->pkt_len ;
  }
  if (cur_frame->flags.ignored){
    sum_tally->ignored_count++;
  }
}

void
summary_fill_in(capture_file *cf, summary_tally *st)
{

  frame_data    *first_frame, *cur_frame;
  guint32        framenum;

  st->start_time = 0;
  st->stop_time = 0;
  st->bytes = 0;
  st->filtered_count = 0;
  st->filtered_start = 0;
  st->filtered_stop = 0;
  st->filtered_bytes = 0;
  st->marked_count = 0;
  st->marked_start = 0;
  st->marked_stop = 0;
  st->marked_bytes = 0;
  st->ignored_count = 0;

  /* initialize the tally */
  if (cf->count != 0) {
    first_frame = frame_data_sequence_find(cf->frames, 1);
    st->start_time = nstime_to_sec(&first_frame->abs_ts);
    st->stop_time = nstime_to_sec(&first_frame->abs_ts);

    for (framenum = 1; framenum <= cf->count; framenum++) {
      cur_frame = frame_data_sequence_find(cf->frames, framenum);
      tally_frame_data(cur_frame, st);
    }
  }

  st->filename = cf->filename;
  st->file_length = cf->f_datalen;
  st->file_type = cf->cd_t;
  st->is_tempfile = cf->is_tempfile;
  st->encap_type = cf->lnk_t;
  st->has_snap = cf->has_snap;
  st->snap = cf->snap;
  st->elapsed_time = nstime_to_sec(&cf->elapsed_time);
  st->packet_count = cf->count;
  st->drops_known = cf->drops_known;
  st->drops = cf->drops;
  st->dfilter = cf->dfilter;

  st->ifaces  = g_array_new(FALSE, FALSE, sizeof(iface_options));
}


#ifdef HAVE_LIBPCAP
void
summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
{
  iface_options iface;
  interface_options interface_opts;
  guint i;
  wtapng_iface_descriptions_t* idb_info;
  wtapng_if_descr_t wtapng_if_descr;

  while (st->ifaces->len > 0) {
    iface = g_array_index(st->ifaces, iface_options, 0);
    st->ifaces = g_array_remove_index(st->ifaces, 0);
    g_free(iface.name);
    g_free(iface.descr);
    g_free(iface.cfilter);
  }
  if (st->is_tempfile) {
    for (i = 0; i < capture_opts->ifaces->len; i++) {
      interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
      iface.cfilter = g_strdup(interface_opts.cfilter);
      iface.name = g_strdup(interface_opts.name);
      iface.descr = g_strdup(interface_opts.descr);
      iface.drops_known = FALSE;
      iface.drops = 0;
      iface.has_snap = interface_opts.has_snaplen;
      iface.snap = interface_opts.snaplen;
      iface.linktype = interface_opts.linktype;
      g_array_append_val(st->ifaces, iface);
    }
  }else{
	idb_info = wtap_file_get_idb_info(cf->wth);
	for (i = 0; i < idb_info->number_of_interfaces; i++) {
      wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i);
      iface.cfilter = g_strdup(wtapng_if_descr.if_filter);
      iface.name = g_strdup(wtapng_if_descr.if_name);
      iface.descr = g_strdup(wtapng_if_descr.if_description);
      iface.drops_known = FALSE;
      iface.drops = 0;
      /*iface.has_snap = wtapng_if_descr.has_snaplen;*/
      iface.snap = wtapng_if_descr.snap_len;
      iface.linktype = wtapng_if_descr.link_type;
      g_array_append_val(st->ifaces, iface);
	  }


  }
}
#endif