2005-02-16 14:16:40 +00:00
|
|
|
/* tap-stats_tree.c
|
|
|
|
* tethereal's tap implememntation of stats_tree
|
|
|
|
* 2005, Luis E. G. Ontanon
|
|
|
|
*
|
|
|
|
* $Id: $
|
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/stats_tree_priv.h>
|
|
|
|
|
|
|
|
/* actually unused */
|
|
|
|
struct _st_node_pres {
|
|
|
|
void* dummy;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _tree_pres {
|
2005-03-20 00:19:15 +00:00
|
|
|
void* dummy;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _tree_cfg_pres {
|
2005-02-16 14:16:40 +00:00
|
|
|
guint8* init_string;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void draw_stats_tree(void *psp) {
|
|
|
|
stats_tree *st = psp;
|
|
|
|
GString* s;
|
2005-02-27 16:55:24 +00:00
|
|
|
gchar* fmt;
|
2005-02-16 14:16:40 +00:00
|
|
|
stat_node* child;
|
|
|
|
|
|
|
|
s = g_string_new("\n===================================================================\n");
|
2005-03-21 00:55:04 +00:00
|
|
|
fmt = g_strdup_printf(" %%s%%-%us%%12s\t%%12s\t%%12s\n",stats_tree_branch_max_namelen(&st->root,0));
|
2005-03-20 00:19:15 +00:00
|
|
|
g_string_sprintfa(s,fmt,"",st->cfg->name,"value","rate","percent");
|
2005-02-27 16:55:24 +00:00
|
|
|
g_free(fmt);
|
|
|
|
g_string_sprintfa(s,"-------------------------------------------------------------------\n");
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
for (child = st->root.children; child; child = child->next ) {
|
2005-03-21 00:55:04 +00:00
|
|
|
stats_tree_branch_to_str(child,s,0);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s = g_string_append(s,"\n===================================================================\n");
|
|
|
|
|
|
|
|
printf("%s",s->str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_stats_tree(char *optarg) {
|
2005-03-21 00:55:04 +00:00
|
|
|
guint8* abbr = stats_tree_get_abbr(optarg);
|
2005-02-16 14:16:40 +00:00
|
|
|
GString *error_string;
|
2005-03-20 00:19:15 +00:00
|
|
|
stats_tree_cfg *cfg = NULL;
|
|
|
|
stats_tree* st = NULL;
|
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
if (abbr) {
|
2005-03-21 00:55:04 +00:00
|
|
|
cfg = stats_tree_get_cfg_by_abbr(abbr);
|
2005-03-20 00:19:15 +00:00
|
|
|
|
|
|
|
if (cfg != NULL) {
|
|
|
|
if (strncmp (optarg, cfg->pr->init_string, strlen(cfg->pr->init_string)) == 0){
|
2005-03-21 00:55:04 +00:00
|
|
|
st = stats_tree_new(cfg,NULL,((guint8*)optarg)+strlen(cfg->pr->init_string));
|
2005-02-16 14:16:40 +00:00
|
|
|
} else {
|
|
|
|
st->filter=NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g_error("no such stats_tree (%s) found in stats_tree registry",abbr);
|
|
|
|
}
|
2005-02-24 22:02:31 +00:00
|
|
|
|
|
|
|
g_free(abbr);
|
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
} else {
|
2005-02-24 22:02:31 +00:00
|
|
|
g_error("could not obtain stats_tree abbr (%s) from optarg '%s'",abbr,optarg);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
error_string = register_tap_listener( st->cfg->tapname,
|
2005-02-16 14:16:40 +00:00
|
|
|
st,
|
|
|
|
st->filter,
|
2005-03-21 00:55:04 +00:00
|
|
|
stats_tree_reset,
|
2005-02-16 14:16:40 +00:00
|
|
|
stats_tree_packet,
|
|
|
|
draw_stats_tree);
|
|
|
|
|
|
|
|
if (error_string) {
|
2005-03-20 00:19:15 +00:00
|
|
|
g_error("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
if (cfg->init) cfg->init(st);
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void register_stats_tree_tap (gpointer k _U_, gpointer v, gpointer p _U_) {
|
2005-03-20 00:19:15 +00:00
|
|
|
stats_tree_cfg* cfg = v;
|
2005-02-16 14:16:40 +00:00
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
cfg->pr = g_malloc(sizeof(tree_cfg_pres));
|
|
|
|
cfg->pr->init_string = g_strdup_printf("%s,tree",cfg->abbr);
|
2005-02-16 14:16:40 +00:00
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
register_ethereal_tap(cfg->pr->init_string, init_stats_tree);
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-03-20 00:19:15 +00:00
|
|
|
static void free_tree_presentation(stats_tree* st) {
|
|
|
|
g_free(st->pr);
|
|
|
|
}
|
|
|
|
|
2005-02-16 14:16:40 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
register_tap_listener_stats_tree_stat(void)
|
|
|
|
{
|
|
|
|
stats_tree_presentation(register_stats_tree_tap,
|
|
|
|
NULL, NULL, NULL, NULL, NULL,
|
2005-03-20 00:19:15 +00:00
|
|
|
free_tree_presentation, NULL, NULL, NULL);
|
2005-02-16 14:16:40 +00:00
|
|
|
}
|