aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/summary_dlg.c
blob: d609cdd99d96c4497c1791933bd86601427a9276 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* summary_dlg.c
 * Routines for capture file summary window
 *
 * $Id: summary_dlg.c,v 1.28 2004/03/13 15:15:25 ulfl 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 <string.h>

#include <gtk/gtk.h>

#include <wtap.h>

#include "summary.h"
#include "summary_dlg.h"
#include "dlg_utils.h"
#include "ui_util.h"
#include "compat_macros.h"

#define SUM_STR_MAX 1024


static void
add_string_to_box(gchar *str, GtkWidget *box)
{
  GtkWidget *lb;
  lb = gtk_label_new(str);
  gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
  gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
  gtk_widget_show(lb);
}


void
summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
{
  summary_tally summary;
  GtkWidget     *sum_open_w,
                *main_vb, *file_fr, *data_fr, *capture_fr, *file_box,
		*filter_box, *filter_fr,
		*data_box, *capture_box, *bbox, *close_bt;

  gchar         string_buff[SUM_STR_MAX];

  double        seconds;
  guint         offset;
  gchar        *str_dup;
  gchar        *str_work;

 /* initialize the tally */
  summary_fill_in(&summary);

  /* initial computations */
  seconds = summary.stop_time - summary.start_time;
  sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: Summary");

  /* Container for each row of widgets */
  main_vb = gtk_vbox_new(FALSE, 3);
  gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
  gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
  gtk_widget_show(main_vb);

  /* File frame */
  file_fr = gtk_frame_new("File");
  gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
  gtk_widget_show(file_fr);

  file_box = gtk_vbox_new(FALSE, 3);
  gtk_container_border_width(GTK_CONTAINER(file_box), 5);
  gtk_container_add(GTK_CONTAINER(file_fr), file_box);
  gtk_widget_show(file_box);

  /* filename */
  g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", summary.filename);
  add_string_to_box(string_buff, file_box);

  /* length */
  g_snprintf(string_buff, SUM_STR_MAX, "Length: %lu", summary.file_length);
  add_string_to_box(string_buff, file_box);

  /* format */
  g_snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.encap_type));
  add_string_to_box(string_buff, file_box);

  if (summary.has_snap) {
    /* snapshot length */
    g_snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
    add_string_to_box(string_buff, file_box);
  }

  /* Data frame */
  data_fr = gtk_frame_new("Data");
  gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
  gtk_widget_show(data_fr);

  data_box = gtk_vbox_new(FALSE, 3);
  gtk_container_border_width(GTK_CONTAINER(data_box), 5);
  gtk_container_add(GTK_CONTAINER(data_fr), data_box);
  gtk_widget_show(data_box);

  /* seconds */
  g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
  add_string_to_box(string_buff, data_box);

  g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
  add_string_to_box(string_buff, data_box);

  /* Packet count */
  g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
  add_string_to_box(string_buff, data_box);

  /* Filtered Packet count */
  /* Unless there is none filter, we move informations about filtered packets in a separate frame */
  if (!summary.dfilter)
	add_string_to_box("Filtered packet count: 0", data_box);

  /* Marked Packet count */
  g_snprintf(string_buff, SUM_STR_MAX, "Marked packet count: %i", summary.marked_count);
  add_string_to_box(string_buff, data_box);

  /* Packets per second */
  if (seconds > 0){
    g_snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f", summary.packet_count/seconds);
    add_string_to_box(string_buff, data_box);
  }

  /* Packet size */
  if (summary.packet_count > 0){
    g_snprintf(string_buff, SUM_STR_MAX, "Avg. packet size: %.3f bytes",
      (float)summary.bytes/summary.packet_count);
    add_string_to_box(string_buff, data_box);
  }

  /* Dropped count */
  if (summary.drops_known) {
    g_snprintf(string_buff, SUM_STR_MAX, "Dropped packets: %u", summary.drops);
    add_string_to_box(string_buff, data_box);
  }

  /* Byte count */
  g_snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d", summary.bytes);
  add_string_to_box(string_buff, data_box);

  /* Bytes per second */
  if (seconds > 0){
    g_snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f", summary.bytes/seconds);
    add_string_to_box(string_buff, data_box);

    /* MBit per second */
    g_snprintf(string_buff, SUM_STR_MAX, "Avg. Mbit/sec: %.3f",
             summary.bytes * 8.0 / (seconds * 1000.0 * 1000.0));
    add_string_to_box(string_buff, data_box);
  }

  /* Filtered packets frame */
  filter_fr = gtk_frame_new("Data in filtered packets");
  gtk_container_add(GTK_CONTAINER(main_vb), filter_fr);
  gtk_widget_show(filter_fr);

  filter_box = gtk_vbox_new( FALSE, 3);
  gtk_container_border_width(GTK_CONTAINER(filter_box), 5);
  gtk_container_add(GTK_CONTAINER(filter_fr), filter_box);
  gtk_widget_show(filter_box);

  if (summary.dfilter) {
    double seconds;

    /* Display filter */
    /* limit each row to some reasonable length */
    str_dup = g_strdup_printf("Display filter: %s", summary.dfilter);
    str_work = g_strdup(str_dup);
    offset = 0;
    while(strlen(str_work) > 100) {
        str_work[100] = '\0';
        add_string_to_box(str_work, filter_box);
        g_free(str_work);
        offset+=100;
        str_work = g_strdup(&str_dup[offset]);
    }
    
    add_string_to_box(str_work, filter_box);
    g_free(str_work);
    g_free(str_dup);

    /* seconds */
    seconds = (summary.filtered_stop - summary.filtered_start);
    g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
    add_string_to_box(string_buff, filter_box);

    /* Packet count */
    g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.filtered_count);
    add_string_to_box(string_buff, filter_box);

    /* Packets per second */
    if (seconds > 0){
      g_snprintf(string_buff, SUM_STR_MAX, "Avg. packets/sec: %.3f", summary.filtered_count/seconds);
      add_string_to_box(string_buff, filter_box);
    }

    /* Packet size */
    if (summary.filtered_count > 0){
      g_snprintf(string_buff, SUM_STR_MAX, "Avg. packet size: %.3f bytes",
          (float) summary.filtered_bytes/summary.filtered_count);
      add_string_to_box(string_buff, filter_box);
    }

    /* Byte count */
    g_snprintf(string_buff, SUM_STR_MAX, "Bytes of traffic: %d", summary.filtered_bytes);
    add_string_to_box(string_buff, filter_box);

    /* Bytes per second */
    if (seconds > 0){
      g_snprintf(string_buff, SUM_STR_MAX, "Avg. bytes/sec: %.3f", summary.filtered_bytes/seconds);
      add_string_to_box(string_buff, filter_box);

      /* MBit per second */
      g_snprintf(string_buff, SUM_STR_MAX, "Avg. Mbit/sec: %.3f",
	       summary.filtered_bytes * 8.0 / (seconds * 1000.0 * 1000.0));
      add_string_to_box(string_buff, filter_box);
    }
  } else {
    /* Display filter */
    g_snprintf(string_buff, SUM_STR_MAX, "Display filter: none");
    add_string_to_box(string_buff, filter_box);
  }

  /* Capture Frame */
  capture_fr = gtk_frame_new("Capture");
  gtk_container_add(GTK_CONTAINER(main_vb), capture_fr);
  gtk_widget_show(capture_fr);

  capture_box = gtk_vbox_new(FALSE, 3);
  gtk_container_border_width(GTK_CONTAINER(capture_box), 5);
  gtk_container_add(GTK_CONTAINER(capture_fr), capture_box);
  gtk_widget_show(capture_box);

  /* interface */
  if (summary.iface) {
    g_snprintf(string_buff, SUM_STR_MAX, "Interface: %s", summary.iface);
  } else {
    g_snprintf(string_buff, SUM_STR_MAX, "Interface: unknown");
  }
  add_string_to_box(string_buff, capture_box);

#ifdef HAVE_LIBPCAP
  /* Capture filter */
  if (summary.cfilter && summary.cfilter[0] != '\0') {
    g_snprintf(string_buff, SUM_STR_MAX, "Capture filter: %s", summary.cfilter);
  } else {
    g_snprintf(string_buff, SUM_STR_MAX, "Capture filter: none");
  }
  add_string_to_box(string_buff, capture_box);
#endif

  /* Button row. */
  bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
  gtk_container_add(GTK_CONTAINER(main_vb), bbox);
  gtk_widget_show(bbox);

  close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
  SIGNAL_CONNECT_OBJECT(close_bt, "clicked", gtk_widget_destroy, sum_open_w);
  gtk_widget_grab_default(close_bt);

  /* Catch the "key_press_event" signal in the window, so that we can catch
     the ESC key being pressed and act as if the "Close" button had
     been selected. */
  dlg_set_cancel(sum_open_w, close_bt);

  gtk_window_set_position(GTK_WINDOW(sum_open_w), GTK_WIN_POS_MOUSE);
  gtk_widget_show(sum_open_w);
}