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
30 /* With MSVC and a libethereal.dll this file needs to import some variables
31 in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */
32 #define _NEED_VAR_IMPORT_
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
45 #include "epan/packet_info.h"
48 #include "epan/value_string.h"
49 #include <epan/dissectors/packet-wsp.h>
51 /* used to keep track of the stats for a specific PDU type*/
52 typedef struct _wsp_pdu_t {
56 /* used to keep track of RTT statistics */
57 typedef struct _wsp_status_code_t {
61 /* used to keep track of the statictics for an entire program interface */
62 typedef struct _wsp_stats_t {
70 wsp_reset_hash(gchar *key _U_ , wsp_status_code_t *data, gpointer ptr _U_ )
75 wsp_print_statuscode(gint *key, wsp_status_code_t *data, char* format)
77 if (data && (data->packets!=0))
78 printf(format, *key, data->packets ,data->name);
81 wsp_free_hash_table( gpointer key, gpointer value, gpointer user_data _U_ )
87 wspstat_reset(void *psp)
92 for(i=1;i<=sp->num_pdus;i++)
94 sp->pdu_stats[i].packets=0;
96 g_hash_table_foreach( sp->hash, (GHFunc)wsp_reset_hash, NULL);
100 /* This callback is invoked whenever the tap system has seen a packet
101 * we might be interested in.
102 * The function is to be used to only update internal state information
103 * in the *tapdata structure, and if there were state changes which requires
104 * the window to be redrawn, return 1 and (*draw) will be called sometime
107 * We didnt apply a filter when we registered so we will be called for
108 * ALL packets and not just the ones we are collecting stats for.
112 pdut2index(gint pdut)
114 if (pdut<=0x09) return pdut;
118 } else if (pdut==0x60||pdut==0x61){
125 index2pdut(gint pdut)
136 wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *pri)
139 wsp_info_value_t *value=pri;
140 gint index = pdut2index(value->pdut);
143 if (value->status_code != 0) {
144 gint *key=g_malloc( sizeof(gint) );
145 wsp_status_code_t *sc;
146 *key=value->status_code ;
147 sc = g_hash_table_lookup(
151 sc = g_malloc( sizeof(wsp_status_code_t) );
167 sp->pdu_stats[ index ].packets++;
174 /* This callback is used when tethereal wants us to draw/update our
175 * data to the output device. Since this is tethereal only output is
177 * Tethereal will only call this callback once, which is when tethereal has
178 * finished reading all packets and exists.
179 * If used with ethereal this may be called any time, perhaps once every 3
181 * This function may even be called in parallell with (*reset) or (*draw)
182 * so make sure there are no races. The data in the rpcstat_t can thus change
183 * beneath us. Beware.
186 wspstat_draw(void *psp)
192 printf("===================================================================\n");
193 printf("WSP Statistics:\n");
194 printf("%-23s %9s || %-23s %9s\n","PDU Type", "Packets", "PDU Type", "Packets");
195 for(i=1; i<= ((sp->num_pdus+1)/2) ; i++)
197 guint32 ii=i+sp->num_pdus/2;
198 printf("%-23s %9d", sp->pdu_stats[i ].type, sp->pdu_stats[i ].packets);
200 if (ii< (sp->num_pdus) )
201 printf("%-23s %9d\n", sp->pdu_stats[ii].type, sp->pdu_stats[ii].packets);
205 printf("\nStatus code in reply packets\n");
206 printf( "Status Code Packets Description\n");
207 g_hash_table_foreach( sp->hash, (GHFunc) wsp_print_statuscode,
208 " 0x%02X %9d %s\n" ) ;
209 printf("===================================================================\n");
212 /* When called, this function will create a new instance of wspstat.
213 * program and version are whick onc-rpc program/version we want to
214 * collect statistics for.
215 * This function is called from tethereal when it parses the -z wsp, arguments
216 * and it creates a new instance to store statistics in and registers this
217 * new instance for the wsp tap.
220 wspstat_init(char *optarg)
225 GString *error_string;
226 wsp_status_code_t *sc;
228 if (!strncmp (optarg, "wsp,stat," , 9)){
235 sp = g_malloc( sizeof(wspstat_t) );
236 sp->hash = g_hash_table_new( g_int_hash, g_int_equal);
237 for (i=0 ; vals_status[i].strptr ; i++ )
240 sc=g_malloc( sizeof(wsp_status_code_t) );
241 key=g_malloc( sizeof(gint) );
243 sc->name=vals_status[i].strptr;
244 *key=vals_status[i].value;
251 sp->pdu_stats=g_malloc( (sp->num_pdus+1) * sizeof( wsp_pdu_t) );
253 sp->filter=g_malloc(strlen(filter)+1);
254 strcpy(sp->filter,filter);
258 for (i=0;i<sp->num_pdus; i++)
260 sp->pdu_stats[i].packets=0;
261 sp->pdu_stats[i].type = match_strval( index2pdut( i ), vals_pdu_type) ;
264 error_string = register_tap_listener(
272 /* error, we failed to attach to the tap. clean up */
273 g_free(sp->pdu_stats);
276 g_hash_table_foreach( sp->hash, (GHFunc) wsp_free_hash_table, NULL ) ;
277 g_hash_table_destroy( sp->hash );
278 fprintf(stderr, "tethereal: Couldn't register wsp,stat tap: %s\n",
280 g_string_free(error_string, TRUE);
285 register_tap_listener_wspstat(void)
287 register_ethereal_tap("wsp,stat,", wspstat_init);