2 * camel message counter for Wireshark
3 * Copyright 2006 Florent Drouin (based on h225_counter.c from Lars Roland)
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
35 #include "epan/packet_info.h"
36 #include "epan/epan.h"
37 #include "epan/value_string.h"
41 #include "timestats.h"
42 #include "simple_dialog.h"
45 #include "stat_menu.h"
46 #include "tap_dfilter_dlg.h"
49 #include "gtk/dlg_utils.h"
50 #include "gtk/gui_utils.h"
51 #include "gtk/gui_stat_util.h"
52 #include "gtk/compat_macros.h"
53 #include "epan/camel-persistentdata.h"
55 static void gtk_camelcounter_reset(void *phs);
56 static int gtk_camelcounter_packet(void *phs,
57 packet_info *pinfo _U_,
58 epan_dissect_t *edt _U_,
60 static void gtk_camelcounter_draw(void *phs);
61 static void win_destroy_cb(GtkWindow *win _U_, gpointer data);
62 static void gtk_camelcounter_init(const char *optarg, void *userdata _U_);
63 void register_tap_listener_gtk_camelcounter(void);
65 /* following values represent the size of their valuestring arrays */
67 struct camelcounter_t {
71 GtkWidget *scrolled_window;
73 guint32 camel_msg[camel_MAX_NUM_OPR_CODES];
76 static void gtk_camelcounter_reset(void *phs)
78 struct camelcounter_t * p_counter= ( struct camelcounter_t *) phs;
81 /* Erase Message Type count */
82 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
83 p_counter->camel_msg[i]=0;
89 * If there is a valid camel operation, increase the value in the array of counter
91 static int gtk_camelcounter_packet(void *phs,
92 packet_info *pinfo _U_,
93 epan_dissect_t *edt _U_,
96 struct camelcounter_t * p_counter =(struct camelcounter_t *)phs;
97 const struct camelsrt_info_t * pi=phi;
98 if (pi->opcode != 255)
99 p_counter->camel_msg[pi->opcode]++;
104 static void gtk_camelcounter_draw(void *phs)
106 struct camelcounter_t *p_counter=(struct camelcounter_t *)phs;
111 str[i]=g_malloc(sizeof(char[256]));
113 /* Now print Message and Reason Counter Table */
114 /* clear list before printing */
115 gtk_clist_clear(p_counter->table);
117 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
118 /* Message counter */
119 if(p_counter->camel_msg[i]!=0) {
120 g_snprintf(str[0], sizeof(char[256]),
121 "Request %s", val_to_str(i,camel_opr_code_strings,"Unknown message "));
122 g_snprintf(str[1], sizeof(char[256]),
123 "%d", p_counter->camel_msg[i]);
124 gtk_clist_append(p_counter->table, str);
127 gtk_widget_show(GTK_WIDGET(p_counter->table));
130 void protect_thread_critical_region(void);
131 void unprotect_thread_critical_region(void);
133 static void win_destroy_cb(GtkWindow *win _U_, gpointer data)
135 struct camelcounter_t *hs=(struct camelcounter_t *)data;
137 protect_thread_critical_region();
138 remove_tap_listener(hs);
139 unprotect_thread_critical_region();
148 static const gchar *titles[]={
149 "Message Type or Reason",
152 static void gtk_camelcounter_init(const char *optarg, void *userdata _U_)
154 struct camelcounter_t *p_camelcounter;
155 const char *filter=NULL;
156 const char *emptyfilter="";
157 GString *error_string;
161 if(strncmp(optarg,"camel,counter,",14) == 0){
167 p_camelcounter=g_malloc(sizeof(struct camelcounter_t));
168 p_camelcounter->filter=g_strdup(filter);
170 gtk_camelcounter_reset(p_camelcounter);
172 p_camelcounter->win=window_new(GTK_WINDOW_TOPLEVEL, "Ethereal: CAMEL counters");
173 gtk_window_set_default_size(GTK_WINDOW(p_camelcounter->win), 500, 300);
175 p_camelcounter->vbox=gtk_vbox_new(FALSE, 3);
176 gtk_container_set_border_width(GTK_CONTAINER(p_camelcounter->vbox), 12);
178 init_main_stat_window(p_camelcounter->win, p_camelcounter->vbox, "CAMEL Messages Counters", filter);
180 /* init a scrolled window*/
181 p_camelcounter->scrolled_window = scrolled_window_new(NULL, NULL);
183 p_camelcounter->table = create_stat_table(p_camelcounter->scrolled_window, p_camelcounter->vbox, 2, titles);
186 error_string=register_tap_listener("CAMEL", p_camelcounter, filter,
187 gtk_camelcounter_reset,
188 gtk_camelcounter_packet,
189 gtk_camelcounter_draw);
191 error_string=register_tap_listener("CAMEL", p_camelcounter, emptyfilter,
192 gtk_camelcounter_reset,
193 gtk_camelcounter_packet,
194 gtk_camelcounter_draw);
198 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
199 g_string_free(error_string, TRUE);
200 g_free(p_camelcounter);
205 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
206 gtk_box_pack_end(GTK_BOX(p_camelcounter->vbox), bbox, FALSE, FALSE, 0);
208 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
209 window_set_cancel_button(p_camelcounter->win, close_bt, window_cancel_button_cb);
211 SIGNAL_CONNECT(p_camelcounter->win, "delete_event", window_delete_event_cb, NULL);
212 SIGNAL_CONNECT(p_camelcounter->win, "destroy", win_destroy_cb, p_camelcounter);
214 gtk_widget_show_all(p_camelcounter->win);
215 window_present(p_camelcounter->win);
217 cf_retap_packets(&cfile, FALSE);
220 static tap_dfilter_dlg camel_counter_dlg = {
221 "CAMEL Messages and Response Status",
223 gtk_camelcounter_init,
227 void /* Next line mandatory */
228 register_tap_listener_gtk_camelcounter(void)
230 register_dfilter_stat(&camel_counter_dlg, "GSM/CAMEL",
231 REGISTER_STAT_GROUP_TELEPHONY);