Ethereal->Wireshark
[obnox/wireshark/wip.git] / tap-sipstat.c
index 715247d1f7959a6b372c6be39f1209aefcbb263d..df24c452b28636a0d06f842a00189d7d43960e89 100644 (file)
@@ -1,11 +1,11 @@
 /* tap_sipstat.c
  * sip message counter for ethereal
  *
- * $Id: tap-sipstat.c,v 1.1 2004/03/30 18:55:46 guy Exp $
+ * $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
 
 #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 "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;
        GHashTable      *hash_responses;
        GHashTable      *hash_requests;
 } sipstat_t;
@@ -53,7 +56,7 @@ typedef struct _sip_stats_t {
 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;
 
@@ -94,6 +97,7 @@ static const value_string vals_status_code[] = {
     { 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"},
@@ -205,6 +209,8 @@ sipstat_reset(void *psp  )
 {
        sipstat_t *sp=psp;
        if (sp) {
+               sp->packets = 0;
+               sp->resent_packets = 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);
        }
@@ -213,11 +219,21 @@ sipstat_reset(void *psp  )
 
 /* 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++;
+    
+    /* Update resent count if flag set */
+    if (value->resend)
+    {
+        sp->resent_packets++;
+    }
 
+    
     /* Looking at both requests and responses */
     if (value->response_code != 0)
     {
@@ -318,6 +334,8 @@ sipstat_draw(void *psp  )
        else
                printf("SIP Statistics with filter %s\n", sp->filter);
 
+       printf("\nNumber of SIP messages: %d", sp->packets);
+       printf("\nNumber of resent SIP messages: %d\n", sp->resent_packets);
        printf( "\n* SIP Status Codes in reply packets\n");
        g_hash_table_foreach( sp->hash_responses, (GHFunc)sip_draw_hash_responses,
                "  SIP %3d %-15s : %5d Packets\n");
@@ -328,10 +346,10 @@ sipstat_draw(void *psp  )
 }
 
 static void
-sipstat_init(char *optarg)
+sipstat_init(const char *optarg, void* userdata _U_)
 {
        sipstat_t *sp;
-       char *filter=NULL;
+       const char *filter=NULL;
        GString *error_string;
 
        if (strncmp (optarg, "sip,stat,", 9) == 0){
@@ -360,17 +378,19 @@ sipstat_init(char *optarg)
                /* 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, "tethereal: Couldn't register sip,stat tap: %s\n",
                                error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
        }
 
+       sp->packets = 0;
+       sp->resent_packets = 0;
        sip_init_hash(sp);
 }
 
 void
 register_tap_listener_sipstat(void)
 {
-       register_ethereal_tap("sip,stat", sipstat_init);
+       register_stat_cmd_arg("sip,stat", sipstat_init,NULL);
 }