Update:
[obnox/wireshark/wip.git] / tap-smbstat.c
index a2e2a32e0d1394287f2aac6fd570af3c4f7da6eb..2a3439e6e1f6bb4777dc0579c031d3c0bf708668 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
 #include <string.h>
 #include "epan/packet_info.h"
 #include <epan/tap.h>
-#include <epan/stat.h>
+#include <epan/stat_cmd_args.h>
 #include "epan/value_string.h"
-#include "smb.h"
-#include "register.h"
+#include <epan/dissectors/packet-smb.h>
 #include "timestats.h"
 
+#define MICROSECS_PER_SEC   1000000
+#define NANOSECS_PER_SEC    1000000000
+
 /* used to keep track of the statistics for an entire program interface */
 typedef struct _smbstat_t {
        char *filter;
@@ -56,7 +58,7 @@ smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const voi
 {
        smbstat_t *ss=(smbstat_t *)pss;
        const smb_info_t *si=psi;
-       nstime_t delta;
+       nstime_t t, deltat;
        timestat_t *sp=NULL;
 
        /* we are only interested in reply packets */
@@ -87,15 +89,11 @@ smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const voi
        }
 
        /* calculate time delta between request and reply */
-       delta.secs=pinfo->fd->abs_secs-si->sip->req_time.secs;
-       delta.nsecs=pinfo->fd->abs_usecs*1000-si->sip->req_time.nsecs;
-       if(delta.nsecs<0){
-               delta.nsecs+=1000000000;
-               delta.secs--;
-       }
+       t=pinfo->fd->abs_ts;
+       nstime_delta(&deltat, &t, &si->sip->req_time);
 
        if(sp){
-               time_stat_update(sp,&delta, pinfo);
+               time_stat_update(sp,&deltat, pinfo);
        }
 
        return 1;
@@ -106,16 +104,12 @@ smbstat_draw(void *pss)
 {
        smbstat_t *ss=(smbstat_t *)pss;
        guint32 i;
-#ifdef G_HAVE_UINT64
        guint64 td;
-#else
-       guint32 td;
-#endif
        printf("\n");
-       printf("===================================================================\n");
-       printf("SMB RTT Statistics:\n");
+       printf("=================================================================\n");
+       printf("SMB SRT Statistics:\n");
        printf("Filter: %s\n",ss->filter?ss->filter:"");
-       printf("Commands                   Calls   Min RTT   Max RTT   Avg RTT\n");
+       printf("Commands                   Calls    Min SRT    Max SRT    Avg SRT\n");
        for(i=0;i<256;i++){
                /* nothing seen, nothing to do */
                if(ss->proc[i].num==0){
@@ -132,92 +126,74 @@ smbstat_draw(void *pss)
                        continue;
                }
 
-               /* scale it to units of 10us.*/
-               /* for long captures with a large tot time, this can overflow on 32bit */
-               td=(int)ss->proc[i].tot.secs;
-               td=td*100000+(int)ss->proc[i].tot.nsecs/10000;
-               if(ss->proc[i].num){
-                       td/=ss->proc[i].num;
-               } else {
-                       td=0;
-               }
+               /* Scale the average SRT in units of 1us and round to the nearest us. */
+               td = ((guint64)(ss->proc[i].tot.secs)) * NANOSECS_PER_SEC + ss->proc[i].tot.nsecs;
 
-               printf("%-25s %6d %3d.%05d %3d.%05d %3d.%05d\n",
-                       val_to_str(i, smb_cmd_vals, "Unknown (0x%02x)"),
+               td = ((td / ss->proc[i].num) + 500) / 1000;
+
+               printf("%-25s %6d %3d.%06d %3d.%06d %3" G_GINT64_MODIFIER "u.%06" G_GINT64_MODIFIER "u\n",
+                       val_to_str_ext(i, &smb_cmd_vals_ext, "Unknown (0x%02x)"),
                        ss->proc[i].num,
-                       (int)ss->proc[i].min.secs,ss->proc[i].min.nsecs/10000,
-                       (int)ss->proc[i].max.secs,ss->proc[i].max.nsecs/10000,
-                       td/100000, td%100000
+                       (int)(ss->proc[i].min.secs),(ss->proc[i].min.nsecs+500)/1000,
+                       (int)(ss->proc[i].max.secs),(ss->proc[i].max.nsecs+500)/1000,
+                       td/MICROSECS_PER_SEC, td%MICROSECS_PER_SEC
                );
        }
 
        printf("\n");
-       printf("Transaction2 Commands      Calls   Min RTT   Max RTT   Avg RTT\n");
+       printf("Transaction2 Commands      Calls    Min SRT    Max SRT    Avg SRT\n");
        for(i=0;i<256;i++){
                /* nothing seen, nothing to do */
                if(ss->trans2[i].num==0){
                        continue;
                }
 
-               /* scale it to units of 10us.*/
-               /* for long captures with a large tot time, this can overflow on 32bit */
-               td=(int)ss->trans2[i].tot.secs;
-               td=td*100000+(int)ss->trans2[i].tot.nsecs/10000;
-               if(ss->trans2[i].num){
-                       td/=ss->trans2[i].num;
-               } else {
-                       td=0;
-               }
+               /* Scale the average SRT in units of 1us and round to the nearest us. */
+               td = ((guint64)(ss->trans2[i].tot.secs)) * NANOSECS_PER_SEC + ss->trans2[i].tot.nsecs;
+               td = ((td / ss->trans2[i].num) + 500) / 1000;
 
-               printf("%-25s %6d %3d.%05d %3d.%05d %3d.%05d\n",
-                       val_to_str(i, trans2_cmd_vals, "Unknown (0x%02x)"),
+               printf("%-25s %6d %3d.%06d %3d.%06d %3" G_GINT64_MODIFIER "u.%06" G_GINT64_MODIFIER "u\n",
+                       val_to_str_ext(i, &trans2_cmd_vals_ext, "Unknown (0x%02x)"),
                        ss->trans2[i].num,
-                       (int)ss->trans2[i].min.secs,ss->trans2[i].min.nsecs/10000,
-                       (int)ss->trans2[i].max.secs,ss->trans2[i].max.nsecs/10000,
-                       td/100000, td%100000
+                       (int)(ss->trans2[i].min.secs),(ss->trans2[i].min.nsecs+500)/1000,
+                       (int)(ss->trans2[i].max.secs),(ss->trans2[i].max.nsecs+500)/1000,
+                       td/MICROSECS_PER_SEC, td%MICROSECS_PER_SEC
                );
        }
 
        printf("\n");
-       printf("NT Transaction Commands    Calls   Min RTT   Max RTT   Avg RTT\n");
+       printf("NT Transaction Commands    Calls    Min SRT    Max SRT    Avg SRT\n");
        for(i=0;i<256;i++){
                /* nothing seen, nothing to do */
                if(ss->nt_trans[i].num==0){
                        continue;
                }
+               /* Scale the average SRT in units of 1us and round to the nearest us. */
+               td = ((guint64)(ss->nt_trans[i].tot.secs)) * NANOSECS_PER_SEC + ss->nt_trans[i].tot.nsecs;
+               td = ((td / ss->nt_trans[i].num) + 500) / 1000;
 
-               /* scale it to units of 10us.*/
-               /* for long captures with a large tot time, this can overflow on 32bit */
-               td=(int)ss->nt_trans[i].tot.secs;
-               td=td*100000+(int)ss->nt_trans[i].tot.nsecs/10000;
-               if(ss->nt_trans[i].num){
-                       td/=ss->nt_trans[i].num;
-               } else {
-                       td=0;
-               }
-
-               printf("%-25s %6d %3d.%05d %3d.%05d %3d.%05d\n",
-                       val_to_str(i, nt_cmd_vals, "Unknown (0x%02x)"),
+               printf("%-25s %6d %3d.%06d %3d.%06d %3" G_GINT64_MODIFIER "u.%06" G_GINT64_MODIFIER "u\n",
+                       val_to_str_ext(i, &nt_cmd_vals_ext, "Unknown (0x%02x)"),
                        ss->nt_trans[i].num,
-                       (int)ss->nt_trans[i].min.secs,ss->nt_trans[i].min.nsecs/10000,
-                       (int)ss->nt_trans[i].max.secs,ss->nt_trans[i].max.nsecs/10000,
-                       td/100000, td%100000
+                       (int)(ss->nt_trans[i].min.secs),(ss->nt_trans[i].min.nsecs+500)/1000,
+                       (int)(ss->nt_trans[i].max.secs),(ss->nt_trans[i].max.nsecs+500)/1000,
+                       td/MICROSECS_PER_SEC, td%MICROSECS_PER_SEC
                );
        }
 
-       printf("===================================================================\n");
+       printf("=================================================================\n");
 }
 
 
 static void
-smbstat_init(const char *optarg)
+smbstat_init(const char *optarg,void* userdata _U_)
 {
        smbstat_t *ss;
        guint32 i;
        const char *filter=NULL;
        GString *error_string;
 
-       if(!strncmp(optarg,"smb,rtt,",8)){
+       if(!strncmp(optarg,"smb,srt,",8)){
                filter=optarg+8;
        } else {
                filter=NULL;
@@ -225,8 +201,7 @@ smbstat_init(const char *optarg)
 
        ss=g_malloc(sizeof(smbstat_t));
        if(filter){
-               ss->filter=g_malloc(strlen(filter)+1);
-               strcpy(ss->filter, filter);
+               ss->filter=g_strdup(filter);
        } else {
                ss->filter=NULL;
        }
@@ -263,13 +238,13 @@ smbstat_init(const char *optarg)
                ss->nt_trans[i].tot.nsecs=0;
        }
 
-       error_string=register_tap_listener("smb", ss, filter, NULL, smbstat_packet, smbstat_draw);
+       error_string=register_tap_listener("smb", ss, filter, 0, NULL, smbstat_packet, smbstat_draw);
        if(error_string){
                /* error, we failed to attach to the tap. clean up */
                g_free(ss->filter);
                g_free(ss);
 
-               fprintf(stderr, "tethereal: Couldn't register smb,rtt tap: %s\n",
+               fprintf(stderr, "tshark: Couldn't register smb,srt tap: %s\n",
                    error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
@@ -280,6 +255,6 @@ smbstat_init(const char *optarg)
 void
 register_tap_listener_smbstat(void)
 {
-       register_stat_cmd_arg("smb,rtt", smbstat_init);
+       register_stat_cmd_arg("smb,srt", smbstat_init,NULL);
 }