Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / ui / cli / tap-smbstat.c
blob781e3f3a81399407f680efb8db62d5e86403b362
1 /* tap-smbstat.c
2 * smbstat 2003 Ronnie Sahlberg
4 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "config.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
31 #include "epan/packet_info.h"
32 #include <epan/tap.h>
33 #include <epan/stat_cmd_args.h>
34 #include "epan/value_string.h"
35 #include <epan/dissectors/packet-smb.h>
36 #include "epan/timestats.h"
38 #define MICROSECS_PER_SEC 1000000
39 #define NANOSECS_PER_SEC 1000000000
41 void register_tap_listener_smbstat(void);
43 /* used to keep track of the statistics for an entire program interface */
44 typedef struct _smbstat_t {
45 char *filter;
46 timestat_t proc[256];
47 timestat_t trans2[256];
48 timestat_t nt_trans[256];
49 } smbstat_t;
53 static int
54 smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
56 smbstat_t *ss=(smbstat_t *)pss;
57 const smb_info_t *si=(const smb_info_t *)psi;
58 nstime_t t, deltat;
59 timestat_t *sp=NULL;
61 /* we are only interested in reply packets */
62 if(si->request){
63 return 0;
65 /* if we havnt seen the request, just ignore it */
66 if(!si->sip){
67 return 0;
70 if(si->cmd==0xA0 && si->sip->extra_info_type == SMB_EI_NTI){
71 smb_nt_transact_info_t *sti=(smb_nt_transact_info_t *)si->sip->extra_info;
73 /*nt transaction*/
74 if(sti){
75 sp=&(ss->nt_trans[sti->subcmd]);
77 } else if(si->cmd==0x32 && si->sip->extra_info_type == SMB_EI_T2I){
78 smb_transact2_info_t *st2i=(smb_transact2_info_t *)si->sip->extra_info;
80 /*transaction2*/
81 if(st2i){
82 sp=&(ss->trans2[st2i->subcmd]);
84 } else {
85 sp=&(ss->proc[si->cmd]);
88 /* calculate time delta between request and reply */
89 t=pinfo->fd->abs_ts;
90 nstime_delta(&deltat, &t, &si->sip->req_time);
92 if(sp){
93 time_stat_update(sp,&deltat, pinfo);
96 return 1;
99 static void
100 smbstat_draw(void *pss)
102 smbstat_t *ss=(smbstat_t *)pss;
103 guint32 i;
104 guint64 td;
105 printf("\n");
106 printf("=================================================================\n");
107 printf("SMB SRT Statistics:\n");
108 printf("Filter: %s\n",ss->filter?ss->filter:"");
109 printf("Commands Calls Min SRT Max SRT Avg SRT\n");
110 for(i=0;i<256;i++){
111 /* nothing seen, nothing to do */
112 if(ss->proc[i].num==0){
113 continue;
116 /* we deal with transaction2 later */
117 if(i==0x32){
118 continue;
121 /* we deal with nt transaction later */
122 if(i==0xA0){
123 continue;
126 /* Scale the average SRT in units of 1us and round to the nearest us. */
127 td = ((guint64)(ss->proc[i].tot.secs)) * NANOSECS_PER_SEC + ss->proc[i].tot.nsecs;
129 td = ((td / ss->proc[i].num) + 500) / 1000;
131 printf("%-25s %6d %3d.%06d %3d.%06d %3" G_GINT64_MODIFIER "u.%06" G_GINT64_MODIFIER "u\n",
132 val_to_str_ext(i, &smb_cmd_vals_ext, "Unknown (0x%02x)"),
133 ss->proc[i].num,
134 (int)(ss->proc[i].min.secs),(ss->proc[i].min.nsecs+500)/1000,
135 (int)(ss->proc[i].max.secs),(ss->proc[i].max.nsecs+500)/1000,
136 td/MICROSECS_PER_SEC, td%MICROSECS_PER_SEC
140 printf("\n");
141 printf("Transaction2 Commands Calls Min SRT Max SRT Avg SRT\n");
142 for(i=0;i<256;i++){
143 /* nothing seen, nothing to do */
144 if(ss->trans2[i].num==0){
145 continue;
148 /* Scale the average SRT in units of 1us and round to the nearest us. */
149 td = ((guint64)(ss->trans2[i].tot.secs)) * NANOSECS_PER_SEC + ss->trans2[i].tot.nsecs;
150 td = ((td / ss->trans2[i].num) + 500) / 1000;
152 printf("%-25s %6d %3d.%06d %3d.%06d %3" G_GINT64_MODIFIER "u.%06" G_GINT64_MODIFIER "u\n",
153 val_to_str_ext(i, &trans2_cmd_vals_ext, "Unknown (0x%02x)"),
154 ss->trans2[i].num,
155 (int)(ss->trans2[i].min.secs),(ss->trans2[i].min.nsecs+500)/1000,
156 (int)(ss->trans2[i].max.secs),(ss->trans2[i].max.nsecs+500)/1000,
157 td/MICROSECS_PER_SEC, td%MICROSECS_PER_SEC
161 printf("\n");
162 printf("NT Transaction Commands Calls Min SRT Max SRT Avg SRT\n");
163 for(i=0;i<256;i++){
164 /* nothing seen, nothing to do */
165 if(ss->nt_trans[i].num==0){
166 continue;
168 /* Scale the average SRT in units of 1us and round to the nearest us. */
169 td = ((guint64)(ss->nt_trans[i].tot.secs)) * NANOSECS_PER_SEC + ss->nt_trans[i].tot.nsecs;
170 td = ((td / ss->nt_trans[i].num) + 500) / 1000;
172 printf("%-25s %6d %3d.%06d %3d.%06d %3" G_GINT64_MODIFIER "u.%06" G_GINT64_MODIFIER "u\n",
173 val_to_str_ext(i, &nt_cmd_vals_ext, "Unknown (0x%02x)"),
174 ss->nt_trans[i].num,
175 (int)(ss->nt_trans[i].min.secs),(ss->nt_trans[i].min.nsecs+500)/1000,
176 (int)(ss->nt_trans[i].max.secs),(ss->nt_trans[i].max.nsecs+500)/1000,
177 td/MICROSECS_PER_SEC, td%MICROSECS_PER_SEC
181 printf("=================================================================\n");
185 static void
186 smbstat_init(const char *opt_arg,void* userdata _U_)
188 smbstat_t *ss;
189 guint32 i;
190 const char *filter=NULL;
191 GString *error_string;
193 if(!strncmp(opt_arg,"smb,srt,",8)){
194 filter=opt_arg+8;
195 } else {
196 filter=NULL;
199 ss=g_new(smbstat_t,1);
200 if(filter){
201 ss->filter=g_strdup(filter);
202 } else {
203 ss->filter=NULL;
206 for(i=0;i<256;i++){
207 ss->proc[i].num=0;
208 ss->proc[i].min_num=0;
209 ss->proc[i].max_num=0;
210 ss->proc[i].min.secs=0;
211 ss->proc[i].min.nsecs=0;
212 ss->proc[i].max.secs=0;
213 ss->proc[i].max.nsecs=0;
214 ss->proc[i].tot.secs=0;
215 ss->proc[i].tot.nsecs=0;
217 ss->trans2[i].num=0;
218 ss->trans2[i].min_num=0;
219 ss->trans2[i].max_num=0;
220 ss->trans2[i].min.secs=0;
221 ss->trans2[i].min.nsecs=0;
222 ss->trans2[i].max.secs=0;
223 ss->trans2[i].max.nsecs=0;
224 ss->trans2[i].tot.secs=0;
225 ss->trans2[i].tot.nsecs=0;
227 ss->nt_trans[i].num=0;
228 ss->nt_trans[i].min_num=0;
229 ss->nt_trans[i].max_num=0;
230 ss->nt_trans[i].min.secs=0;
231 ss->nt_trans[i].min.nsecs=0;
232 ss->nt_trans[i].max.secs=0;
233 ss->nt_trans[i].max.nsecs=0;
234 ss->nt_trans[i].tot.secs=0;
235 ss->nt_trans[i].tot.nsecs=0;
238 error_string=register_tap_listener("smb", ss, filter, 0, NULL, smbstat_packet, smbstat_draw);
239 if(error_string){
240 /* error, we failed to attach to the tap. clean up */
241 g_free(ss->filter);
242 g_free(ss);
244 fprintf(stderr, "tshark: Couldn't register smb,srt tap: %s\n",
245 error_string->str);
246 g_string_free(error_string, TRUE);
247 exit(1);
252 void
253 register_tap_listener_smbstat(void)
255 register_stat_cmd_arg("smb,srt", smbstat_init,NULL);