Update to V9.0.0 (2009-12)
[obnox/wireshark/wip.git] / tap-sipstat.c
index fb517e6b1f74b052eb47f0059ef81eb5ed6fb7b3..e3b281c93875ab30633cf377530463f4494a5e5c 100644 (file)
@@ -1,11 +1,11 @@
 /* tap_sipstat.c
 /* tap_sipstat.c
- * sip message counter for ethereal
+ * sip message counter for wireshark
  *
  * $Id$
  * Copied from gtk/sip_stat.c and tap-httpstat.c
  *
  *
  * $Id$
  * Copied from gtk/sip_stat.c and tap-httpstat.c
  *
- * 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
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
 
 #include <string.h>
 #include "epan/packet_info.h"
 
 #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 "epan/value_string.h"
 #include "register.h"
-#include "packet-sip.h"
+#include <epan/dissectors/packet-sip.h>
 
 /* used to keep track of the statictics for an entire program interface */
 typedef struct _sip_stats_t {
        char            *filter;
        guint32         packets;        /* number of sip packets, including continuations */
        guint32         resent_packets;
 
 /* used to keep track of the statictics for an entire program interface */
 typedef struct _sip_stats_t {
        char            *filter;
        guint32         packets;        /* number of sip packets, including continuations */
        guint32         resent_packets;
+       guint32         average_setup_time;
+       guint32         max_setup_time;
+       guint32         min_setup_time;
+       guint32         no_of_completed_calls;
+       guint64         total_setup_time;
        GHashTable      *hash_responses;
        GHashTable      *hash_requests;
 } sipstat_t;
        GHashTable      *hash_responses;
        GHashTable      *hash_requests;
 } sipstat_t;
@@ -55,7 +61,7 @@ typedef struct _sip_stats_t {
 typedef struct _sip_response_code_t {
        guint32          packets;               /* 3 */
        guint            response_code;         /* 404 */
 typedef struct _sip_response_code_t {
        guint32          packets;               /* 3 */
        guint            response_code;         /* 404 */
-       gchar           *name;                  /* Not Found */
+       const gchar     *name;                  /* Not Found */
        sipstat_t       *sp;
 } sip_response_code_t;
 
        sipstat_t       *sp;
 } sip_response_code_t;
 
@@ -96,13 +102,16 @@ static const value_string vals_status_code[] = {
     { 407, "Proxy Authentication Required"},
     { 408, "Request Timeout"},
     { 410, "Gone"},
     { 407, "Proxy Authentication Required"},
     { 408, "Request Timeout"},
     { 410, "Gone"},
+    { 412, "Conditional Request Failed"},
     { 413, "Request Entity Too Large"},
     { 414, "Request-URI Too Long"},
     { 415, "Unsupported Media Type"},
     { 416, "Unsupported URI Scheme"},
     { 420, "Bad Extension"},
     { 421, "Extension Required"},
     { 413, "Request Entity Too Large"},
     { 414, "Request-URI Too Long"},
     { 415, "Unsupported Media Type"},
     { 416, "Unsupported URI Scheme"},
     { 420, "Bad Extension"},
     { 421, "Extension Required"},
+    { 422, "Session Timer Too Small"},
     { 423, "Interval Too Brief"},
     { 423, "Interval Too Brief"},
+    { 429, "Provide Referrer Identity"},
     { 480, "Temporarily Unavailable"},
     { 481, "Call/Transaction Does Not Exist"},
     { 482, "Loop Detected"},
     { 480, "Temporarily Unavailable"},
     { 481, "Call/Transaction Does Not Exist"},
     { 482, "Loop Detected"},
@@ -115,6 +124,7 @@ static const value_string vals_status_code[] = {
     { 489, "Bad Event"},
     { 491, "Request Pending"},
     { 493, "Undecipherable"},
     { 489, "Bad Event"},
     { 491, "Request Pending"},
     { 493, "Undecipherable"},
+    { 494, "Security Agreement Required"},
     { 499, "Client Error - Others"},
 
     { 500, "Server Internal Error"},
     { 499, "Client Error - Others"},
 
     { 500, "Server Internal Error"},
@@ -209,6 +219,12 @@ sipstat_reset(void *psp  )
        if (sp) {
                sp->packets = 0;
                sp->resent_packets = 0;
        if (sp) {
                sp->packets = 0;
                sp->resent_packets = 0;
+               sp->average_setup_time = 0;
+               sp->max_setup_time = 0;
+               sp->min_setup_time = 0;
+               sp->no_of_completed_calls = 0;
+               sp->total_setup_time = 0;
+
                g_hash_table_foreach( sp->hash_responses, (GHFunc)sip_reset_hash_responses, NULL);
                g_hash_table_foreach( sp->hash_requests, (GHFunc)sip_reset_hash_requests, NULL);
        }
                g_hash_table_foreach( sp->hash_responses, (GHFunc)sip_reset_hash_responses, NULL);
                g_hash_table_foreach( sp->hash_requests, (GHFunc)sip_reset_hash_requests, NULL);
        }
@@ -217,13 +233,35 @@ sipstat_reset(void *psp  )
 
 /* Main entry point to SIP tap */
 static int
 
 /* Main entry point to SIP tap */
 static int
-sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *pri)
+sipstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
 {
 {
-    sip_info_value_t *value=pri;
+    const sip_info_value_t *value=pri;
     sipstat_t *sp = (sipstat_t *)psp;
     
     /* Total number of packets, including continuation packets */
     sp->packets++;
     sipstat_t *sp = (sipstat_t *)psp;
     
     /* Total number of packets, including continuation packets */
     sp->packets++;
+
+       /* Calculate average setup time */
+       if (value->setup_time){
+               sp->no_of_completed_calls++;
+               /* Check if it's the first value */
+               if ( sp->total_setup_time == 0 ){
+                       sp->average_setup_time = value->setup_time;
+                       sp->total_setup_time = value->setup_time;
+                       sp->max_setup_time = value->setup_time;
+                       sp->min_setup_time = value->setup_time;
+               }else{
+                       sp->total_setup_time = sp->total_setup_time + value->setup_time;
+                       if (sp->max_setup_time < value->setup_time){
+                               sp->max_setup_time = value->setup_time;
+                       }
+                       if (sp->min_setup_time > value->setup_time){
+                               sp->min_setup_time = value->setup_time;
+                       }
+                       /* Calculate average */
+                       sp->average_setup_time = (guint32)(sp->total_setup_time / sp->no_of_completed_calls); 
+               }
+       }
     
     /* Update resent count if flag set */
     if (value->resend)
     
     /* Update resent count if flag set */
     if (value->resend)
@@ -340,14 +378,15 @@ sipstat_draw(void *psp  )
        printf("\n* List of SIP Request methods\n");
        g_hash_table_foreach( sp->hash_requests,  (GHFunc)sip_draw_hash_requests,
                "  %-15s : %5d Packets\n");
        printf("\n* List of SIP Request methods\n");
        g_hash_table_foreach( sp->hash_requests,  (GHFunc)sip_draw_hash_requests,
                "  %-15s : %5d Packets\n");
+       printf( "\n* Average setup time %d ms\n Min %d ms\n Max %d ms\n", sp->average_setup_time, sp->min_setup_time, sp->max_setup_time);
        printf("===================================================================\n");
 }
 
 static void
        printf("===================================================================\n");
 }
 
 static void
-sipstat_init(char *optarg)
+sipstat_init(const char *optarg, void* userdata _U_)
 {
        sipstat_t *sp;
 {
        sipstat_t *sp;
-       char *filter=NULL;
+       const char *filter=NULL;
        GString *error_string;
 
        if (strncmp (optarg, "sip,stat,", 9) == 0){
        GString *error_string;
 
        if (strncmp (optarg, "sip,stat,", 9) == 0){
@@ -369,6 +408,7 @@ sipstat_init(char *optarg)
                        "sip",
                        sp,
                        filter,
                        "sip",
                        sp,
                        filter,
+                       0,
                        sipstat_reset,
                        sipstat_packet,
                        sipstat_draw);
                        sipstat_reset,
                        sipstat_packet,
                        sipstat_draw);
@@ -376,7 +416,7 @@ sipstat_init(char *optarg)
                /* error, we failed to attach to the tap. clean up */
                g_free(sp->filter);
                g_free(sp);
                /* error, we failed to attach to the tap. clean up */
                g_free(sp->filter);
                g_free(sp);
-               fprintf (stderr, "tethereal: Coulnd't register sip,stat tap: %s\n",
+               fprintf (stderr, "tshark: Couldn't register sip,stat tap: %s\n",
                                error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
                                error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
@@ -390,5 +430,5 @@ sipstat_init(char *optarg)
 void
 register_tap_listener_sipstat(void)
 {
 void
 register_tap_listener_sipstat(void)
 {
-       register_ethereal_tap("sip,stat", sipstat_init);
+       register_stat_cmd_arg("sip,stat", sipstat_init,NULL);
 }
 }