Xcode 4 isn't available on DVD, but is available for download from
[obnox/wireshark/wip.git] / tap-mgcpstat.c
index acd1980ae1d4b69ea6f716c8684c686f8c215b72..f5b0b1ee7995aefe9e01c1a9a3e8a023403783bf 100644 (file)
@@ -3,8 +3,8 @@
  *
  * $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
@@ -37,8 +37,7 @@
 #include <epan/tap.h>
 #include <epan/stat_cmd_args.h>
 #include "epan/value_string.h"
-#include "register.h"
-#include "plugins/mgcp/packet-mgcp.h"
+#include "epan/dissectors/packet-mgcp.h"
 #include "timestats.h"
 
 #define NUM_TIMESTATS 11
@@ -64,6 +63,7 @@ static const value_string mgcp_mesage_type[] = {
   {  7,        "AUEP   "},
   {  8, "AUCX   "},
   {  9, "RSIP   "},
+  {  0, NULL}
 };
 
 static int
@@ -72,6 +72,7 @@ mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const vo
        mgcpstat_t *ms=(mgcpstat_t *)pms;
        const mgcp_info_t *mi=pmi;
        nstime_t delta;
+       int ret = 0;
 
        switch (mi->mgcp_type) {
 
@@ -79,76 +80,68 @@ mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const vo
                if(mi->is_duplicate){
                        /* Duplicate is ignored */
                        ms->req_dup_num++;
-                       return 0;
                }
                else {
                        ms->open_req_num++;
-                       return 0;
                }
-       break;
+               break;
 
        case MGCP_RESPONSE:
                if(mi->is_duplicate){
                        /* Duplicate is ignored */
                        ms->rsp_dup_num++;
-                       return 0;
                }
                else if (!mi->request_available) {
                        /* no request was seen */
                        ms->disc_rsp_num++;
-                       return 0;
                }
                else {
                        ms->open_req_num--;
                        /* calculate time delta between request and response */
-                       delta.secs=pinfo->fd->abs_secs-mi->req_time.secs;
-                       delta.nsecs=pinfo->fd->abs_usecs*1000-mi->req_time.nsecs;
-                       if(delta.nsecs<0){
-                               delta.nsecs+=1000000000;
-                               delta.secs--;
-                       }
+                       nstime_delta(&delta, &pinfo->fd->abs_ts, &mi->req_time);
 
                        time_stat_update(&(ms->rtd[0]),&delta, pinfo);
 
-                       if (strncasecmp(mi->code, "EPCF", 4) == 0 ) {
+                       if (g_ascii_strncasecmp(mi->code, "EPCF", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[1]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "CRCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "CRCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[2]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "MDCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "MDCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[3]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "DLCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "DLCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[4]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "RQNT", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "RQNT", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[5]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "NTFY", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "NTFY", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[6]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "AUEP", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "AUEP", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[7]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "AUCX", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "AUCX", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[8]),&delta, pinfo);
                        }
-                       else if (strncasecmp(mi->code, "RSIP", 4) == 0 ) {
+                       else if (g_ascii_strncasecmp(mi->code, "RSIP", 4) == 0 ) {
                                time_stat_update(&(ms->rtd[9]),&delta, pinfo);
                        }
                        else {
                                time_stat_update(&(ms->rtd[10]),&delta, pinfo);
                        }
 
-                       return 1;
+                       ret = 1;
                }
-       break;
+               break;
 
        default:
-               return 0;
-       break;
+               break;
        }
+
+       return ret;
 }
 
 static void
@@ -182,23 +175,19 @@ mgcpstat_draw(void *pms)
 
 
 static void
-mgcpstat_init(const char *optarg)
+mgcpstat_init(const char *optarg, void* userdata _U_)
 {
        mgcpstat_t *ms;
        int i;
-       const char *filter=NULL;
        GString *error_string;
 
+       ms=g_malloc(sizeof(mgcpstat_t));
        if(!strncmp(optarg,"mgcp,rtd,",9)){
-               filter=optarg+9;
+               ms->filter=g_strdup(optarg+9);
        } else {
-               filter="";
+               ms->filter=NULL;
        }
 
-       ms=g_malloc(sizeof(mgcpstat_t));
-       ms->filter=g_malloc(strlen(filter)+1);
-       strcpy(ms->filter, filter);
-
        for(i=0;i<NUM_TIMESTATS;i++) {
                ms->rtd[i].num=0;
                ms->rtd[i].min_num=0;
@@ -216,13 +205,13 @@ mgcpstat_init(const char *optarg)
        ms->req_dup_num=0;
        ms->rsp_dup_num=0;
 
-       error_string=register_tap_listener("mgcp", ms, filter, NULL, mgcpstat_packet, mgcpstat_draw);
+       error_string=register_tap_listener("mgcp", ms, ms->filter, 0, NULL, mgcpstat_packet, mgcpstat_draw);
        if(error_string){
                /* error, we failed to attach to the tap. clean up */
                g_free(ms->filter);
                g_free(ms);
 
-               fprintf(stderr, "tethereal: Couldn't register mgcp,rtd tap: %s\n",
+               fprintf(stderr, "tshark: Couldn't register mgcp,rtd tap: %s\n",
                    error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
@@ -235,7 +224,7 @@ register_tap_listener_mgcpstat(void)
 {
        /* We don't register this tap, if we don't have the mgcp plugin loaded.*/
        if (find_tap_id("mgcp")) {
-               register_stat_cmd_arg("mgcp,rtd", mgcpstat_init);
+               register_stat_cmd_arg("mgcp,rtd", mgcpstat_init, NULL);
        }
 }