Xcode 4 isn't available on DVD, but is available for download from
[obnox/wireshark/wip.git] / tap-mgcpstat.c
index 6ec9f5ea5eaa28fca0c723648df52f9b0b13fbaf..f5b0b1ee7995aefe9e01c1a9a3e8a023403783bf 100644 (file)
@@ -1,10 +1,10 @@
 /* tap-mgcpstat.c
  * mgcpstat   2003 Lars Roland
  *
- * $Id: tap-mgcpstat.c,v 1.4 2003/04/16 07:24:04 guy Exp $
+ * $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
 
 #include <string.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 "plugins/mgcp/packet-mgcp.h"
+#include "epan/dissectors/packet-mgcp.h"
 #include "timestats.h"
 
 #define NUM_TIMESTATS 11
@@ -63,14 +63,16 @@ static const value_string mgcp_mesage_type[] = {
   {  7,        "AUEP   "},
   {  8, "AUCX   "},
   {  9, "RSIP   "},
+  {  0, NULL}
 };
 
 static int
-mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, void *pmi)
+mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
 {
        mgcpstat_t *ms=(mgcpstat_t *)pms;
-       mgcp_info_t *mi=pmi;
+       const mgcp_info_t *mi=pmi;
        nstime_t delta;
+       int ret = 0;
 
        switch (mi->mgcp_type) {
 
@@ -78,76 +80,68 @@ mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, void *pm
                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
@@ -181,24 +175,19 @@ mgcpstat_draw(void *pms)
 
 
 static void
-mgcpstat_init(char *optarg)
+mgcpstat_init(const char *optarg, void* userdata _U_)
 {
        mgcpstat_t *ms;
        int i;
-       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=g_malloc(1);
-               *filter='\0';
+               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,12 +205,15 @@ mgcpstat_init(char *optarg)
        ms->req_dup_num=0;
        ms->rsp_dup_num=0;
 
-       if(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: mgcpstat_init() failed to attach to tap.\n");
+               fprintf(stderr, "tshark: Couldn't register mgcp,rtd tap: %s\n",
+                   error_string->str);
+               g_string_free(error_string, TRUE);
                exit(1);
        }
 }
@@ -230,6 +222,9 @@ mgcpstat_init(char *optarg)
 void
 register_tap_listener_mgcpstat(void)
 {
-       register_ethereal_tap("mgcp,rtd", mgcpstat_init, NULL, NULL);
+       /* 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, NULL);
+       }
 }