2 * smb_stat 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/packet_info.h>
32 #include <epan/epan.h>
33 #include <epan/value_string.h>
35 #include <epan/dissectors/packet-smb.h>
37 #include "ui/simple_dialog.h"
39 #include "../globals.h"
40 #include "../stat_menu.h"
42 #include "ui/gtk/gui_utils.h"
43 #include "ui/gtk/dlg_utils.h"
44 #include "ui/gtk/service_response_time_table.h"
45 #include "ui/gtk/tap_param_dlg.h"
46 #include "ui/gtk/gtkglobals.h"
47 #include "ui/gtk/main.h"
49 #include "ui/gtk/old-gtk-compat.h"
51 /* used to keep track of the statistics for an entire program interface */
52 typedef struct _smbstat_t
{
54 srt_stat_table smb_srt_table
;
55 srt_stat_table trans2_srt_table
;
56 srt_stat_table nt_trans_srt_table
;
60 smbstat_set_title(smbstat_t
*ss
)
62 set_window_title(ss
->win
, "SMB Service Response Time statistics");
66 smbstat_reset(void *pss
)
68 smbstat_t
*ss
=(smbstat_t
*)pss
;
70 reset_srt_table_data(&ss
->smb_srt_table
);
71 reset_srt_table_data(&ss
->trans2_srt_table
);
72 reset_srt_table_data(&ss
->nt_trans_srt_table
);
73 smbstat_set_title(ss
);
77 smbstat_packet(void *pss
, packet_info
*pinfo
, epan_dissect_t
*edt _U_
, const void *psi
)
79 smbstat_t
*ss
=(smbstat_t
*)pss
;
80 const smb_info_t
*si
=(smb_info_t
*)psi
;
82 /* we are only interested in reply packets */
86 /* if we havnt seen the request, just ignore it */
91 add_srt_table_data(&ss
->smb_srt_table
, si
->cmd
, &si
->sip
->req_time
, pinfo
);
93 if(si
->cmd
==0xA0 && si
->sip
->extra_info_type
== SMB_EI_NTI
){
94 smb_nt_transact_info_t
*sti
=(smb_nt_transact_info_t
*)si
->sip
->extra_info
;
97 add_srt_table_data(&ss
->nt_trans_srt_table
, sti
->subcmd
, &si
->sip
->req_time
, pinfo
);
99 } else if(si
->cmd
==0x32 && si
->sip
->extra_info_type
== SMB_EI_T2I
){
100 smb_transact2_info_t
*st2i
=(smb_transact2_info_t
*)si
->sip
->extra_info
;
103 add_srt_table_data(&ss
->trans2_srt_table
, st2i
->subcmd
, &si
->sip
->req_time
, pinfo
);
113 smbstat_draw(void *pss
)
115 smbstat_t
*ss
=(smbstat_t
*)pss
;
117 draw_srt_table_data(&ss
->smb_srt_table
);
118 draw_srt_table_data(&ss
->trans2_srt_table
);
119 draw_srt_table_data(&ss
->nt_trans_srt_table
);
124 win_destroy_cb(GtkWindow
*win _U_
, gpointer data
)
126 smbstat_t
*ss
=(smbstat_t
*)data
;
128 remove_tap_listener(ss
);
130 free_srt_table_data(&ss
->smb_srt_table
);
131 free_srt_table_data(&ss
->trans2_srt_table
);
132 free_srt_table_data(&ss
->nt_trans_srt_table
);
138 gtk_smbstat_init(const char *opt_arg
, void *userdata _U_
)
141 const char *filter
=NULL
;
144 GString
*error_string
;
150 if(!strncmp(opt_arg
,"smb,srt,",8)){
156 ss
=(smbstat_t
*)g_malloc(sizeof(smbstat_t
));
158 ss
->win
= dlg_window_new("smb-stat"); /* transient_for top_level */
159 gtk_window_set_destroy_with_parent (GTK_WINDOW(ss
->win
), TRUE
);
160 gtk_window_set_default_size(GTK_WINDOW(ss
->win
), 550, 600);
161 smbstat_set_title(ss
);
163 vbox
=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL
, 3, FALSE
);
164 gtk_container_add(GTK_CONTAINER(ss
->win
), vbox
);
165 gtk_container_set_border_width(GTK_CONTAINER(vbox
), 12);
167 label
=gtk_label_new("SMB Service Response Time statistics");
168 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
170 filter_string
= g_strdup_printf("Filter: %s", filter
? filter
: "");
171 label
=gtk_label_new(filter_string
);
172 g_free(filter_string
);
173 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
174 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
176 label
=gtk_label_new("SMB Commands");
177 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
179 /* We must display TOP LEVEL Widget before calling init_srt_table() */
180 gtk_widget_show_all(ss
->win
);
182 init_srt_table(&ss
->smb_srt_table
, 256, vbox
, "smb.cmd");
184 init_srt_table_row(&ss
->smb_srt_table
, i
, val_to_str_ext(i
, &smb_cmd_vals_ext
, "Unknown(0x%02x)"));
188 label
=gtk_label_new("Transaction2 Sub-Commands");
189 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
190 init_srt_table(&ss
->trans2_srt_table
, 256, vbox
, "smb.trans2.cmd");
192 init_srt_table_row(&ss
->trans2_srt_table
, i
, val_to_str_ext(i
, &trans2_cmd_vals_ext
, "Unknown(0x%02x)"));
196 label
=gtk_label_new("NT Transaction Sub-Commands");
197 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
198 init_srt_table(&ss
->nt_trans_srt_table
, 256, vbox
, "smb.nt.function");
200 init_srt_table_row(&ss
->nt_trans_srt_table
, i
, val_to_str_ext(i
, &nt_cmd_vals_ext
, "Unknown(0x%02x)"));
204 error_string
=register_tap_listener("smb", ss
, filter
, 0, smbstat_reset
, smbstat_packet
, smbstat_draw
);
206 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
, "%s", error_string
->str
);
207 g_string_free(error_string
, TRUE
);
213 bbox
= dlg_button_row_new(GTK_STOCK_CLOSE
, NULL
);
214 gtk_box_pack_end(GTK_BOX(vbox
), bbox
, FALSE
, FALSE
, 0);
216 close_bt
= (GtkWidget
*)g_object_get_data(G_OBJECT(bbox
), GTK_STOCK_CLOSE
);
217 window_set_cancel_button(ss
->win
, close_bt
, window_cancel_button_cb
);
219 g_signal_connect(ss
->win
, "delete_event", G_CALLBACK(window_delete_event_cb
), NULL
);
220 g_signal_connect(ss
->win
, "destroy", G_CALLBACK(win_destroy_cb
), ss
);
222 gtk_widget_show_all(ss
->win
);
223 window_present(ss
->win
);
225 cf_retap_packets(&cfile
);
226 gdk_window_raise(gtk_widget_get_window(ss
->win
));
229 static tap_param smb_stat_params
[] = {
230 { PARAM_FILTER
, "Filter", NULL
}
233 static tap_param_dlg smb_stat_dlg
= {
234 "SMB SRT Statistics",
238 G_N_ELEMENTS(smb_stat_params
),
243 register_tap_listener_gtksmbstat(void)
245 register_param_stat(&smb_stat_dlg
, "SMB",
246 REGISTER_STAT_GROUP_RESPONSE_TIME
);