- Move setting _U_ into config.h, because
[obnox/wireshark/wip.git] / tap-wspstat.c
index b99061dc01adbea98fddc5f799f5f5971232769b..40bce6cefc203a75a788073085c14ce9b37de472 100644 (file)
@@ -6,24 +6,24 @@
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * 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 WSP  statistics to twireshark.
- * It is only used by twireshark and not wireshark
+/* This module provides WSP  statistics to tshark.
+ * It is only used by tshark and not wireshark
  *
  */
 
@@ -41,7 +41,6 @@
 #include "epan/packet_info.h"
 #include <epan/tap.h>
 #include <epan/stat_cmd_args.h>
-#include "register.h"
 #include "epan/value_string.h"
 #include <epan/dissectors/packet-wsp.h>
 
@@ -50,7 +49,7 @@ typedef struct _wsp_pdu_t {
        const gchar     *type;
        guint32          packets;
 } wsp_pdu_t;
-/* used to keep track of RTT statistics */
+/* used to keep track of SRT statistics */
 typedef struct _wsp_status_code_t {
        const gchar     *name;
        guint32          packets;
@@ -62,10 +61,10 @@ typedef struct _wsp_stats_t {
        guint32 num_pdus;
        GHashTable      *hash;
 } wspstat_t;
-       
+
 static void
-wsp_reset_hash(gchar *key _U_ , wsp_status_code_t *data, gpointer ptr _U_ ) 
-{      
+wsp_reset_hash(gchar *key _U_ , wsp_status_code_t *data, gpointer ptr _U_ )
+{
        data->packets = 0;
 }
 static void
@@ -105,7 +104,7 @@ wspstat_reset(void *psp)
  * ALL packets and not just the ones we are collecting stats for.
  *
  */
-static gint 
+static gint
 pdut2index(gint pdut)
 {
        if (pdut<=0x09)         return pdut;
@@ -134,15 +133,15 @@ wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
 {
        wspstat_t *sp=psp;
        const wsp_info_value_t *value=pri;
-       gint index = pdut2index(value->pdut);
+       gint idx = pdut2index(value->pdut);
        int retour=0;
 
        if (value->status_code != 0) {
                gint *key=g_malloc( sizeof(gint) );
                wsp_status_code_t *sc;
                *key=value->status_code ;
-               sc = g_hash_table_lookup( 
-                               sp->hash, 
+               sc = g_hash_table_lookup(
+                               sp->hash,
                                key);
                if (!sc) {
                        sc = g_malloc( sizeof(wsp_status_code_t) );
@@ -158,22 +157,22 @@ wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const
                retour=1;
        }
 
-               
 
-       if (index!=0) {
-               sp->pdu_stats[ index ].packets++;
+
+       if (idx!=0) {
+               sp->pdu_stats[ idx ].packets++;
                retour = 1;
        }
        return retour;
 }
 
 
-/* This callback is used when twireshark wants us to draw/update our
- * data to the output device. Since this is twireshark only output is
+/* This callback is used when tshark wants us to draw/update our
+ * data to the output device. Since this is tshark only output is
  * stdout.
- * Twireshark will only call this callback once, which is when twireshark has
+ * TShark will only call this callback once, which is when tshark has
  * finished reading all packets and exists.
- * If used with wireshark this may be called any time, perhaps once every 3 
+ * If used with wireshark this may be called any time, perhaps once every 3
  * seconds or so.
  * This function may even be called in parallell with (*reset) or (*draw)
  * so make sure there are no races. The data in the rpcstat_t can thus change
@@ -196,12 +195,12 @@ wspstat_draw(void *psp)
                printf(" || ");
                if (ii< (sp->num_pdus) )
                        printf("%-23s %9d\n", sp->pdu_stats[ii].type, sp->pdu_stats[ii].packets);
-               else 
+               else
                        printf("\n");
                }
        printf("\nStatus code in reply packets\n");
        printf(         "Status Code    Packets  Description\n");
-       g_hash_table_foreach( sp->hash, (GHFunc) wsp_print_statuscode, 
+       g_hash_table_foreach( sp->hash, (GHFunc) wsp_print_statuscode,
                        "       0x%02X  %9d  %s\n" ) ;
        printf("===================================================================\n");
 }
@@ -209,36 +208,38 @@ wspstat_draw(void *psp)
 /* When called, this function will create a new instance of wspstat.
  * program and version are whick onc-rpc program/version we want to
  * collect statistics for.
- * This function is called from twireshark when it parses the -z wsp, arguments
+ * This function is called from tshark when it parses the -z wsp, arguments
  * and it creates a new instance to store statistics in and registers this
  * new instance for the wsp tap.
  */
 static void
 wspstat_init(const char *optarg, void* userdata _U_)
 {
-       wspstat_t *sp;
-       const char *filter=NULL;
-       guint32 i;
-       GString *error_string;
-       wsp_status_code_t *sc;
-       
+       wspstat_t          *sp;
+       const char         *filter=NULL;
+       guint32             i;
+       GString            *error_string;
+       wsp_status_code_t  *sc;
+       const value_string *wsp_vals_status_p;
+
        if (!strncmp (optarg, "wsp,stat," , 9)){
                filter=optarg+9;
        } else {
                filter=NULL;
        }
-       
-               
+
+
        sp = g_malloc( sizeof(wspstat_t) );
        sp->hash = g_hash_table_new( g_int_hash, g_int_equal);
-       for (i=0 ; vals_status[i].strptr ; i++ )
+       wsp_vals_status_p = VALUE_STRING_EXT_VS_P(&wsp_vals_status_ext);
+       for (i=0 ; wsp_vals_status_p[i].strptr ; i++ )
        {
                gint *key;
                sc=g_malloc( sizeof(wsp_status_code_t) );
                key=g_malloc( sizeof(gint) );
                sc->packets=0;
-               sc->name=vals_status[i].strptr;
-               *key=vals_status[i].value;
+               sc->name=wsp_vals_status_p[i].strptr;
+               *key=wsp_vals_status_p[i].value;
                g_hash_table_insert(
                                sp->hash,
                                key,
@@ -247,21 +248,21 @@ wspstat_init(const char *optarg, void* userdata _U_)
        sp->num_pdus = 16;
        sp->pdu_stats=g_malloc( (sp->num_pdus+1) * sizeof( wsp_pdu_t) );
        if(filter){
-               sp->filter=g_malloc(strlen(filter)+1);
-               strcpy(sp->filter,filter);
+               sp->filter=g_strdup(filter);
        } else {
                sp->filter=NULL;
        }
        for (i=0;i<sp->num_pdus; i++)
        {
                sp->pdu_stats[i].packets=0;
-               sp->pdu_stats[i].type = match_strval( index2pdut( i ), vals_pdu_type) ;
+               sp->pdu_stats[i].type = match_strval_ext( index2pdut( i ), &wsp_vals_pdu_type_ext) ;
        }
 
-       error_string = register_tap_listener( 
+       error_string = register_tap_listener(
                        "wsp",
                        sp,
                        filter,
+                       0,
                        wspstat_reset,
                        wspstat_packet,
                        wspstat_draw);
@@ -272,13 +273,13 @@ wspstat_init(const char *optarg, void* userdata _U_)
                g_free(sp);
                g_hash_table_foreach( sp->hash, (GHFunc) wsp_free_hash_table, NULL ) ;
                g_hash_table_destroy( sp->hash );
-               fprintf(stderr, "twireshark: Couldn't register wsp,stat tap: %s\n",
+               fprintf(stderr, "tshark: Couldn't register wsp,stat tap: %s\n",
                                error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
        }
 }
-void 
+void
 register_tap_listener_wspstat(void)
 {
        register_stat_cmd_arg("wsp,stat,", wspstat_init,NULL);