From Stig Bjorlykke:
[obnox/wireshark/wip.git] / tap-smbstat.c
index 484de6abb2f80b6f91b973a42328f14ff3b2d0c0..94ead0f07b601e0e210d821e3fbf1b161085415a 100644 (file)
@@ -1,10 +1,10 @@
 /* tap-smbstat.c
  * smbstat   2003 Ronnie Sahlberg
  *
- * $Id: tap-smbstat.c,v 1.4 2003/04/25 20:54:16 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/emem.h>
+#include <epan/stat_cmd_args.h>
 #include "epan/value_string.h"
-#include "smb.h"
+#include <epan/dissectors/packet-smb.h>
 #include "register.h"
 #include "timestats.h"
 
@@ -51,12 +53,12 @@ typedef struct _smbstat_t {
 
 
 static int
-smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, void *psi)
+smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
 {
        smbstat_t *ss=(smbstat_t *)pss;
-       smb_info_t *si=psi;
-       nstime_t delta;
-       timestat_t *sp;
+       const smb_info_t *si=psi;
+       nstime_t t, deltat;
+       timestat_t *sp=NULL;
 
        /* we are only interested in reply packets */
        if(si->request){
@@ -67,29 +69,31 @@ smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, void *psi
                return 0;
        }
 
-       if(si->cmd==0xA0){
+       if(si->cmd==0xA0 && si->sip->extra_info_type == SMB_EI_NTI){
                smb_nt_transact_info_t *sti=(smb_nt_transact_info_t *)si->sip->extra_info;
 
                /*nt transaction*/
-               sp=&(ss->nt_trans[sti->subcmd]);
-       } else if(si->cmd==0x32){
+               if(sti){
+                       sp=&(ss->nt_trans[sti->subcmd]);
+               }
+       } else if(si->cmd==0x32 && si->sip->extra_info_type == SMB_EI_T2I){
                smb_transact2_info_t *st2i=(smb_transact2_info_t *)si->sip->extra_info;
 
                /*transaction2*/
-               sp=&(ss->trans2[st2i->subcmd]);
+               if(st2i){
+                       sp=&(ss->trans2[st2i->subcmd]);
+               }
        } else {
                sp=&(ss->proc[si->cmd]);
        }
 
        /* 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);
 
-       time_stat_update(sp,&delta, pinfo);
+       if(sp){
+               time_stat_update(sp,&deltat, pinfo);
+       }
 
        return 1;
 }
@@ -99,11 +103,7 @@ 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");
@@ -126,8 +126,7 @@ smbstat_draw(void *pss)
                }
 
                /* 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=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;
@@ -135,7 +134,7 @@ smbstat_draw(void *pss)
                        td=0;
                }
 
-               printf("%-25s %6d %3d.%05d %3d.%05d %3d.%05d\n",
+               printf("%-25s %6d %3d.%05d %3d.%05d %3" PRIu64 ".%05" PRIu64 "\n",
                        val_to_str(i, smb_cmd_vals, "Unknown (0x%02x)"),
                        ss->proc[i].num,
                        (int)ss->proc[i].min.secs,ss->proc[i].min.nsecs/10000,
@@ -153,8 +152,7 @@ smbstat_draw(void *pss)
                }
 
                /* 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=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;
@@ -162,7 +160,7 @@ smbstat_draw(void *pss)
                        td=0;
                }
 
-               printf("%-25s %6d %3d.%05d %3d.%05d %3d.%05d\n",
+               printf("%-25s %6d %3d.%05d %3d.%05d %3" PRIu64 ".%05" PRIu64 "\n",
                        val_to_str(i, trans2_cmd_vals, "Unknown (0x%02x)"),
                        ss->trans2[i].num,
                        (int)ss->trans2[i].min.secs,ss->trans2[i].min.nsecs/10000,
@@ -180,8 +178,7 @@ smbstat_draw(void *pss)
                }
 
                /* 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=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;
@@ -189,7 +186,7 @@ smbstat_draw(void *pss)
                        td=0;
                }
 
-               printf("%-25s %6d %3d.%05d %3d.%05d %3d.%05d\n",
+               printf("%-25s %6d %3d.%05d %3d.%05d %3" PRIu64 ".%05" PRIu64 "\n",
                        val_to_str(i, nt_cmd_vals, "Unknown (0x%02x)"),
                        ss->nt_trans[i].num,
                        (int)ss->nt_trans[i].min.secs,ss->nt_trans[i].min.nsecs/10000,
@@ -203,11 +200,11 @@ smbstat_draw(void *pss)
 
 
 static void
-smbstat_init(char *optarg)
+smbstat_init(const char *optarg,void* userdata _U_)
 {
        smbstat_t *ss;
        guint32 i;
-       char *filter=NULL;
+       const char *filter=NULL;
        GString *error_string;
 
        if(!strncmp(optarg,"smb,rtt,",8)){
@@ -262,7 +259,7 @@ smbstat_init(char *optarg)
                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,rtt tap: %s\n",
                    error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
@@ -273,6 +270,6 @@ smbstat_init(char *optarg)
 void
 register_tap_listener_smbstat(void)
 {
-       register_ethereal_tap("smb,rtt", smbstat_init);
+       register_stat_cmd_arg("smb,rtt", smbstat_init,NULL);
 }