aboutsummaryrefslogtreecommitdiffstats
path: root/summary.c
blob: 2b5715a485e73ddc155ebb44266df6cfed74ede7 (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
/* summary.c
 * Routines for capture file summary info
 *
 * $Id: summary.c,v 1.23 2003/09/02 22:10:32 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * 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

#include <epan/packet.h>
#include "globals.h"
#include "summary.h"


static double
secs_usecs( guint32 s, guint32 us)
{
  return (us / 1000000.0) + (double)s;
}

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

  cur_time = secs_usecs(cur_frame->abs_secs, cur_frame->abs_usecs);

  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->start_time = 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)
    sum_tally->marked_count++;

}

void
summary_fill_in(summary_tally *st)
{

  frame_data    *first_frame, *cur_frame;
  int 		i;
  frame_data    *cur_glist;

  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;

  /* initialize the tally */
  if (cfile.plist != NULL) {
    first_frame = cfile.plist;
    st->start_time 	= secs_usecs(first_frame->abs_secs,first_frame->abs_usecs);
    st->stop_time = secs_usecs(first_frame->abs_secs,first_frame->abs_usecs);
    cur_glist = cfile.plist;

    for (i = 0; i < cfile.count; i++) {
      cur_frame = cur_glist;
      tally_frame_data(cur_frame, st);
      cur_glist = cur_glist->next;
    }
  }

  st->filename = cfile.filename;
  st->file_length = cfile.f_len;
  st->encap_type = cfile.cd_t;
  st->has_snap = cfile.has_snap;
  st->snap = cfile.snap;
  st->elapsed_time = secs_usecs(cfile.esec, cfile.eusec);
  st->packet_count = cfile.count;
  st->drops_known = cfile.drops_known;
  st->drops = cfile.drops;
  st->iface = cfile.iface;
  st->dfilter = cfile.dfilter;

#ifdef HAVE_LIBPCAP
  st->cfilter = cfile.cfilter;
#else
  st->cfilter = NULL;
#endif
}