2001-03-22 23:54:47 +00:00
|
|
|
/* proto_hier_stats.c
|
|
|
|
* Routines for calculating statistics based on protocol.
|
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2001-03-22 23:54:47 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-12-10 00:26:21 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
2001-03-22 23:54:47 +00:00
|
|
|
* 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 "globals.h"
|
|
|
|
#include "proto_hier_stats.h"
|
2001-03-24 02:07:22 +00:00
|
|
|
#include "progress_dlg.h"
|
2003-09-03 23:32:40 +00:00
|
|
|
#include "simple_dialog.h"
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/epan_dissect.h>
|
2001-03-22 23:54:47 +00:00
|
|
|
#include <wtap.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
2001-03-24 02:07:22 +00:00
|
|
|
/* Update the progress bar this many times when scanning the packet list. */
|
|
|
|
#define N_PROGBAR_UPDATES 100
|
|
|
|
|
2002-01-02 20:23:46 +00:00
|
|
|
#define STAT_NODE_STATS(n) ((ph_stats_node_t*)(n)->data)
|
|
|
|
#define STAT_NODE_HFINFO(n) (STAT_NODE_STATS(n)->hfinfo)
|
|
|
|
|
2004-03-17 21:48:15 +00:00
|
|
|
static double
|
|
|
|
secs_usecs(guint32 s, guint32 us)
|
|
|
|
{
|
|
|
|
return (us / 1000000.0) + (double)s;
|
|
|
|
}
|
|
|
|
|
2001-03-22 23:54:47 +00:00
|
|
|
static GNode*
|
2002-01-02 20:23:46 +00:00
|
|
|
find_stat_node(GNode *parent_stat_node, header_field_info *needle_hfinfo)
|
2001-03-22 23:54:47 +00:00
|
|
|
{
|
2002-01-02 20:23:46 +00:00
|
|
|
GNode *needle_stat_node;
|
|
|
|
header_field_info *hfinfo;
|
|
|
|
ph_stats_node_t *stats;
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2002-01-02 20:23:46 +00:00
|
|
|
needle_stat_node = g_node_first_child(parent_stat_node);
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2002-01-02 20:23:46 +00:00
|
|
|
while (needle_stat_node) {
|
|
|
|
hfinfo = STAT_NODE_HFINFO(needle_stat_node);
|
|
|
|
if (hfinfo && hfinfo->id == needle_hfinfo->id) {
|
|
|
|
return needle_stat_node;
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
2002-01-02 20:23:46 +00:00
|
|
|
needle_stat_node = g_node_next_sibling(needle_stat_node);
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* None found. Create one. */
|
|
|
|
stats = g_new(ph_stats_node_t, 1);
|
|
|
|
|
|
|
|
/* Intialize counters */
|
|
|
|
stats->hfinfo = needle_hfinfo;
|
|
|
|
stats->num_pkts_total = 0;
|
|
|
|
stats->num_pkts_last = 0;
|
|
|
|
stats->num_bytes_total = 0;
|
|
|
|
stats->num_bytes_last = 0;
|
|
|
|
|
2002-01-02 20:23:46 +00:00
|
|
|
needle_stat_node = g_node_new(stats);
|
|
|
|
g_node_append(parent_stat_node, needle_stat_node);
|
|
|
|
return needle_stat_node;
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-12-04 10:59:34 +00:00
|
|
|
process_node(proto_node *ptree_node, GNode *parent_stat_node, ph_stats_t *ps, guint pkt_len)
|
2001-03-22 23:54:47 +00:00
|
|
|
{
|
|
|
|
field_info *finfo;
|
2003-12-04 10:59:34 +00:00
|
|
|
ph_stats_node_t *stats;
|
|
|
|
proto_node *proto_sibling_node;
|
2001-03-22 23:54:47 +00:00
|
|
|
GNode *stat_node;
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
finfo = PITEM_FINFO(ptree_node);
|
2001-03-22 23:54:47 +00:00
|
|
|
g_assert(finfo);
|
|
|
|
|
2003-12-03 09:28:26 +00:00
|
|
|
stat_node = find_stat_node(parent_stat_node, finfo->hfinfo);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-03-22 23:54:47 +00:00
|
|
|
/* Assert that the finfo is related to a protocol, not a field. */
|
2003-12-03 09:28:26 +00:00
|
|
|
g_assert(finfo->hfinfo->parent == -1);
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2002-01-02 20:23:46 +00:00
|
|
|
stats = STAT_NODE_STATS(stat_node);
|
2001-03-22 23:54:47 +00:00
|
|
|
stats->num_pkts_total++;
|
|
|
|
stats->num_bytes_total += pkt_len;
|
|
|
|
|
2003-12-04 10:59:34 +00:00
|
|
|
proto_sibling_node = ptree_node->next;
|
2001-03-22 23:54:47 +00:00
|
|
|
|
|
|
|
if (proto_sibling_node) {
|
|
|
|
process_node(proto_sibling_node, stat_node, ps, pkt_len);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stats->num_pkts_last++;
|
|
|
|
stats->num_bytes_last += pkt_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_tree(proto_tree *protocol_tree, ph_stats_t* ps, guint pkt_len)
|
|
|
|
{
|
2003-12-04 10:59:34 +00:00
|
|
|
proto_node *ptree_node;
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2003-12-04 10:59:34 +00:00
|
|
|
ptree_node = ((proto_node *)protocol_tree)->first_child;
|
2001-12-18 19:09:08 +00:00
|
|
|
if (!ptree_node) {
|
2001-03-22 23:54:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-18 19:09:08 +00:00
|
|
|
process_node(ptree_node, ps->stats_tree, ps, pkt_len);
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 23:32:40 +00:00
|
|
|
static gboolean
|
2001-12-10 00:26:21 +00:00
|
|
|
process_frame(frame_data *frame, column_info *cinfo, ph_stats_t* ps)
|
2001-03-22 23:54:47 +00:00
|
|
|
{
|
|
|
|
epan_dissect_t *edt;
|
|
|
|
union wtap_pseudo_header phdr;
|
|
|
|
guint8 pd[WTAP_MAX_PACKET_SIZE];
|
2002-03-05 05:58:41 +00:00
|
|
|
int err;
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
gchar *err_info;
|
2004-03-17 21:48:15 +00:00
|
|
|
double cur_time;
|
2001-03-22 23:54:47 +00:00
|
|
|
|
|
|
|
/* Load the frame from the capture file */
|
2003-09-03 23:32:40 +00:00
|
|
|
if (!wtap_seek_read(cfile.wth, frame->file_off, &phdr, pd,
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
frame->cap_len, &err, &err_info)) {
|
2004-01-31 03:22:42 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
|
Have the Wiretap open, read, and seek-and-read routines return, in
addition to an error code, an error info string, for
WTAP_ERR_UNSUPPORTED, WTAP_ERR_UNSUPPORTED_ENCAP, and
WTAP_ERR_BAD_RECORD errors. Replace the error messages logged with
"g_message()" for those errors with g_strdup()ed or g_strdup_printf()ed
strings returned as the error info string, and change the callers of
those routines to, for those errors, put the info string into the
printed message or alert box for the error.
Add messages for cases where those errors were returned without printing
an additional message.
Nobody uses the error code from "cf_read()" - "cf_read()" puts up the
alert box itself for failures; get rid of the error code, so it just
returns a success/failure indication.
Rename "file_read_error_message()" to "cf_read_error_message()", as it
handles read errors from Wiretap, and have it take an error info string
as an argument. (That handles a lot of the work of putting the info
string into the error message.)
Make some variables in "ascend-grammar.y" static.
Check the return value of "erf_read_header()" in "erf_seek_read()".
Get rid of an unused #define in "i4btrace.c".
svn path=/trunk/; revision=9852
2004-01-25 21:55:17 +00:00
|
|
|
cf_read_error_message(err, err_info), cfile.filename);
|
2003-09-03 23:32:40 +00:00
|
|
|
return FALSE; /* failure */
|
|
|
|
}
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2005-04-07 12:00:03 +00:00
|
|
|
/* Dissect the frame tree not visible */
|
2001-12-18 19:09:08 +00:00
|
|
|
edt = epan_dissect_new(TRUE, FALSE);
|
2002-03-05 05:58:41 +00:00
|
|
|
epan_dissect_run(edt, &phdr, pd, frame, cinfo);
|
2001-03-22 23:54:47 +00:00
|
|
|
|
|
|
|
/* Get stats from this protocol tree */
|
2001-12-06 04:25:09 +00:00
|
|
|
process_tree(edt->tree, ps, frame->pkt_len);
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2004-03-17 21:48:15 +00:00
|
|
|
/* Update times */
|
|
|
|
cur_time = secs_usecs(frame->abs_secs, frame->abs_usecs);
|
|
|
|
if (cur_time < ps->first_time) {
|
|
|
|
ps->first_time = cur_time;
|
|
|
|
}
|
|
|
|
if (cur_time > ps->last_time){
|
|
|
|
ps->last_time = cur_time;
|
|
|
|
}
|
|
|
|
|
2001-03-22 23:54:47 +00:00
|
|
|
/* Free our memory. */
|
|
|
|
epan_dissect_free(edt);
|
2003-09-03 23:32:40 +00:00
|
|
|
|
|
|
|
return TRUE; /* success */
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ph_stats_t*
|
|
|
|
ph_stats_new(void)
|
|
|
|
{
|
|
|
|
ph_stats_t *ps;
|
|
|
|
frame_data *frame;
|
|
|
|
guint tot_packets, tot_bytes;
|
2002-07-30 10:13:16 +00:00
|
|
|
progdlg_t *progbar = NULL;
|
2001-03-24 02:07:22 +00:00
|
|
|
gboolean stop_flag;
|
2002-08-28 10:07:37 +00:00
|
|
|
int count;
|
2002-07-30 10:13:16 +00:00
|
|
|
float prog_val;
|
|
|
|
GTimeVal start_time;
|
2002-08-28 10:07:37 +00:00
|
|
|
gchar status_str[100];
|
2004-01-09 21:38:21 +00:00
|
|
|
int progbar_nextstep;
|
|
|
|
int progbar_quantum;
|
2001-03-22 23:54:47 +00:00
|
|
|
|
|
|
|
/* Initialize the data */
|
|
|
|
ps = g_new(ph_stats_t, 1);
|
|
|
|
ps->tot_packets = 0;
|
|
|
|
ps->tot_bytes = 0;
|
|
|
|
ps->stats_tree = g_node_new(NULL);
|
2004-03-17 21:48:15 +00:00
|
|
|
ps->first_time = 0.0;
|
|
|
|
ps->last_time = 0.0;
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2001-03-24 02:07:22 +00:00
|
|
|
/* Update the progress bar when it gets to this value. */
|
2004-01-09 21:38:21 +00:00
|
|
|
progbar_nextstep = 0;
|
2001-03-24 02:07:22 +00:00
|
|
|
/* When we reach the value that triggers a progress bar update,
|
|
|
|
bump that value by this amount. */
|
2004-01-09 21:38:21 +00:00
|
|
|
progbar_quantum = cfile.count/N_PROGBAR_UPDATES;
|
2001-03-24 02:07:22 +00:00
|
|
|
/* Count of packets at which we've looked. */
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
stop_flag = FALSE;
|
2002-07-30 10:13:16 +00:00
|
|
|
g_get_current_time(&start_time);
|
2001-03-24 02:07:22 +00:00
|
|
|
|
2001-03-22 23:54:47 +00:00
|
|
|
tot_packets = 0;
|
|
|
|
tot_bytes = 0;
|
|
|
|
|
2001-03-24 02:07:22 +00:00
|
|
|
for (frame = cfile.plist; frame != NULL; frame = frame->next) {
|
|
|
|
/* Update the progress bar, but do it only N_PROGBAR_UPDATES
|
|
|
|
times; when we update it, we have to run the GTK+ main
|
|
|
|
loop to get it to repaint what's pending, and doing so
|
|
|
|
may involve an "ioctl()" to see if there's any pending
|
|
|
|
input from an X server, and doing that for every packet
|
|
|
|
can be costly, especially on a big file. */
|
2004-01-09 21:38:21 +00:00
|
|
|
if (count >= progbar_nextstep) {
|
2001-03-24 02:07:22 +00:00
|
|
|
/* let's not divide by zero. I should never be started
|
|
|
|
* with count == 0, so let's assert that
|
|
|
|
*/
|
|
|
|
g_assert(cfile.count > 0);
|
|
|
|
|
2002-07-30 10:13:16 +00:00
|
|
|
prog_val = (gfloat) count / cfile.count;
|
2001-03-24 02:07:22 +00:00
|
|
|
|
2002-07-30 10:13:16 +00:00
|
|
|
if (progbar == NULL)
|
|
|
|
/* Create the progress bar if necessary */
|
|
|
|
progbar = delayed_create_progress_dlg(
|
2004-01-21 22:00:28 +00:00
|
|
|
"Computing", "protocol hierarchy statistics",
|
2002-07-30 10:13:16 +00:00
|
|
|
&stop_flag, &start_time, prog_val);
|
|
|
|
|
2002-08-28 10:07:37 +00:00
|
|
|
if (progbar != NULL) {
|
|
|
|
g_snprintf(status_str, sizeof(status_str),
|
|
|
|
"%4u of %u frames", count, cfile.count);
|
|
|
|
update_progress_dlg(progbar, prog_val, status_str);
|
|
|
|
}
|
2002-07-30 10:13:16 +00:00
|
|
|
|
2004-01-09 21:38:21 +00:00
|
|
|
progbar_nextstep += progbar_quantum;
|
2001-03-24 02:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stop_flag) {
|
|
|
|
/* Well, the user decided to abort the statistics.
|
|
|
|
computation process Just stop. */
|
|
|
|
break;
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
2001-03-24 02:07:22 +00:00
|
|
|
/* Skip frames that are hidden due to the display filter.
|
|
|
|
XXX - should the progress bar count only packets that
|
|
|
|
passed the display filter? If so, it should
|
|
|
|
probably do so for other loops (see "file.c") that
|
|
|
|
look only at those packets. */
|
|
|
|
if (frame->flags.passed_dfilter) {
|
2004-03-17 21:48:15 +00:00
|
|
|
|
|
|
|
if (tot_packets == 0) {
|
|
|
|
double cur_time = secs_usecs(frame->abs_secs,
|
|
|
|
frame->abs_usecs);
|
|
|
|
ps->first_time = cur_time;
|
|
|
|
ps->last_time = cur_time;
|
|
|
|
}
|
2005-04-07 12:00:03 +00:00
|
|
|
|
|
|
|
/* we don't care about colinfo */
|
|
|
|
if (!process_frame(frame, NULL, ps)) {
|
2003-09-03 23:32:40 +00:00
|
|
|
/*
|
|
|
|
* Give up, and set "stop_flag" so we
|
|
|
|
* just abort rather than popping up
|
|
|
|
* the statistics window.
|
|
|
|
*/
|
|
|
|
stop_flag = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-24 02:07:22 +00:00
|
|
|
|
|
|
|
tot_packets++;
|
|
|
|
tot_bytes += frame->pkt_len;
|
|
|
|
}
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2001-03-24 02:07:22 +00:00
|
|
|
count++;
|
|
|
|
}
|
2001-03-22 23:54:47 +00:00
|
|
|
|
2002-07-30 10:13:16 +00:00
|
|
|
/* We're done calculating the statistics; destroy the progress bar
|
|
|
|
if it was created. */
|
|
|
|
if (progbar != NULL)
|
|
|
|
destroy_progress_dlg(progbar);
|
2001-03-24 02:07:22 +00:00
|
|
|
|
|
|
|
if (stop_flag) {
|
|
|
|
/*
|
|
|
|
* We quit in the middle; throw away the statistics
|
|
|
|
* and return NULL, so our caller doesn't pop up a
|
|
|
|
* window with the incomplete statistics.
|
|
|
|
*/
|
|
|
|
ph_stats_free(ps);
|
|
|
|
return NULL;
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ps->tot_packets = tot_packets;
|
|
|
|
ps->tot_bytes = tot_bytes;
|
|
|
|
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2002-03-31 20:39:08 +00:00
|
|
|
stat_node_free(GNode *node, gpointer data _U_)
|
2001-03-22 23:54:47 +00:00
|
|
|
{
|
|
|
|
ph_stats_node_t *stats = node->data;
|
|
|
|
|
|
|
|
if (stats) {
|
|
|
|
g_free(stats);
|
|
|
|
}
|
2001-03-23 21:55:36 +00:00
|
|
|
return FALSE;
|
2001-03-22 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ph_stats_free(ph_stats_t *ps)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ps->stats_tree) {
|
|
|
|
g_node_traverse(ps->stats_tree, G_IN_ORDER,
|
|
|
|
G_TRAVERSE_ALL, -1,
|
|
|
|
stat_node_free, NULL);
|
|
|
|
g_node_destroy(ps->stats_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(ps);
|
|
|
|
}
|