1 /* conversation_table.h
2 * GUI independent helper routines common to all conversations taps.
3 * Refactored original conversations_table by Ronnie Sahlberg
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.
24 #ifndef __CONVERSATION_TABLE_H__
25 #define __CONVERSATION_TABLE_H__
32 #endif /* __cplusplus */
35 * Conversation definitions.
47 /* Filter direction */
52 CONV_DIR_A_TO_FROM_ANY,
55 CONV_DIR_ANY_TO_FROM_B,
60 /** Conversation hash + value storage
61 * Hash table keys are conv_key_t. Hash table values are indexes into conv_array.
63 typedef struct _conversation_hash_t {
64 GHashTable *hashtable; /**< conversations hash table */
65 GArray *conv_array; /**< array of conversation values */
66 void *user_data; /**< "GUI" specifics (if necessary) */
69 /** Key for hash lookups */
70 typedef struct _conversation_key_t {
83 struct _conversation_item_t;
84 typedef const char* (*conv_get_filter_type)(struct _conversation_item_t* item, conv_filter_type_e filter);
86 typedef struct _ct_dissector_info {
87 conv_get_filter_type get_filter_type;
88 } ct_dissector_info_t;
90 struct _hostlist_talker_t;
91 typedef const char* (*host_get_filter_type)(struct _hostlist_talker_t* item, conv_filter_type_e filter_type);
93 typedef struct _hostlist_dissector_info {
94 host_get_filter_type get_filter_type;
95 } hostlist_dissector_info_t;
97 #define CONV_FILTER_INVALID "INVALID"
101 typedef void (*conv_gui_init_cb)(struct register_ct* ct, const char *filter);
103 typedef void (*host_gui_init_cb)(struct register_ct* host, const char *filter);
105 /** Structure for information about a registered conversation */
106 typedef struct register_ct register_ct_t;
108 /** Conversation information */
109 typedef struct _conversation_item_t {
110 ct_dissector_info_t *dissector_info; /**< conversation information provided by dissector */
111 address src_address; /**< source address */
112 address dst_address; /**< destination address */
113 port_type ptype; /**< port_type (e.g. PT_TCP) */
114 guint32 src_port; /**< source port */
115 guint32 dst_port; /**< destination port */
116 conv_id_t conv_id; /**< conversation id */
118 guint64 rx_frames; /**< number of received packets */
119 guint64 tx_frames; /**< number of transmitted packets */
120 guint64 rx_bytes; /**< number of received bytes */
121 guint64 tx_bytes; /**< number of transmitted bytes */
123 nstime_t start_time; /**< relative start time for the conversation */
124 nstime_t stop_time; /**< relative stop time for the conversation */
125 nstime_t start_abs_time; /**< absolute start time for the conversation */
127 gboolean modified; /**< new to redraw the row (only used in GTK+) */
130 /** Hostlist information */
131 typedef struct _hostlist_talker_t {
132 hostlist_dissector_info_t *dissector_info; /**< conversation information provided by dissector */
133 address myaddress; /**< address */
134 port_type ptype; /**< port_type (e.g. PT_TCP) */
135 guint32 port; /**< port */
137 guint64 rx_frames; /**< number of received packets */
138 guint64 tx_frames; /**< number of transmitted packets */
139 guint64 rx_bytes; /**< number of received bytes */
140 guint64 tx_bytes; /**< number of transmitted bytes */
142 gboolean modified; /**< new to redraw the row */
146 #define HOSTLIST_TAP_PREFIX "endpoints"
148 /** Register the conversation table for the conversation and endpoint windows.
150 * @param proto_id is the protocol with conversation
151 * @param hide_ports hide the port columns
152 * @param conv_packet_func the registered conversation tap name
153 * @param hostlist_func the registered hostlist tap name
155 extern void register_conversation_table(const int proto_id, gboolean hide_ports, tap_packet_cb conv_packet_func, tap_packet_cb hostlist_func);
157 /** Should port columns be hidden?
159 * @param ct Registered conversation
160 * @return TRUE if port columns should be hidden for this conversation type.
162 WS_DLL_PUBLIC gboolean get_conversation_hide_ports(register_ct_t* ct);
164 /** Get protocol ID from conversation
166 * @param ct Registered conversation
167 * @return protocol id of conversation
169 WS_DLL_PUBLIC int get_conversation_proto_id(register_ct_t* ct);
171 /** Get tap function handler from conversation
173 * @param ct Registered conversation
174 * @return tap function handler of conversation
176 WS_DLL_PUBLIC tap_packet_cb get_conversation_packet_func(register_ct_t* ct);
178 /** Get tap function handler from hostlist
180 * @param ct Registered conversation
181 * @return tap function handler of conversation
183 WS_DLL_PUBLIC tap_packet_cb get_hostlist_packet_func(register_ct_t* ct);
185 /** get conversation from protocol ID
187 * @param proto_id protocol ID
188 * @return tap function handler of conversation
190 WS_DLL_PUBLIC register_ct_t* get_conversation_by_proto_id(int proto_id);
192 /** Register "initialization function" used by the GUI to create conversation
193 * table display in GUI
195 * @param init_cb callback function that will be called when converation table "display
196 * is instantiated in GUI
198 WS_DLL_PUBLIC void conversation_table_set_gui_info(conv_gui_init_cb init_cb);
200 /** Register "initialization function" used by the GUI to create hostlist
201 * table display in GUI
203 * @param init_cb callback function that will be called when hostlist "display"
204 * is instantiated in GUI
206 WS_DLL_PUBLIC void hostlist_table_set_gui_info(host_gui_init_cb init_cb);
208 /** Interator to walk converation tables and execute func
209 * a GUI menu (only used in GTK)
211 * @param func action to be performed on all converation tables
212 * @param user_data any data needed to help perform function
214 WS_DLL_PUBLIC void conversation_table_iterate_tables(GFunc func, gpointer user_data);
216 /** Total number of converation tables
218 WS_DLL_PUBLIC guint conversation_table_get_num(void);
220 /** Get conversation table by its number
221 * Tables are ordered alphabetically by title.
223 * @param table_num Item to fetch.
224 * @return table pointer or NULL.
226 WS_DLL_PUBLIC register_ct_t* get_conversation_table_by_num(guint table_num);
228 /** Remove all entries from the conversation table.
230 * @param ch the table to reset
232 WS_DLL_PUBLIC void reset_conversation_table_data(conv_hash_t *ch);
234 /** Remove all entries from the hostlist table.
236 * @param ch the table to reset
238 WS_DLL_PUBLIC void reset_hostlist_table_data(conv_hash_t *ch);
240 /** Initialize dissector conversation for stats and (possibly) GUI.
242 * @param opt_arg filter string to compare with dissector
243 * @param userdata register_ct_t* for dissector conversation
245 WS_DLL_PUBLIC void dissector_conversation_init(const char *opt_arg, void* userdata);
247 /** Initialize dissector hostlist for stats and (possibly) GUI.
249 * @param opt_arg filter string to compare with dissector
250 * @param userdata register_ct_t* for dissector conversation
252 WS_DLL_PUBLIC void dissector_hostlist_init(const char *opt_arg, void* userdata);
254 /** Get the string representation of an address.
256 * @param allocator The wmem allocator to use when allocating the string
257 * @param addr The address.
258 * @param resolve_names Enable name resolution.
259 * @return A string representing the address.
261 WS_DLL_PUBLIC char *get_conversation_address(wmem_allocator_t *allocator, address *addr, gboolean resolve_names);
263 /** Get the string representation of a port.
265 * @param allocator The wmem allocator to use when allocating the string
266 * @param port The port number.
267 * @param ptype The port type.
268 * @param resolve_names Enable name resolution.
269 * @return A string representing the port.
271 WS_DLL_PUBLIC char *get_conversation_port(wmem_allocator_t *allocator, guint32 port, port_type ptype, gboolean resolve_names);
273 /** Get a display filter for the given conversation and direction.
275 * @param conv_item The conversation.
276 * @param direction The desired direction.
277 * @return An g_allocated string representing the conversation that must be freed
279 WS_DLL_PUBLIC char *get_conversation_filter(conv_item_t *conv_item, conv_direction_e direction);
281 /** Get a display filter for the given hostlist.
283 * @param host The hostlist.
284 * @return A string, allocated using the wmem NULL allocator,
285 * representing the conversation.
287 WS_DLL_PUBLIC char *get_hostlist_filter(hostlist_talker_t *host);
289 /** Add some data to the conversation table.
291 * @param ch the table to add the data to
292 * @param src source address
293 * @param dst destination address
294 * @param src_port source port
295 * @param dst_port destination port
296 * @param num_frames number of packets
297 * @param num_bytes number of bytes
298 * @param ts timestamp
299 * @param abs_ts absolute timestamp
300 * @param ct_info callback handlers from the dissector
301 * @param ptype the port type (e.g. PT_TCP)
303 extern void add_conversation_table_data(conv_hash_t *ch, const address *src, const address *dst,
304 guint32 src_port, guint32 dst_port, int num_frames, int num_bytes, nstime_t *ts, nstime_t *abs_ts,
305 ct_dissector_info_t *ct_info, port_type ptype);
307 /** Add some data to the conversation table, passing a value to be used in
308 * addition to the address and port quadruple to uniquely identify the
311 * @param ch the table to add the data to
312 * @param src source address
313 * @param dst destination address
314 * @param src_port source port
315 * @param dst_port destination port
316 * @param num_frames number of packets
317 * @param num_bytes number of bytes
318 * @param ts timestamp
319 * @param abs_ts absolute timestamp
320 * @param ct_info callback handlers from the dissector
321 * @param ptype the port type (e.g. PT_TCP)
322 * @param conv_id a value to help differentiate the conversation in case the address and port quadruple is not sufficiently unique
325 add_conversation_table_data_with_conv_id(conv_hash_t *ch, const address *src, const address *dst, guint32 src_port,
326 guint32 dst_port, conv_id_t conv_id, int num_frames, int num_bytes,
327 nstime_t *ts, nstime_t *abs_ts, ct_dissector_info_t *ct_info, port_type ptype);
329 /** Add some data to the table.
331 * @param ch the table hash to add the data to
332 * @param addr address
334 * @param sender TRUE, if this is a sender
335 * @param num_frames number of packets
336 * @param num_bytes number of bytes
337 * @param host_info conversation information provided by dissector
338 * @param port_type_val the port type (e.g. PT_TCP)
340 void add_hostlist_table_data(conv_hash_t *ch, const address *addr,
341 guint32 port, gboolean sender, int num_frames, int num_bytes, hostlist_dissector_info_t *host_info, port_type port_type_val);
345 #endif /* __cplusplus */
347 #endif /* __CONVERSATION_TABLE_H__ */
355 * indent-tabs-mode: nil
358 * ex: set shiftwidth=4 tabstop=8 expandtab:
359 * :indentSize=4:tabSize=8:noTabs=true: