cd ../gtk ==> cd ../ui/gtk
[obnox/wireshark/wip.git] / tap-h225counter.c
index c9ed94d9eeb16f6658001b38dca1e2ddbf21370b..6076f1c22534ff43a95d5389fd37eedc9755a354 100644 (file)
@@ -1,11 +1,11 @@
 /* tap_h225counter.c
- * h225 message counter for ethereal
+ * h225 message counter for wireshark
  * Copyright 2003 Lars Roland
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * 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
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-/* With MSVC and a libethereal.dll this file needs to import some variables 
-   in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */  
-#define _NEED_VAR_IMPORT_
-
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 #endif
 
 #include <string.h>
+#include "epan/packet.h"
 #include "epan/packet_info.h"
-#include "tap.h"
+#include <epan/tap.h>
+#include <epan/stat_cmd_args.h>
 #include "epan/value_string.h"
-#include "register.h"
-#include "packet-h225.h"
+#include <epan/dissectors/packet-h225.h>
 
 /* following values represent the size of their valuestring arrays */
 
@@ -87,57 +84,18 @@ static void
 h225counter_reset(void *phs)
 {
        h225counter_t *hs=(h225counter_t *)phs;
-       int i;
+       char *save_filter = hs->filter;
 
-       for(i=0;i<=RAS_MSG_TYPES;i++) {
-               hs->ras_msg[i] = 0;
-       }
-       for(i=0;i<=CS_MSG_TYPES;i++) {
-               hs->cs_msg[i] = 0;
-       }
-       for(i=0;i<=GRJ_REASONS;i++) {
-               hs->grj_reason[i] = 0;
-       }
-       for(i=0;i<=RRJ_REASONS;i++) {
-               hs->rrj_reason[i] = 0;
-       }
-       for(i=0;i<=URQ_REASONS;i++) {
-               hs->urq_reason[i] = 0;
-       }
-       for(i=0;i<=URJ_REASONS;i++) {
-               hs->urj_reason[i] = 0;
-       }
-       for(i=0;i<=ARJ_REASONS;i++) {
-               hs->arj_reason[i] = 0;
-       }
-       for(i=0;i<=BRJ_REASONS;i++) {
-               hs->brj_reason[i] = 0;
-       }
-       for(i=0;i<=DRQ_REASONS;i++) {
-               hs->drq_reason[i] = 0;
-       }
-       for(i=0;i<=DRJ_REASONS;i++) {
-               hs->drj_reason[i] = 0;
-       }
-       for(i=0;i<=LRJ_REASONS;i++) {
-               hs->lrj_reason[i] = 0;
-       }
-       for(i=0;i<=IRQNAK_REASONS;i++) {
-               hs->irqnak_reason[i] = 0;
-       }
-       for(i=0;i<=REL_CMP_REASONS;i++) {
-               hs->rel_cmp_reason[i] = 0;
-       }
-       for(i=0;i<=FACILITY_REASONS;i++) {
-               hs->facility_reason[i] = 0;
-       }
+       memset(hs, 0, sizeof(h225counter_t));
+
+       hs->filter = save_filter;
 }
 
 static int
-h225counter_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *phi)
+h225counter_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *phi)
 {
        h225counter_t *hs=(h225counter_t *)phs;
-       h225_packet_info *pi=phi;
+       const h225_packet_info *pi=phi;
 
        switch (pi->msg_type) {
 
@@ -266,7 +224,6 @@ h225counter_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, v
 
        default:
                return 0;
-               break;
        }
 
        return 1;
@@ -283,7 +240,7 @@ h225counter_draw(void *phs)
        printf("RAS-Messages:\n");
        for(i=0;i<=RAS_MSG_TYPES;i++) {
                if(hs->ras_msg[i]!=0) {
-                       printf("  %s : %u\n", val_to_str(i,RasMessage_vals,"unknown ras-messages  "), hs->ras_msg[i]);
+                       printf("  %s : %u\n", val_to_str(i,h225_RasMessage_vals,"unknown ras-messages  "), hs->ras_msg[i]);
                        /* reason counter */
                        switch(i) {
                        case 2: /* GRJ */
@@ -348,6 +305,7 @@ h225counter_draw(void *phs)
                                                printf("    %s : %u\n", val_to_str(j,LocationRejectReason_vals,"unknown reason   "), hs->lrj_reason[j]);
                                        }
                                }
+                               break;
                        case 29: /* IRQNak */
                                for(j=0;j<=IRQNAK_REASONS;j++) {
                                        if(hs->irqnak_reason[j]!=0) {
@@ -364,13 +322,13 @@ h225counter_draw(void *phs)
        printf("Call Signalling:\n");
        for(i=0;i<=CS_MSG_TYPES;i++) {
                if(hs->cs_msg[i]!=0) {
-                       printf("  %s : %u\n", val_to_str(i,h323_message_body_vals,"unknown cs-messages   "), hs->cs_msg[i]);
+                       printf("  %s : %u\n", val_to_str(i,T_h323_message_body_vals,"unknown cs-messages   "), hs->cs_msg[i]);
                        /* reason counter */
                        switch(i) {
                        case 5: /* ReleaseComplete */
                                for(j=0;j<=REL_CMP_REASONS;j++) {
                                        if(hs->rel_cmp_reason[j]!=0) {
-                                               printf("    %s : %u\n", val_to_str(j,ReleaseCompleteReason_vals,"unknown reason   "), hs->rel_cmp_reason[j]);
+                                               printf("    %s : %u\n", val_to_str(j,h225_ReleaseCompleteReason_vals,"unknown reason   "), hs->rel_cmp_reason[j]);
                                        }
                                }
                                break;
@@ -391,32 +349,27 @@ h225counter_draw(void *phs)
 
 
 static void
-h225counter_init(char *optarg)
+h225counter_init(const char *optarg, void* userdata _U_)
 {
        h225counter_t *hs;
-       char *filter=NULL;
        GString *error_string;
 
+       hs = g_malloc(sizeof(h225counter_t));
        if(!strncmp(optarg,"h225,counter,",13)){
-               filter=optarg+13;
+               hs->filter=g_strdup(optarg+13);
        } else {
-               filter=g_malloc(1);
-               *filter='\0';
+               hs->filter=NULL;
        }
 
-       hs = g_malloc(sizeof(h225counter_t));
-       hs->filter=g_malloc(strlen(filter)+1);
-       strcpy(hs->filter, filter);
-
        h225counter_reset(hs);
 
-       error_string=register_tap_listener("h225", hs, filter, NULL, h225counter_packet, h225counter_draw);
+       error_string=register_tap_listener("h225", hs, hs->filter, 0, NULL, h225counter_packet, h225counter_draw);
        if(error_string){
                /* error, we failed to attach to the tap. clean up */
                g_free(hs->filter);
                g_free(hs);
 
-               fprintf(stderr, "tethereal: Couldn't register h225,counter tap: %s\n",
+               fprintf(stderr, "tshark: Couldn't register h225,counter tap: %s\n",
                    error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
@@ -427,5 +380,5 @@ h225counter_init(char *optarg)
 void
 register_tap_listener_h225counter(void)
 {
-       register_ethereal_tap("h225,counter", h225counter_init);
+       register_stat_cmd_arg("h225,counter", h225counter_init,NULL);
 }