From Tom Brezinski:
[obnox/wireshark/wip.git] / tap-camelsrt.c
index 85b634a558ea5c5d2b07b7c263213c6ea7d69d4f..d4c16589ec16f0b2e370187afcdbc242fb2ff515 100644 (file)
@@ -2,6 +2,8 @@
  * CAMEL Service Response Time statistics for tshark
  * Copyright 2006 Florent Drouin (based on tap_h225rassrt.c from Lars Roland)
  *
+ * $Id$
+ *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
 #endif
 
 #include <string.h>
+#include "epan/packet.h"
 #include "epan/packet_info.h"
 #include <epan/tap.h>
 #include "epan/value_string.h"
-#include "register.h"
+#include "epan/asn1.h"
 #include "epan/dissectors/packet-camel.h"
 #include "epan/camel-persistentdata.h"
 #include "timestats.h"
 #include "epan/stat_cmd_args.h"
 
-#undef  MIN
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
 
 void register_tap_listener_camelsrt(void);
 
@@ -60,12 +61,6 @@ struct camelsrt_t {
   nstime_t delta_time[NB_CAMELSRT_CATEGORY][NUM_RAS_STATS];
 };
 
-/* Check if we have to inhibit the display or not 
- * cannot be static because it's exported in libwireshark.def
- */
-gboolean gcamel_StatSRT;
-gboolean gtcap_StatSRT;
-
 /* Reset the counter */
 static void camelsrt_reset(void *phs)
 {
@@ -74,8 +69,8 @@ static void camelsrt_reset(void *phs)
 }
 
 
-static int camelsrt_packet(void *phs, 
-                          packet_info *pinfo _U_, 
+static int camelsrt_packet(void *phs,
+                          packet_info *pinfo _U_,
                           epan_dissect_t *edt _U_,
                           const void *phi)
 {
@@ -85,16 +80,16 @@ static int camelsrt_packet(void *phs,
 
   for (i=0; i<NB_CAMELSRT_CATEGORY; i++) {
     if (pi->bool_msginfo[i] &&
-       pi->msginfo[i].is_delta_time 
+       pi->msginfo[i].is_delta_time
        && pi->msginfo[i].request_available
        && !pi->msginfo[i].is_duplicate ) {
-      
+
       time_stat_update(&(hs->stats[i]),
                       &(pi->msginfo[i].delta_time),
                       pinfo);
-       
+
       if (hs->count[i] < NUM_RAS_STATS) {
-       hs->delta_time[i][hs->count[i]++] 
+       hs->delta_time[i][hs->count[i]++]
          = pi->msginfo[i].delta_time;
       }
     }
@@ -119,7 +114,7 @@ static void camelsrt_draw(void *phs)
   printf("=================================================================================================\n");
   printf("|        Category         | Measure |  Min SRT  |  Max SRT  |  Avg SRT  | Min frame | Max frame |\n");
   printf("|-------------------------|---------|-----------|-----------|-----------|-----------|-----------|\n");
+
   j=1;
   printf("|%24s |%8u |%8.2f s |%8.2f s |%8.2f s |%10u |%10u |\n",
         val_to_str(j,camelSRTtype_naming,"Unknown Message 0x%02x"),
@@ -127,27 +122,27 @@ static void camelsrt_draw(void *phs)
         nstime_to_sec(&(hs->stats[j].min)),
         nstime_to_sec(&(hs->stats[j].max)),
         get_average(&(hs->stats[j].tot),hs->stats[j].num)/1000.0,
-        hs->stats[j].min_num, 
+        hs->stats[j].min_num,
         hs->stats[j].max_num
         );
-  for(j=2; j<NB_CAMELSRT_CATEGORY; j++) { 
-    if(hs->stats[j].num==0){ 
+  for(j=2; j<NB_CAMELSRT_CATEGORY; j++) {
+    if(hs->stats[j].num==0){
       printf("|%24s |%8u |%8.2f ms|%8.2f ms|%8.2f ms|%10u |%10u |\n",
             val_to_str(j,camelSRTtype_naming,"Unknown Message 0x%02x"),
             0, 0.0, 0.0, 0.0, 0, 0);
       continue;
     }
-    
+
     printf("|%24s |%8u |%8.2f ms|%8.2f ms|%8.2f ms|%10u |%10u |\n",
           val_to_str(j,camelSRTtype_naming,"Unknown Message 0x%02x"),
           hs->stats[j].num,
           MIN(9999,nstime_to_msec(&(hs->stats[j].min))),
           MIN(9999,nstime_to_msec(&(hs->stats[j].max))),
           MIN(9999,get_average(&(hs->stats[j].tot),hs->stats[j].num)),
-          hs->stats[j].min_num, 
+          hs->stats[j].min_num,
           hs->stats[j].max_num
           );
-  } /* j category */ 
+  } /* j category */
 
   printf("=================================================================================================\n");
   /*
@@ -163,10 +158,10 @@ static void camelsrt_draw(void *phs)
   printf("\n");
   /* calculate the delay max to have a given number of messages (in percentage) */
   for(j=2;j<NB_CAMELSRT_CATEGORY;j++) {
-    
+
     rtd_temp = &(hs->stats[j]);
-    
-    if (hs->count[j]>0) { 
+
+    if (hs->count[j]>0) {
       /* Calculate the delay to answer to p% of the MS */
       for(z=0; z<NB_CRITERIA; z++) {
        iteration=0;
@@ -177,9 +172,9 @@ static void camelsrt_draw(void *phs)
        while( (delta > 0.001) && (iteration < 10000) ) {
          somme=0;
          iteration++;
-         
+
          for(li=0;li<hs->count[j];li++) {
-           x=hs->delta_time[j][li].secs*1000 
+           x=hs->delta_time[j][li].secs*1000
              + (double)hs->delta_time[j][li].nsecs/1000000;
            if (x <= delay) somme++;
          }
@@ -199,12 +194,12 @@ static void camelsrt_draw(void *phs)
       printf("X%24s |", val_to_str(j, camelSRTtype_naming, "Unknown") );
       for(z=0; z<NB_CRITERIA; z++) printf("%8.2f |", MIN(9999,delay_criteria[z]));
       printf("\n");
-    } else { /* count */ 
+    } else { /* count */
       printf("X%24s |", val_to_str(j, camelSRTtype_naming, "Unknown") );
       for(z=0; z<NB_CRITERIA; z++) printf("%8.2f |", 0.0);
       printf("\n");
-    } /* count */ 
-  }/* j category */ 
+    } /* count */
+  }/* j category */
   printf("===========================");
   for(z=0; z<NB_CRITERIA; z++) printf("==========");
   printf("\n");
@@ -213,47 +208,29 @@ static void camelsrt_draw(void *phs)
 static void camelsrt_init(const char *optarg, void* userdata _U_)
 {
   struct camelsrt_t *p_camelsrt;
-  const char *filter=NULL;
-  const char *emptyfilter=""; 
-
   GString *error_string;
 
-  if(!strncmp(optarg,"camel,srt,",9)){
-    filter=optarg+9;
-  } else {
-    filter=NULL;
-  }
-
   p_camelsrt = g_malloc(sizeof(struct camelsrt_t));
-  if(filter){
-    p_camelsrt->filter=g_malloc(strlen(filter)+1);
-    strcpy(p_camelsrt->filter,filter);
+  if(!strncmp(optarg,"camel,srt,",9)){
+    p_camelsrt->filter=g_strdup(optarg+9);
   } else {
     p_camelsrt->filter=NULL;
   }
   camelsrt_reset(p_camelsrt);
-  
-  if (filter) {
-    error_string=register_tap_listener("CAMEL",
-                                      p_camelsrt,
-                                      filter,
-                                      NULL,
-                                      camelsrt_packet,
-                                      camelsrt_draw);
-  } else { 
-    error_string=register_tap_listener("CAMEL",
-                                      p_camelsrt,
-                                      emptyfilter,
-                                      NULL,
-                                      camelsrt_packet,
-                                      camelsrt_draw);
-  }
-  
+
+  error_string=register_tap_listener("CAMEL",
+                                    p_camelsrt,
+                                    p_camelsrt->filter,
+                                    0,
+                                    NULL,
+                                    camelsrt_packet,
+                                    camelsrt_draw);
+
   if(error_string){
     /* error, we failed to attach to the tap. clean up */
     g_free(p_camelsrt->filter);
     g_free(p_camelsrt);
-    
+
     fprintf(stderr, "tshark: Couldn't register camel,srt tap: %s\n",
            error_string->str);
     g_string_free(error_string, TRUE);
@@ -265,7 +242,7 @@ static void camelsrt_init(const char *optarg, void* userdata _U_)
    * As the frame are proceeded in the chronological order, we do not need persistent stats
    * Whereas, with wireshark, it is not possible to have the correct display, if the stats are
    * not saved along the analyze
-   */ 
+   */
   gtcap_StatSRT=TRUE;
   gcamel_StatSRT=TRUE;
 }