2 * Helper routines common to all RTD taps.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "packet_info.h"
30 #include "rtd_table.h"
33 int proto_id; /* protocol id (0-indexed) */
34 const char* tap_listen_str; /* string used in register_tap_listener (NULL to use protocol name) */
35 tap_packet_cb rtd_func; /* function to be called for new incoming packets for RTD */
38 const value_string* vs_type;
39 rtd_filter_check_cb filter_check;
42 int get_rtd_proto_id(register_rtd_t* rtd)
50 const char* get_rtd_tap_listener_name(register_rtd_t* rtd)
52 return rtd->tap_listen_str;
55 tap_packet_cb get_rtd_packet_func(register_rtd_t* rtd)
60 guint get_rtd_num_tables(register_rtd_t* rtd) {
61 return rtd->num_tables;
64 const value_string* get_rtd_value_string(register_rtd_t* rtd)
69 static GSList *registered_rtd_tables = NULL;
72 insert_sorted_by_table_name(gconstpointer aparam, gconstpointer bparam)
74 const register_rtd_t *a = (register_rtd_t *)aparam;
75 const register_rtd_t *b = (register_rtd_t *)bparam;
77 return g_ascii_strcasecmp(proto_get_protocol_short_name(find_protocol_by_id(a->proto_id)), proto_get_protocol_short_name(find_protocol_by_id(b->proto_id)));
81 register_rtd_table(const int proto_id, const char* tap_listener, guint num_tables, guint num_timestats, const value_string* vs_type,
82 tap_packet_cb rtd_packet_func, rtd_filter_check_cb filter_check_cb)
84 register_rtd_t *table;
85 DISSECTOR_ASSERT(rtd_packet_func);
87 table = g_new(register_rtd_t,1);
89 table->proto_id = proto_id;
90 if (tap_listener != NULL)
91 table->tap_listen_str = tap_listener;
93 table->tap_listen_str = proto_get_protocol_filter_name(proto_id);
94 table->rtd_func = rtd_packet_func;
95 table->num_tables = num_tables;
96 table->num_timestats = num_timestats;
97 table->vs_type = vs_type;
98 table->filter_check = filter_check_cb;
100 registered_rtd_tables = g_slist_insert_sorted(registered_rtd_tables, table, insert_sorted_by_table_name);
103 void free_rtd_table(rtd_stat_table* table, rtd_gui_free_cb gui_callback, void *callback_data)
107 for (i = 0; i < table->num_rtds; i++)
109 g_free(table->time_stats[i].rtd);
111 g_free(table->time_stats);
112 table->time_stats = NULL;
115 /* Give GUI the first crack at it before we clean up */
117 gui_callback(table, callback_data);
120 void reset_rtd_table(rtd_stat_table* table, rtd_gui_reset_cb gui_callback, void *callback_data)
124 for (i = 0; i < table->num_rtds; i++)
125 memset(table->time_stats[i].rtd, 0, sizeof(timestat_t)*table->time_stats[i].num_timestat);
127 /* Give GUI the first crack at it before we clean up */
129 gui_callback(table, callback_data);
133 register_rtd_t* get_rtd_table_by_name(const char* name)
135 guint i, size = g_slist_length(registered_rtd_tables);
139 for (i = 0; i < size; i++) {
140 slist = g_slist_nth(registered_rtd_tables, i);
141 rtd = (register_rtd_t*)slist->data;
143 if (strcmp(name, proto_get_protocol_filter_name(rtd->proto_id)) == 0)
150 gchar* rtd_table_get_tap_string(register_rtd_t* rtd)
152 GString *cmd_str = g_string_new(proto_get_protocol_filter_name(rtd->proto_id));
153 g_string_append(cmd_str, ",rtd");
154 return g_string_free(cmd_str, FALSE);
157 void rtd_table_get_filter(register_rtd_t* rtd, const char *opt_arg, const char **filter, char** err)
159 gchar* cmd_str = rtd_table_get_tap_string(rtd);
160 guint len = (guint) strlen(cmd_str);
164 if (!strncmp(opt_arg, cmd_str, len))
166 if (opt_arg[len] == ',')
168 *filter = opt_arg + len+1;
172 if (rtd->filter_check)
173 rtd->filter_check(opt_arg, filter, err);
178 void rtd_table_dissector_init(register_rtd_t* rtd, rtd_stat_table* table, rtd_gui_init_cb gui_callback, void *callback_data)
182 table->num_rtds = rtd->num_tables;
183 table->time_stats = g_new0(rtd_timestat, rtd->num_tables);
185 for (i = 0; i < table->num_rtds; i++)
187 table->time_stats[i].num_timestat = rtd->num_timestats;
188 table->time_stats[i].rtd = g_new0(timestat_t, rtd->num_timestats);
192 gui_callback(table, callback_data);
195 void rtd_table_iterate_tables(GFunc func, gpointer user_data)
197 g_slist_foreach(registered_rtd_tables, func, user_data);
206 * indent-tabs-mode: nil
209 * ex: set shiftwidth=4 tabstop=8 expandtab:
210 * :indentSize=4:tabSize=8:noTabs=true: