2 * wsp_stat 2003 Jean-Michel FAYARD
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 /* #define DEBUG do{ printf("%s:%d ",__FILE__,__LINE__);} while(0); */
31 #include <epan/packet.h>
33 #include <epan/dissectors/packet-wsp.h>
35 #include "ui/simple_dialog.h"
36 #include "../globals.h"
37 #include "../stat_menu.h"
39 #include "ui/gtk/gui_utils.h"
40 #include "ui/gtk/dlg_utils.h"
41 #include "ui/gtk/tap_param_dlg.h"
42 #include "ui/gtk/main.h"
44 #include "ui/gtk/old-gtk-compat.h"
46 /* Used to keep track of the statistics for a specific PDU type */
47 typedef struct _wsp_pdu_t
{
52 /* Used to keep track of the statistics for an entire program interface */
53 typedef struct _wsp_stats_t
{
59 GtkWidget
*grid_pdu_types
;
60 GtkWidget
*grid_status_code
;
61 guint index
; /* Number of status codes to display */
64 /* Used to keep track of a single type of status code */
65 typedef struct _wsp_status_code_t
{
68 GtkWidget
*widget
;/* label in which we print the number of packets */
69 wspstat_t
*sp
; /* entire program interface */
73 wsp_reset_hash(gchar
*key _U_
, wsp_status_code_t
*data
, gpointer ptr _U_
)
78 /* Update the entry corresponding to the number of packets of a special status code
79 * or create it if it doesn't exist.
82 wsp_draw_statuscode(gchar
*key _U_
, wsp_status_code_t
*data
, gchar
*unused _U_
)
84 char string_buff
[256];
86 if ((data
== NULL
) || (data
->packets
== 0))
88 if (data
->widget
== NULL
) { /* create an entry in the table */
90 int x
= 2 * ((data
->sp
->index
) % 2);
91 int y
= (data
->sp
->index
) / 2;
94 /* Maybe we should display the hexadecimal value ? */
95 /* g_snprintf(string_buff, sizeof(string_buff), "%s (0X%x)", data->name, *key); */
96 tmp
= gtk_label_new(data
->name
/* string_buff */ );
97 ws_gtk_grid_attach_defaults(GTK_GRID(data
->sp
->grid_status_code
), tmp
, x
, y
, 1, 1);
98 gtk_label_set_justify(GTK_LABEL(tmp
), GTK_JUSTIFY_LEFT
);
101 g_snprintf(string_buff
, sizeof(string_buff
), "%9d", data
->packets
);
102 data
->widget
= gtk_label_new(string_buff
);
103 ws_gtk_grid_attach_defaults(GTK_GRID(data
->sp
->grid_status_code
), data
->widget
, x
+1, y
, 1, 1);
104 gtk_label_set_justify(GTK_LABEL(data
->widget
), GTK_JUSTIFY_LEFT
);
105 gtk_widget_show(data
->widget
);
109 /* Just update the label string */
110 g_snprintf(string_buff
, sizeof(string_buff
), "%9d", data
->packets
);
111 gtk_label_set_text(GTK_LABEL(data
->widget
), string_buff
);
115 wspstat_reset(void *psp
)
117 wspstat_t
*sp
= (wspstat_t
*)psp
;
120 for(i
=1; i
<=sp
->num_pdus
; i
++)
122 sp
->pdu_stats
[i
].packets
= 0;
124 g_hash_table_foreach(sp
->hash
, (GHFunc
)wsp_reset_hash
, NULL
);
127 /* Fixme: !! Magic !! */
128 /* See wsp_vals_pdu_type in packet-wsp.c */
130 pdut2index(gint pdut
)
137 } else if ((pdut
== 0x60) || (pdut
== 0x61)) {
144 /* Fixme: !! Magic !! */
145 /* See wsp_vals_pdu_type in packet-wsp.c */
147 index2pdut(gint pdut
)
159 wspstat_packet(void *psp
, packet_info
*pinfo _U_
, epan_dissect_t
*edt _U_
, const void *pri
)
161 wspstat_t
*sp
= (wspstat_t
*)psp
;
162 const wsp_info_value_t
*value
= (wsp_info_value_t
*)pri
;
163 gint idx
= pdut2index(value
->pdut
);
164 gboolean retour
= FALSE
;
166 if (value
->status_code
!= 0) {
167 wsp_status_code_t
*sc
;
168 sc
= (wsp_status_code_t
*)g_hash_table_lookup(
170 GINT_TO_POINTER(value
->status_code
));
172 g_warning("%s:%d What's Wrong, doc ?\n", __FILE__
, __LINE__
);
173 sc
= (wsp_status_code_t
*)g_malloc(sizeof(wsp_status_code_t
));
180 GINT_TO_POINTER(value
->status_code
),
191 sp
->pdu_stats
[idx
].packets
++;
200 wspstat_draw(void *psp
)
202 wspstat_t
*sp
= (wspstat_t
*)psp
;
206 for(i
=1; i
<=sp
->num_pdus
; i
++)
208 g_snprintf(str
, sizeof(str
), "%9d", sp
->pdu_stats
[i
].packets
);
209 gtk_label_set_text(GTK_LABEL(sp
->pdu_stats
[i
].widget
), str
);
212 g_hash_table_foreach(sp
->hash
, (GHFunc
)wsp_draw_statuscode
, NULL
);
216 win_destroy_cb(GtkWindow
*win _U_
, gpointer data
)
218 wspstat_t
*sp
= (wspstat_t
*)data
;
220 remove_tap_listener(sp
);
222 g_free(sp
->pdu_stats
);
224 g_hash_table_destroy(sp
->hash
);
229 add_table_entry(wspstat_t
*sp
, const char *str
, int x
, int y
, int idx
)
233 tmp
= gtk_label_new(str
);
234 ws_gtk_grid_attach_defaults(GTK_GRID(sp
->grid_pdu_types
), tmp
, x
, y
, 1, 1);
235 gtk_label_set_justify(GTK_LABEL(tmp
), GTK_JUSTIFY_LEFT
);
236 gtk_widget_show(tmp
);
238 sp
->pdu_stats
[idx
].widget
= GTK_LABEL(tmp
);
244 wsp_init_table(wspstat_t
*sp
)
248 /* gchar buffer[51]; */
250 add_table_entry(sp
, "PDU Type ", 0, pos
, 0);
251 add_table_entry(sp
, "packets " , 1, pos
, 0);
252 add_table_entry(sp
, "PDU Type ", 2, pos
, 0);
253 add_table_entry(sp
, "packets " , 3, pos
, 0);
255 for (i
=1; i
<=sp
->num_pdus
;i
++)
258 if (i
> (sp
->num_pdus
+1) / 2) {
261 /* Maybe we should display the hexadecimal value ? */
263 g_snprintf(buffer
, sizeof(buffer
), "%s (0X%x)",
264 try_val_to_str_ext(index2pdut(i
), &wsp_vals_pdu_type_ext
), index2pdut(i
));
267 try_val_to_str_ext(index2pdut(i
), &wsp_vals_pdu_type_ext
), /* or buffer, */
276 i
/* keep a pointer to this widget to update it in _draw() */
279 if (i
== (sp
->num_pdus
+1) / 2) {
285 /* When called, this function will create a new instance of gtk2-wspstat.
288 gtk_wspstat_init(const char *opt_arg
, void *userdata _U_
)
293 GString
*error_string
;
294 GtkWidget
*main_vb
, *pdutypes_fr
, *statuscode_fr
;
298 wsp_status_code_t
*sc
;
299 const value_string
*wsp_vals_status_p
;
301 if (strncmp(opt_arg
, "wsp,stat,", 9) == 0) {
307 sp
= (wspstat_t
*)g_malloc(sizeof(wspstat_t
));
308 sp
->win
= dlg_window_new("wsp-stat"); /* transient_for top_level */
309 gtk_window_set_destroy_with_parent(GTK_WINDOW(sp
->win
), TRUE
);
311 sp
->hash
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
, NULL
, g_free
);
312 wsp_vals_status_p
= VALUE_STRING_EXT_VS_P(&wsp_vals_status_ext
);
313 for (i
=0; wsp_vals_status_p
[i
].strptr
; i
++)
315 sc
= (wsp_status_code_t
*)g_malloc(sizeof(wsp_status_code_t
));
316 sc
->name
= wsp_vals_status_p
[i
].strptr
;
322 GINT_TO_POINTER(wsp_vals_status_p
[i
].value
),
326 sp
->pdu_stats
= (wsp_pdu_t
*)g_malloc((sp
->num_pdus
+1) * sizeof(wsp_pdu_t
));
328 sp
->filter
= g_strdup(filter
);
329 title
= g_strdup_printf("Wireshark: WAP-WSP statistics with filter: %s", filter
);
332 title
= g_strdup("Wireshark: WAP-WSP statistics");
334 for (i
=0; i
<=sp
->num_pdus
; i
++)
336 sp
->pdu_stats
[i
].packets
= 0;
339 gtk_window_set_title(GTK_WINDOW(sp
->win
), title
);
342 /* container for the two frames */
343 main_vb
= ws_gtk_box_new(GTK_ORIENTATION_VERTICAL
, 3, FALSE
);
344 gtk_container_set_border_width(GTK_CONTAINER(main_vb
), 12);
345 gtk_container_add(GTK_CONTAINER(sp
->win
), main_vb
);
347 /* PDU Types frame */
348 pdutypes_fr
= gtk_frame_new("Summary of PDU Types (wsp.pdu_type)");
349 gtk_box_pack_start(GTK_BOX(main_vb
), pdutypes_fr
, TRUE
, TRUE
, 0);
351 sp
->grid_pdu_types
= ws_gtk_grid_new();
352 gtk_container_add(GTK_CONTAINER(pdutypes_fr
), sp
->grid_pdu_types
);
353 gtk_container_set_border_width(GTK_CONTAINER(sp
->grid_pdu_types
), 10);
357 /* Status Codes frame */
358 statuscode_fr
= gtk_frame_new("Summary of Status Code (wsp.reply.status)");
359 gtk_box_pack_start(GTK_BOX(main_vb
), statuscode_fr
, FALSE
, FALSE
, 0);
361 sp
->grid_status_code
= ws_gtk_grid_new();
362 gtk_container_add(GTK_CONTAINER(statuscode_fr
), sp
->grid_status_code
);
363 gtk_container_set_border_width(GTK_CONTAINER(sp
->grid_status_code
), 10);
364 sp
->index
= 0; /* No answers to display yet */
366 error_string
= register_tap_listener(
375 /* error, we failed to attach to the tap. clean up */
376 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
, "%s", error_string
->str
);
377 g_free(sp
->pdu_stats
);
380 g_string_free(error_string
, TRUE
);
385 bbox
= dlg_button_row_new(GTK_STOCK_CLOSE
, NULL
);
386 gtk_box_pack_start(GTK_BOX(main_vb
), bbox
, FALSE
, FALSE
, 0);
388 bt_close
= (GtkWidget
*)g_object_get_data(G_OBJECT(bbox
), GTK_STOCK_CLOSE
);
389 window_set_cancel_button(sp
->win
, bt_close
, window_cancel_button_cb
);
391 g_signal_connect(sp
->win
, "delete_event", G_CALLBACK(window_delete_event_cb
), NULL
);
392 g_signal_connect(sp
->win
, "destroy", G_CALLBACK(win_destroy_cb
), sp
);
394 gtk_widget_show_all(sp
->win
);
395 window_present(sp
->win
);
397 cf_retap_packets(&cfile
);
398 gdk_window_raise(gtk_widget_get_window(sp
->win
));
401 static tap_param wsp_stat_params
[] = {
402 { PARAM_FILTER
, "Filter", NULL
}
405 static tap_param_dlg wsp_stat_dlg
= {
406 "WAP-WSP Packet Counter",
410 G_N_ELEMENTS(wsp_stat_params
),
415 register_tap_listener_gtkwspstat(void)
417 register_param_stat(&wsp_stat_dlg
, "_WAP-WSP",
418 REGISTER_STAT_GROUP_TELEPHONY
);