2 * smb_stat 2003 Ronnie Sahlberg
4 * $Id: smb_stat.c,v 1.25 2003/12/04 00:45:39 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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>
37 #include "../epan/packet_info.h"
38 #include "../epan/epan.h"
41 #include "../epan/value_string.h"
43 #include "../register.h"
44 #include "../timestats.h"
45 #include "compat_macros.h"
46 #include "../simple_dialog.h"
47 #include "dlg_utils.h"
49 #include "../globals.h"
50 #include "filter_prefs.h"
51 #include "service_response_time_table.h"
53 extern GtkWidget *main_display_filter_widget;
55 /* used to keep track of the statistics for an entire program interface */
56 typedef struct _smbstat_t {
58 srt_stat_table smb_srt_table;
59 srt_stat_table trans2_srt_table;
60 srt_stat_table nt_trans_srt_table;
64 smbstat_set_title(smbstat_t *ss)
68 title = g_strdup_printf("SMB Service Response Time statistics: %s",
69 cf_get_display_name(&cfile));
70 gtk_window_set_title(GTK_WINDOW(ss->win), title);
75 smbstat_reset(void *pss)
77 smbstat_t *ss=(smbstat_t *)pss;
79 reset_srt_table_data(&ss->smb_srt_table);
80 reset_srt_table_data(&ss->trans2_srt_table);
81 reset_srt_table_data(&ss->nt_trans_srt_table);
82 smbstat_set_title(ss);
86 smbstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, void *psi)
88 smbstat_t *ss=(smbstat_t *)pss;
91 /* we are only interested in reply packets */
95 /* if we havnt seen the request, just ignore it */
100 add_srt_table_data(&ss->smb_srt_table, si->cmd, &si->sip->req_time, pinfo);
103 smb_nt_transact_info_t *sti=(smb_nt_transact_info_t *)si->sip->extra_info;
106 add_srt_table_data(&ss->nt_trans_srt_table, sti->subcmd, &si->sip->req_time, pinfo);
108 } else if(si->cmd==0x32){
109 smb_transact2_info_t *st2i=(smb_transact2_info_t *)si->sip->extra_info;
112 add_srt_table_data(&ss->trans2_srt_table, st2i->subcmd, &si->sip->req_time, pinfo);
122 smbstat_draw(void *pss)
124 smbstat_t *ss=(smbstat_t *)pss;
126 draw_srt_table_data(&ss->smb_srt_table);
127 draw_srt_table_data(&ss->trans2_srt_table);
128 draw_srt_table_data(&ss->nt_trans_srt_table);
132 void protect_thread_critical_region(void);
133 void unprotect_thread_critical_region(void);
135 win_destroy_cb(GtkWindow *win _U_, gpointer data)
137 smbstat_t *ss=(smbstat_t *)data;
139 protect_thread_critical_region();
140 remove_tap_listener(ss);
141 unprotect_thread_critical_region();
143 free_srt_table_data(&ss->smb_srt_table);
144 free_srt_table_data(&ss->trans2_srt_table);
145 free_srt_table_data(&ss->nt_trans_srt_table);
151 gtk_smbstat_init(char *optarg)
156 char filter_string[256];
157 GString *error_string;
161 if(!strncmp(optarg,"smb,srt,",8)){
167 ss=g_malloc(sizeof(smbstat_t));
169 ss->win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
170 gtk_window_set_default_size(GTK_WINDOW(ss->win), 550, 600);
171 smbstat_set_title(ss);
172 SIGNAL_CONNECT(ss->win, "destroy", win_destroy_cb, ss);
174 vbox=gtk_vbox_new(FALSE, 0);
175 gtk_container_add(GTK_CONTAINER(ss->win), vbox);
176 gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
177 gtk_widget_show(vbox);
179 label=gtk_label_new("SMB Service Response Time statistics");
180 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
181 gtk_widget_show(label);
183 snprintf(filter_string,255,"Filter:%s",filter?filter:"");
184 label=gtk_label_new(filter_string);
185 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
186 gtk_widget_show(label);
189 label=gtk_label_new("SMB Commands");
190 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
191 gtk_widget_show(label);
193 /* We must display TOP LEVEL Widget before calling init_srt_table() */
194 gtk_widget_show(ss->win);
196 init_srt_table(&ss->smb_srt_table, 256, vbox, "smb.cmd");
198 init_srt_table_row(&ss->smb_srt_table, i, val_to_str(i, smb_cmd_vals, "Unknown(0x%02x)"));
202 label=gtk_label_new("Transaction2 Sub-Commands");
203 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
204 gtk_widget_show(label);
205 init_srt_table(&ss->trans2_srt_table, 256, vbox, "smb.trans2.cmd");
207 init_srt_table_row(&ss->trans2_srt_table, i, val_to_str(i, trans2_cmd_vals, "Unknown(0x%02x)"));
211 label=gtk_label_new("NT Transaction Sub-Commands");
212 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
213 gtk_widget_show(label);
214 init_srt_table(&ss->nt_trans_srt_table, 256, vbox, "smb.nt.function");
216 init_srt_table_row(&ss->nt_trans_srt_table, i, val_to_str(i, nt_cmd_vals, "Unknown(0x%02x)"));
220 error_string=register_tap_listener("smb", ss, filter, smbstat_reset, smbstat_packet, smbstat_draw);
222 simple_dialog(ESD_TYPE_WARN, NULL, error_string->str);
223 g_string_free(error_string, TRUE);
228 gtk_widget_show_all(ss->win);
229 redissect_packets(&cfile);
234 static GtkWidget *dlg=NULL;
235 static GtkWidget *filter_entry;
244 dlg_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w)
246 gtk_widget_destroy(GTK_WIDGET(parent_w));
250 smbstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
255 str = g_string_new("smb,srt");
256 filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
258 g_string_sprintfa(str,",%s", filter);
260 gtk_smbstat_init(str->str);
261 g_string_free(str, TRUE);
265 gtk_smbstat_cb(GtkWidget *w _U_, gpointer d _U_)
268 GtkWidget *filter_box, *filter_bt;
269 GtkWidget *bbox, *start_button, *cancel_button;
271 static construct_args_t args = {
272 "Service Response Time Statistics Filter",
277 /* if the window is already open, bring it to front */
279 gdk_window_raise(dlg->window);
283 dlg=dlg_window_new("Ethereal: Compute SMB SRT statistics");
284 SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
286 dlg_box=gtk_vbox_new(FALSE, 10);
287 gtk_container_border_width(GTK_CONTAINER(dlg_box), 10);
288 gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
289 gtk_widget_show(dlg_box);
292 filter_box=gtk_hbox_new(FALSE, 3);
295 filter_bt = gtk_button_new_with_label("Filter:");
296 SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
297 gtk_box_pack_start(GTK_BOX(filter_box), filter_bt, FALSE, TRUE, 0);
298 gtk_widget_show(filter_bt);
301 filter_entry=gtk_entry_new();
302 gtk_widget_set_usize(filter_entry, 300, -2);
304 /* filter prefs dialog */
305 OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_entry);
306 /* filter prefs dialog */
308 gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, TRUE, TRUE, 0);
309 filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
311 gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
313 gtk_widget_show(filter_entry);
315 gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
316 gtk_widget_show(filter_box);
319 bbox=gtk_hbutton_box_new();
320 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_DEFAULT_STYLE);
321 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
322 gtk_box_pack_start(GTK_BOX(dlg_box), bbox, FALSE, FALSE, 0);
323 gtk_widget_show(bbox);
325 /* the start button */
326 start_button=gtk_button_new_with_label("Create Stat");
327 SIGNAL_CONNECT_OBJECT(start_button, "clicked",
328 smbstat_start_button_clicked, NULL);
329 gtk_box_pack_start(GTK_BOX(bbox), start_button, TRUE, TRUE, 0);
330 GTK_WIDGET_SET_FLAGS(start_button, GTK_CAN_DEFAULT);
331 gtk_widget_grab_default(start_button);
332 gtk_widget_show(start_button);
334 #if GTK_MAJOR_VERSION < 2
335 cancel_button=gtk_button_new_with_label("Cancel");
337 cancel_button=gtk_button_new_from_stock(GTK_STOCK_CANCEL);
339 SIGNAL_CONNECT(cancel_button, "clicked", dlg_cancel_cb, dlg);
340 GTK_WIDGET_SET_FLAGS(cancel_button, GTK_CAN_DEFAULT);
341 gtk_box_pack_start(GTK_BOX(bbox), cancel_button, TRUE, TRUE, 0);
342 gtk_widget_show(cancel_button);
344 /* Catch the "activate" signal on the filter text entry, so that
345 if the user types Return there, we act as if the "Create Stat"
346 button had been selected, as happens if Return is typed if some
347 widget that *doesn't* handle the Return key has the input
349 dlg_set_activate(filter_entry, start_button);
351 /* Catch the "key_press_event" signal in the window, so that we can
352 catch the ESC key being pressed and act as if the "Cancel" button
353 had been selected. */
354 dlg_set_cancel(dlg, cancel_button);
356 /* Give the initial focus to the "Filter" entry box. */
357 gtk_widget_grab_focus(filter_entry);
359 gtk_widget_show_all(dlg);
363 register_tap_listener_gtksmbstat(void)
365 register_ethereal_tap("smb,srt", gtk_smbstat_init);
369 register_tap_menu_gtksmbstat(void)
371 register_tap_menu_item("Statistics/Service Response Time/SMB...",
372 gtk_smbstat_cb, NULL, NULL);