2 * smbstat 2003 Ronnie Sahlberg
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
36 #include "epan/packet_info.h"
38 #include <epan/emem.h>
39 #include <epan/stat_cmd_args.h>
40 #include "epan/value_string.h"
41 #include <epan/dissectors/packet-smb.h>
43 #include "timestats.h"
45 /* used to keep track of the statistics for an entire program interface */
46 typedef struct _smbstat_t {
49 timestat_t trans2[256];
50 timestat_t nt_trans[256];
56 smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
58 smbstat_t *ss=(smbstat_t *)pss;
59 const smb_info_t *si=psi;
63 /* we are only interested in reply packets */
67 /* if we havnt seen the request, just ignore it */
72 if(si->cmd==0xA0 && si->sip->extra_info_type == SMB_EI_NTI){
73 smb_nt_transact_info_t *sti=(smb_nt_transact_info_t *)si->sip->extra_info;
77 sp=&(ss->nt_trans[sti->subcmd]);
79 } else if(si->cmd==0x32 && si->sip->extra_info_type == SMB_EI_T2I){
80 smb_transact2_info_t *st2i=(smb_transact2_info_t *)si->sip->extra_info;
84 sp=&(ss->trans2[st2i->subcmd]);
87 sp=&(ss->proc[si->cmd]);
90 /* calculate time delta between request and reply */
92 nstime_delta(&deltat, &t, &si->sip->req_time);
95 time_stat_update(sp,&deltat, pinfo);
102 smbstat_draw(void *pss)
104 smbstat_t *ss=(smbstat_t *)pss;
108 printf("===================================================================\n");
109 printf("SMB RTT Statistics:\n");
110 printf("Filter: %s\n",ss->filter?ss->filter:"");
111 printf("Commands Calls Min RTT Max RTT Avg RTT\n");
113 /* nothing seen, nothing to do */
114 if(ss->proc[i].num==0){
118 /* we deal with transaction2 later */
123 /* we deal with nt transaction later */
128 /* scale it to units of 10us.*/
129 td=ss->proc[i].tot.secs;
130 td=td*100000+(int)ss->proc[i].tot.nsecs/10000;
137 printf("%-25s %6d %3d.%05d %3d.%05d %3" PRIu64 ".%05" PRIu64 "\n",
138 val_to_str(i, smb_cmd_vals, "Unknown (0x%02x)"),
140 (int)ss->proc[i].min.secs,ss->proc[i].min.nsecs/10000,
141 (int)ss->proc[i].max.secs,ss->proc[i].max.nsecs/10000,
147 printf("Transaction2 Commands Calls Min RTT Max RTT Avg RTT\n");
149 /* nothing seen, nothing to do */
150 if(ss->trans2[i].num==0){
154 /* scale it to units of 10us.*/
155 td=ss->trans2[i].tot.secs;
156 td=td*100000+(int)ss->trans2[i].tot.nsecs/10000;
157 if(ss->trans2[i].num){
158 td/=ss->trans2[i].num;
163 printf("%-25s %6d %3d.%05d %3d.%05d %3" PRIu64 ".%05" PRIu64 "\n",
164 val_to_str(i, trans2_cmd_vals, "Unknown (0x%02x)"),
166 (int)ss->trans2[i].min.secs,ss->trans2[i].min.nsecs/10000,
167 (int)ss->trans2[i].max.secs,ss->trans2[i].max.nsecs/10000,
173 printf("NT Transaction Commands Calls Min RTT Max RTT Avg RTT\n");
175 /* nothing seen, nothing to do */
176 if(ss->nt_trans[i].num==0){
180 /* scale it to units of 10us.*/
181 td=ss->nt_trans[i].tot.secs;
182 td=td*100000+(int)ss->nt_trans[i].tot.nsecs/10000;
183 if(ss->nt_trans[i].num){
184 td/=ss->nt_trans[i].num;
189 printf("%-25s %6d %3d.%05d %3d.%05d %3" PRIu64 ".%05" PRIu64 "\n",
190 val_to_str(i, nt_cmd_vals, "Unknown (0x%02x)"),
192 (int)ss->nt_trans[i].min.secs,ss->nt_trans[i].min.nsecs/10000,
193 (int)ss->nt_trans[i].max.secs,ss->nt_trans[i].max.nsecs/10000,
198 printf("===================================================================\n");
203 smbstat_init(const char *optarg,void* userdata _U_)
207 const char *filter=NULL;
208 GString *error_string;
210 if(!strncmp(optarg,"smb,rtt,",8)){
216 ss=g_malloc(sizeof(smbstat_t));
218 ss->filter=g_malloc(strlen(filter)+1);
219 strcpy(ss->filter, filter);
226 ss->proc[i].min_num=0;
227 ss->proc[i].max_num=0;
228 ss->proc[i].min.secs=0;
229 ss->proc[i].min.nsecs=0;
230 ss->proc[i].max.secs=0;
231 ss->proc[i].max.nsecs=0;
232 ss->proc[i].tot.secs=0;
233 ss->proc[i].tot.nsecs=0;
236 ss->trans2[i].min_num=0;
237 ss->trans2[i].max_num=0;
238 ss->trans2[i].min.secs=0;
239 ss->trans2[i].min.nsecs=0;
240 ss->trans2[i].max.secs=0;
241 ss->trans2[i].max.nsecs=0;
242 ss->trans2[i].tot.secs=0;
243 ss->trans2[i].tot.nsecs=0;
245 ss->nt_trans[i].num=0;
246 ss->nt_trans[i].min_num=0;
247 ss->nt_trans[i].max_num=0;
248 ss->nt_trans[i].min.secs=0;
249 ss->nt_trans[i].min.nsecs=0;
250 ss->nt_trans[i].max.secs=0;
251 ss->nt_trans[i].max.nsecs=0;
252 ss->nt_trans[i].tot.secs=0;
253 ss->nt_trans[i].tot.nsecs=0;
256 error_string=register_tap_listener("smb", ss, filter, NULL, smbstat_packet, smbstat_draw);
258 /* error, we failed to attach to the tap. clean up */
262 fprintf(stderr, "tshark: Couldn't register smb,rtt tap: %s\n",
264 g_string_free(error_string, TRUE);
271 register_tap_listener_smbstat(void)
273 register_stat_cmd_arg("smb,rtt", smbstat_init,NULL);