Add Windows version info resource.
[obnox/wireshark/wip.git] / tap-smbstat.c
index cb4273949406bc1a4db97d85aa0f1a3bb41639e9..2ef3f4d9962d93f2fdd01f74e749948204b28e12 100644 (file)
@@ -1,22 +1,22 @@
 /* tap-smbstat.c
  * smbstat   2003 Ronnie Sahlberg
  *
- * $Id: tap-smbstat.c,v 1.3 2003/04/23 08:20:02 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
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #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"
-
-
-typedef struct _smb_procedure_t {
-       int num;
-       nstime_t min;
-       nstime_t max;
-       nstime_t tot;
-} smb_procedure_t;
+#include "timestats.h"
 
 /* used to keep track of the statistics for an entire program interface */
 typedef struct _smbstat_t {
        char *filter;
-       smb_procedure_t proc[256];
-       smb_procedure_t trans2[256];
-       smb_procedure_t nt_trans[256];
+       timestat_t proc[256];
+       timestat_t trans2[256];
+       timestat_t nt_trans[256];
 } 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;
-       smb_procedure_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){
@@ -74,62 +69,32 @@ 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);
 
-       if((sp->max.secs==0)
-       && (sp->max.nsecs==0) ){
-               sp->max.secs=delta.secs;
-               sp->max.nsecs=delta.nsecs;
+       if(sp){
+               time_stat_update(sp,&deltat, pinfo);
        }
 
-       if((sp->min.secs==0)
-       && (sp->min.nsecs==0) ){
-               sp->min.secs=delta.secs;
-               sp->min.nsecs=delta.nsecs;
-       }
-
-       if( (delta.secs<sp->min.secs)
-       ||( (delta.secs==sp->min.secs)
-         &&(delta.nsecs<sp->min.nsecs) ) ){
-               sp->min.secs=delta.secs;
-               sp->min.nsecs=delta.nsecs;
-       }
-
-       if( (delta.secs>sp->max.secs)
-       ||( (delta.secs==sp->max.secs)
-         &&(delta.nsecs>sp->max.nsecs) ) ){
-               sp->max.secs=delta.secs;
-               sp->max.nsecs=delta.nsecs;
-       }
-       
-       sp->tot.secs += delta.secs;
-       sp->tot.nsecs += delta.nsecs;
-       if(sp->tot.nsecs>1000000000){
-               sp->tot.nsecs-=1000000000;
-               sp->tot.secs++;
-       }
-       sp->num++;
-
        return 1;
 }
 
@@ -242,11 +207,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)){
@@ -264,21 +229,35 @@ smbstat_init(char *optarg)
        }
 
        for(i=0;i<256;i++){
-               ss->proc[i].num=0;      
+               ss->proc[i].num=0;
+               ss->proc[i].min_num=0;
+               ss->proc[i].max_num=0;
                ss->proc[i].min.secs=0;
                ss->proc[i].min.nsecs=0;
                ss->proc[i].max.secs=0;
                ss->proc[i].max.nsecs=0;
                ss->proc[i].tot.secs=0;
                ss->proc[i].tot.nsecs=0;
-               
-               ss->trans2[i].num=0;    
+
+               ss->trans2[i].num=0;
+               ss->trans2[i].min_num=0;
+               ss->trans2[i].max_num=0;
                ss->trans2[i].min.secs=0;
                ss->trans2[i].min.nsecs=0;
                ss->trans2[i].max.secs=0;
                ss->trans2[i].max.nsecs=0;
                ss->trans2[i].tot.secs=0;
                ss->trans2[i].tot.nsecs=0;
+
+               ss->nt_trans[i].num=0;
+               ss->nt_trans[i].min_num=0;
+               ss->nt_trans[i].max_num=0;
+               ss->nt_trans[i].min.secs=0;
+               ss->nt_trans[i].min.nsecs=0;
+               ss->nt_trans[i].max.secs=0;
+               ss->nt_trans[i].max.nsecs=0;
+               ss->nt_trans[i].tot.secs=0;
+               ss->nt_trans[i].tot.nsecs=0;
        }
 
        error_string=register_tap_listener("smb", ss, filter, NULL, smbstat_packet, smbstat_draw);
@@ -287,7 +266,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);
@@ -298,6 +277,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);
 }