2 * wsp_stat 2003 Jean-Michel FAYARD
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 /* #define DEBUG do{ printf("%s:%d ",__FILE__,__LINE__);} while(0); */
29 #include <epan/packet.h>
31 #include <epan/dissectors/packet-wsp.h>
33 #include "ui/simple_dialog.h"
35 #include "ui/gtk/gui_utils.h"
36 #include "ui/gtk/dlg_utils.h"
37 #include "ui/gtk/tap_param_dlg.h"
38 #include "ui/gtk/main.h"
41 void register_tap_listener_gtkwspstat(void);
43 /* Used to keep track of the statistics for a specific PDU type */
44 typedef struct _wsp_pdu_t {
49 /* Used to keep track of the statistics for an entire program interface */
50 typedef struct _wsp_stats_t {
56 GtkWidget *grid_pdu_types;
57 GtkWidget *grid_status_code;
58 guint index; /* Number of status codes to display */
61 /* Used to keep track of a single type of status code */
62 typedef struct _wsp_status_code_t {
65 GtkWidget *widget;/* label in which we print the number of packets */
66 wspstat_t *sp; /* entire program interface */
70 wsp_reset_hash(gchar *key _U_ , wsp_status_code_t *data, gpointer ptr _U_)
75 /* Update the entry corresponding to the number of packets of a special status code
76 * or create it if it doesn't exist.
79 wsp_draw_statuscode(gchar *key _U_, wsp_status_code_t *data, gchar *unused _U_)
81 char string_buff[256];
83 if ((data == NULL) || (data->packets == 0))
85 if (data->widget == NULL) { /* create an entry in the table */
87 int x = 2 * ((data->sp->index) % 2);
88 int y = (data->sp->index) / 2;
91 /* Maybe we should display the hexadecimal value ? */
92 /* g_snprintf(string_buff, sizeof(string_buff), "%s (0X%x)", data->name, *key); */
93 tmp = gtk_label_new(data->name /* string_buff */ );
94 ws_gtk_grid_attach_defaults(GTK_GRID(data->sp->grid_status_code), tmp, x, y, 1, 1);
95 gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT);
98 g_snprintf(string_buff, sizeof(string_buff), "%9d", data->packets);
99 data->widget = gtk_label_new(string_buff);
100 ws_gtk_grid_attach_defaults(GTK_GRID(data->sp->grid_status_code), data->widget, x+1, y, 1, 1);
101 gtk_label_set_justify(GTK_LABEL(data->widget), GTK_JUSTIFY_LEFT);
102 gtk_widget_show(data->widget);
106 /* Just update the label string */
107 g_snprintf(string_buff, sizeof(string_buff), "%9d", data->packets);
108 gtk_label_set_text(GTK_LABEL(data->widget), string_buff);
112 wspstat_reset(void *psp)
114 wspstat_t *sp = (wspstat_t *)psp;
117 for(i=1; i<=sp->num_pdus; i++)
119 sp->pdu_stats[i].packets = 0;
121 g_hash_table_foreach(sp->hash, (GHFunc)wsp_reset_hash, NULL);
124 /* Fixme: !! Magic !! */
125 /* See wsp_vals_pdu_type in packet-wsp.c */
127 pdut2index(gint pdut)
134 } else if ((pdut == 0x60) || (pdut == 0x61)) {
141 /* Fixme: !! Magic !! */
142 /* See wsp_vals_pdu_type in packet-wsp.c */
144 index2pdut(gint pdut)
156 wspstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
158 wspstat_t *sp = (wspstat_t *)psp;
159 const wsp_info_value_t *value = (const wsp_info_value_t *)pri;
160 gint idx = pdut2index(value->pdut);
161 gboolean retour = FALSE;
163 if (value->status_code != 0) {
164 wsp_status_code_t *sc;
165 sc = (wsp_status_code_t *)g_hash_table_lookup(
167 GINT_TO_POINTER(value->status_code));
169 g_warning("%s:%d What's Wrong, doc ?\n", __FILE__, __LINE__);
170 sc = (wsp_status_code_t *)g_malloc(sizeof(wsp_status_code_t));
177 GINT_TO_POINTER(value->status_code),
188 sp->pdu_stats[idx].packets++;
197 wspstat_draw(void *psp)
199 wspstat_t *sp = (wspstat_t *)psp;
203 for(i=1; i<=sp->num_pdus; i++)
205 g_snprintf(str, sizeof(str), "%9d", sp->pdu_stats[i].packets);
206 gtk_label_set_text(GTK_LABEL(sp->pdu_stats[i].widget), str);
209 g_hash_table_foreach(sp->hash, (GHFunc)wsp_draw_statuscode, NULL);
213 win_destroy_cb(GtkWindow *win _U_, gpointer data)
215 wspstat_t *sp = (wspstat_t *)data;
217 remove_tap_listener(sp);
219 g_free(sp->pdu_stats);
221 g_hash_table_destroy(sp->hash);
226 add_table_entry(wspstat_t *sp, const char *str, int x, int y, int idx)
230 tmp = gtk_label_new(str);
231 ws_gtk_grid_attach_defaults(GTK_GRID(sp->grid_pdu_types), tmp, x, y, 1, 1);
232 gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT);
233 gtk_widget_show(tmp);
235 sp->pdu_stats[idx].widget = GTK_LABEL(tmp);
241 wsp_init_table(wspstat_t *sp)
245 /* gchar buffer[51]; */
247 add_table_entry(sp, "PDU Type ", 0, pos, 0);
248 add_table_entry(sp, "packets " , 1, pos, 0);
249 add_table_entry(sp, "PDU Type ", 2, pos, 0);
250 add_table_entry(sp, "packets " , 3, pos, 0);
252 for (i=1; i<=sp->num_pdus ;i++)
255 if (i > (sp->num_pdus+1) / 2) {
258 /* Maybe we should display the hexadecimal value ? */
260 g_snprintf(buffer, sizeof(buffer), "%s (0X%x)",
261 try_val_to_str_ext(index2pdut(i), &wsp_vals_pdu_type_ext), index2pdut(i));
264 try_val_to_str_ext(index2pdut(i), &wsp_vals_pdu_type_ext), /* or buffer, */
273 i /* keep a pointer to this widget to update it in _draw() */
276 if (i == (sp->num_pdus+1) / 2) {
282 /* When called, this function will create a new instance of gtk2-wspstat.
285 gtk_wspstat_init(const char *opt_arg, void *userdata _U_)
290 GString *error_string;
291 GtkWidget *main_vb, *pdutypes_fr, *statuscode_fr ;
295 wsp_status_code_t *sc;
296 const value_string *wsp_vals_status_p;
298 if (strncmp(opt_arg, "wsp,stat,", 9) == 0) {
304 sp = (wspstat_t *)g_malloc(sizeof(wspstat_t));
305 sp->win = dlg_window_new("wsp-stat"); /* transient_for top_level */
306 gtk_window_set_destroy_with_parent(GTK_WINDOW(sp->win), TRUE);
308 sp->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
309 wsp_vals_status_p = VALUE_STRING_EXT_VS_P(&wsp_vals_status_ext);
310 for (i=0; wsp_vals_status_p[i].strptr; i++)
312 sc = (wsp_status_code_t *)g_malloc(sizeof(wsp_status_code_t));
313 sc->name = wsp_vals_status_p[i].strptr;
319 GINT_TO_POINTER(wsp_vals_status_p[i].value),
323 sp->pdu_stats = (wsp_pdu_t *)g_malloc((sp->num_pdus+1) * sizeof(wsp_pdu_t));
325 sp->filter = g_strdup(filter);
326 title = g_strdup_printf("Wireshark: WAP-WSP statistics with filter: %s", filter);
329 title = g_strdup("Wireshark: WAP-WSP statistics");
331 for (i=0; i<=sp->num_pdus; i++)
333 sp->pdu_stats[i].packets = 0;
336 gtk_window_set_title(GTK_WINDOW(sp->win), title);
339 /* container for the two frames */
340 main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
341 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 12);
342 gtk_container_add(GTK_CONTAINER(sp->win), main_vb);
344 /* PDU Types frame */
345 pdutypes_fr = gtk_frame_new("Summary of PDU Types (wsp.pdu_type)");
346 gtk_box_pack_start(GTK_BOX(main_vb), pdutypes_fr, TRUE, TRUE, 0);
348 sp->grid_pdu_types = ws_gtk_grid_new();
349 gtk_container_add(GTK_CONTAINER(pdutypes_fr), sp->grid_pdu_types);
350 gtk_container_set_border_width(GTK_CONTAINER(sp->grid_pdu_types), 10);
354 /* Status Codes frame */
355 statuscode_fr = gtk_frame_new("Summary of Status Code (wsp.reply.status)");
356 gtk_box_pack_start(GTK_BOX(main_vb), statuscode_fr, FALSE, FALSE, 0);
358 sp->grid_status_code = ws_gtk_grid_new();
359 gtk_container_add(GTK_CONTAINER(statuscode_fr), sp->grid_status_code);
360 gtk_container_set_border_width(GTK_CONTAINER(sp->grid_status_code), 10);
361 sp->index = 0; /* No answers to display yet */
363 error_string = register_tap_listener(
372 /* error, we failed to attach to the tap. clean up */
373 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
374 g_free(sp->pdu_stats);
377 g_string_free(error_string, TRUE);
382 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
383 gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
385 bt_close = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
386 window_set_cancel_button(sp->win, bt_close, window_cancel_button_cb);
388 g_signal_connect(sp->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
389 g_signal_connect(sp->win, "destroy", G_CALLBACK(win_destroy_cb), sp);
391 gtk_widget_show_all(sp->win);
392 window_present(sp->win);
394 cf_retap_packets(&cfile);
395 gdk_window_raise(gtk_widget_get_window(sp->win));
398 static tap_param wsp_stat_params[] = {
399 { PARAM_FILTER, "filter", "Filter", NULL, TRUE }
402 static tap_param_dlg wsp_stat_dlg = {
403 "WAP-WSP Packet Counter",
407 G_N_ELEMENTS(wsp_stat_params),
413 register_tap_listener_gtkwspstat(void)
415 register_param_stat(&wsp_stat_dlg, "_WAP-WSP",
416 REGISTER_STAT_GROUP_TELEPHONY);
420 * Editor modelines - http://www.wireshark.org/tools/modelines.html
425 * indent-tabs-mode: t
428 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
429 * :indentSize=8:tabSize=8:noTabs=false: