X-Git-Url: http://git.samba.org/samba.git/?a=blobdiff_plain;f=tap-protohierstat.c;h=7f897b930aec45b560d24da17a79ad887850a34d;hb=0dc1c57b8bfafe566c15ed67ce0d131b37ae4776;hp=00131f0910800ae28c5911449be3e2afd1dadb0d;hpb=9abce60635dcb0bd95cbca2db2796dad0dc301c4;p=obnox%2Fwireshark%2Fwip.git diff --git a/tap-protohierstat.c b/tap-protohierstat.c index 00131f0910..7f897b930a 100644 --- a/tap-protohierstat.c +++ b/tap-protohierstat.c @@ -1,28 +1,28 @@ /* tap-protohierstat.c * protohierstat 2002 Ronnie Sahlberg * - * $Id: tap-protohierstat.c,v 1.2 2003/04/23 03:50:59 guy Exp $ + * $Id$ * - * Ethereal - Network traffic analyzer - * By Gerald Combs + * Wireshark - Network traffic analyzer + * By Gerald Combs * 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. */ -/* This module provides ProtocolHierarchyStatistics for tethereal */ +/* This module provides ProtocolHierarchyStatistics for tshark */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -38,7 +38,8 @@ #include "epan/packet_info.h" #include "epan/epan_dissect.h" #include "epan/proto.h" -#include "tap.h" +#include +#include #include "register.h" typedef struct _phs_t { @@ -47,9 +48,9 @@ typedef struct _phs_t { struct _phs_t *parent; char *filter; int protocol; - char *proto_name; + const char *proto_name; guint32 frames; - guint32 bytes; + guint64 bytes; } phs_t; @@ -71,7 +72,7 @@ new_phs_t(phs_t *parent) static int -protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *dummy _U_) +protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_) { phs_t *rs=prs; phs_t *tmprs; @@ -84,11 +85,11 @@ protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *d if(!edt->tree){ return 0; } - if(!edt->tree->children){ + if(!edt->tree->first_child){ return 0; } - for(tree=edt->tree->children;tree;tree=tree->next){ + for(tree=edt->tree->first_child;tree;tree=tree->next){ fi=PITEM_FINFO(tree); /* first time we saw a protocol at this leaf */ @@ -135,18 +136,24 @@ protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *d static void phs_draw(phs_t *rs, int indentation) { - int i; - char str[80]; + int i, stroff; +#define MAXPHSLINE 80 + char str[MAXPHSLINE]; for(;rs;rs=rs->sibling){ if(rs->protocol==-1){ return; } str[0]=0; + stroff=0; for(i=0;i15){ + stroff+=g_snprintf(str+stroff, MAXPHSLINE-stroff, "..."); + break; + } + stroff+=g_snprintf(str+stroff, MAXPHSLINE-stroff, " "); } - strcat(str, rs->proto_name); - printf("%-40s frames:%d bytes:%d\n",str, rs->frames, rs->bytes); + stroff+=g_snprintf(str+stroff, MAXPHSLINE-stroff, rs->proto_name); + printf("%-40s frames:%d bytes:%" G_GINT64_MODIFIER "d\n",str, rs->frames, rs->bytes); phs_draw(rs->child, indentation+1); } } @@ -166,11 +173,12 @@ protohierstat_draw(void *prs) static void -protohierstat_init(char *optarg) +protohierstat_init(const char *optarg, void* userdata _U_) { phs_t *rs; int pos=0; - char *filter=NULL; + const char *filter=NULL; + GString *error_string; if(!strcmp("io,phs",optarg)){ filter="frame"; @@ -182,28 +190,30 @@ protohierstat_init(char *optarg) will be populated. "frame" matches everything so that one is used instead of no filter. */ - filter="frame"; + filter="frame"; } } else { - fprintf(stderr, "tethereal: invalid \"-z io,phs[,]\" argument\n"); + fprintf(stderr, "tshark: invalid \"-z io,phs[,]\" argument\n"); exit(1); } rs=new_phs_t(NULL); if(filter){ - rs->filter=g_malloc(strlen(filter)+1); - strcpy(rs->filter, filter); + rs->filter=g_strdup(filter); } else { rs->filter=NULL; } - if(register_tap_listener("frame", rs, filter, NULL, protohierstat_packet, protohierstat_draw)){ + error_string=register_tap_listener("frame", rs, filter, NULL, protohierstat_packet, protohierstat_draw); + if(error_string){ /* error, we failed to attach to the tap. clean up */ g_free(rs->filter); g_free(rs); - fprintf(stderr,"tethereal: protohierstat_init() failed to attach to tap.\n"); + fprintf(stderr, "tshark: Couldn't register io,phs tap: %s\n", + error_string->str); + g_string_free(error_string, TRUE); exit(1); } } @@ -212,6 +222,6 @@ protohierstat_init(char *optarg) void register_tap_listener_protohierstat(void) { - register_ethereal_tap("io,phs", protohierstat_init); + register_stat_cmd_arg("io,phs", protohierstat_init, NULL); }