2 * wspstat 2003 Jean-Michel FAYARD
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* This module provides WSP statistics to tethereal.
26 * It is only used by tethereal and not ethereal
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
41 #include "epan/packet_info.h"
44 #include "epan/value_string.h"
45 #include <epan/dissectors/packet-wsp.h>
47 /* used to keep track of the stats for a specific PDU type*/
48 typedef struct _wsp_pdu_t {
52 /* used to keep track of RTT statistics */
53 typedef struct _wsp_status_code_t {
57 /* used to keep track of the statictics for an entire program interface */
58 typedef struct _wsp_stats_t {
66 wsp_reset_hash(gchar *key _U_ , wsp_status_code_t *data, gpointer ptr _U_ )
71 wsp_print_statuscode(gint *key, wsp_status_code_t *data, char* format)
73 if (data && (data->packets!=0))
74 printf(format, *key, data->packets ,data->name);
77 wsp_free_hash_table( gpointer key, gpointer value, gpointer user_data _U_ )
83 wspstat_reset(void *psp)
88 for(i=1;i<=sp->num_pdus;i++)
90 sp->pdu_stats[i].packets=0;
92 g_hash_table_foreach( sp->hash, (GHFunc)wsp_reset_hash, NULL);
96 /* This callback is invoked whenever the tap system has seen a packet
97 * we might be interested in.
98 * The function is to be used to only update internal state information
99 * in the *tapdata structure, and if there were state changes which requires
100 * the window to be redrawn, return 1 and (*draw) will be called sometime
103 * We didnt apply a filter when we registered so we will be called for
104 * ALL packets and not just the ones we are collecting stats for.
108 pdut2index(gint pdut)
110 if (pdut<=0x09) return pdut;
114 } else if (pdut==0x60||pdut==0x61){
121 index2pdut(gint pdut)
132 wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
135 const wsp_info_value_t *value=pri;
136 gint index = pdut2index(value->pdut);
139 if (value->status_code != 0) {
140 gint *key=g_malloc( sizeof(gint) );
141 wsp_status_code_t *sc;
142 *key=value->status_code ;
143 sc = g_hash_table_lookup(
147 sc = g_malloc( sizeof(wsp_status_code_t) );
163 sp->pdu_stats[ index ].packets++;
170 /* This callback is used when tethereal wants us to draw/update our
171 * data to the output device. Since this is tethereal only output is
173 * Tethereal will only call this callback once, which is when tethereal has
174 * finished reading all packets and exists.
175 * If used with ethereal this may be called any time, perhaps once every 3
177 * This function may even be called in parallell with (*reset) or (*draw)
178 * so make sure there are no races. The data in the rpcstat_t can thus change
179 * beneath us. Beware.
182 wspstat_draw(void *psp)
188 printf("===================================================================\n");
189 printf("WSP Statistics:\n");
190 printf("%-23s %9s || %-23s %9s\n","PDU Type", "Packets", "PDU Type", "Packets");
191 for(i=1; i<= ((sp->num_pdus+1)/2) ; i++)
193 guint32 ii=i+sp->num_pdus/2;
194 printf("%-23s %9d", sp->pdu_stats[i ].type, sp->pdu_stats[i ].packets);
196 if (ii< (sp->num_pdus) )
197 printf("%-23s %9d\n", sp->pdu_stats[ii].type, sp->pdu_stats[ii].packets);
201 printf("\nStatus code in reply packets\n");
202 printf( "Status Code Packets Description\n");
203 g_hash_table_foreach( sp->hash, (GHFunc) wsp_print_statuscode,
204 " 0x%02X %9d %s\n" ) ;
205 printf("===================================================================\n");
208 /* When called, this function will create a new instance of wspstat.
209 * program and version are whick onc-rpc program/version we want to
210 * collect statistics for.
211 * This function is called from tethereal when it parses the -z wsp, arguments
212 * and it creates a new instance to store statistics in and registers this
213 * new instance for the wsp tap.
216 wspstat_init(const char *optarg)
219 const char *filter=NULL;
221 GString *error_string;
222 wsp_status_code_t *sc;
224 if (!strncmp (optarg, "wsp,stat," , 9)){
231 sp = g_malloc( sizeof(wspstat_t) );
232 sp->hash = g_hash_table_new( g_int_hash, g_int_equal);
233 for (i=0 ; vals_status[i].strptr ; i++ )
236 sc=g_malloc( sizeof(wsp_status_code_t) );
237 key=g_malloc( sizeof(gint) );
239 sc->name=vals_status[i].strptr;
240 *key=vals_status[i].value;
247 sp->pdu_stats=g_malloc( (sp->num_pdus+1) * sizeof( wsp_pdu_t) );
249 sp->filter=g_malloc(strlen(filter)+1);
250 strcpy(sp->filter,filter);
254 for (i=0;i<sp->num_pdus; i++)
256 sp->pdu_stats[i].packets=0;
257 sp->pdu_stats[i].type = match_strval( index2pdut( i ), vals_pdu_type) ;
260 error_string = register_tap_listener(
268 /* error, we failed to attach to the tap. clean up */
269 g_free(sp->pdu_stats);
272 g_hash_table_foreach( sp->hash, (GHFunc) wsp_free_hash_table, NULL ) ;
273 g_hash_table_destroy( sp->hash );
274 fprintf(stderr, "tethereal: Couldn't register wsp,stat tap: %s\n",
276 g_string_free(error_string, TRUE);
281 register_tap_listener_wspstat(void)
283 register_tap_listener_cmd_arg("wsp,stat,", wspstat_init);