GSM/ANSI/CAMEL...: fix no previous prototype for '*_stat_init' [-Wmissing-prototypes]
[metze/wireshark/wip.git] / epan / packet.h
1 /* packet.h
2  * Definitions for packet disassembly structures and routines
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef __PACKET_H__
24 #define __PACKET_H__
25
26 #include "proto.h"
27 #include "tvbuff.h"
28 #include "value_string.h"
29 #include "frame_data.h"
30 #include "packet_info.h"
31 #include "column-utils.h"
32 #include "tfs.h"
33 #include "ws_symbol_export.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38
39 struct epan_range;
40
41 /** @defgroup packet General Packet Dissection
42  *
43  * @{
44  */
45
46 #define hi_nibble(b) (((b) & 0xf0) >> 4)
47 #define lo_nibble(b) ((b) & 0x0f)
48
49 /* Useful when you have an array whose size you can tell at compile-time */
50 #define array_length(x) (sizeof x / sizeof x[0])
51
52 /* Check whether the "len" bytes of data starting at "offset" is
53  * entirely inside the captured data for this packet. */
54 #define BYTES_ARE_IN_FRAME(offset, captured_len, len) \
55         ((guint)(offset) + (guint)(len) > (guint)(offset) && \
56          (guint)(offset) + (guint)(len) <= (guint)(captured_len))
57
58 /* To pass one of two strings, singular or plural */
59 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
60
61 typedef struct _packet_counts {
62   gint           sctp;
63   gint           tcp;
64   gint           udp;
65   gint           icmp;
66   gint           ospf;
67   gint           gre;
68   gint           netbios;
69   gint           ipx;
70   gint           vines;
71   gint           other;
72   gint           total;
73   gint           arp;
74   gint           i2c_event;
75   gint           i2c_data;
76 } packet_counts;
77
78 /** Number of packet counts. */
79 #define PACKET_COUNTS_SIZE sizeof(packet_counts) / sizeof (gint)
80
81 extern void packet_init(void);
82 extern void packet_cache_proto_handles(void);
83 extern void packet_cleanup(void);
84
85 /* Handle for dissectors you call directly or register with "dissector_add_uint()".
86    This handle is opaque outside of "packet.c". */
87 struct dissector_handle;
88 typedef struct dissector_handle *dissector_handle_t;
89
90 /* Hash table for matching unsigned integers, or strings, and dissectors;
91    this is opaque outside of "packet.c". */
92 struct dissector_table;
93 typedef struct dissector_table *dissector_table_t;
94
95 /*
96  * Dissector that returns nothing.
97  */
98 typedef void (*dissector_t)(tvbuff_t *, packet_info *, proto_tree *);
99
100 /*
101  * Dissector that returns:
102  *
103  *      The amount of data in the protocol's PDU, if it was able to
104  *      dissect all the data;
105  *
106  *      0, if the tvbuff doesn't contain a PDU for that protocol;
107  *
108  *      The negative of the amount of additional data needed, if
109  *      we need more data (e.g., from subsequent TCP segments) to
110  *      dissect the entire PDU.
111  */
112 typedef int (*new_dissector_t)(tvbuff_t *, packet_info *, proto_tree *, void *);
113
114 /** Type of a heuristic dissector, used in heur_dissector_add().
115  *
116  * @param tvb the tvbuff with the (remaining) packet data
117  * @param pinfo the packet info of this packet (additional info)
118  * @param tree the protocol tree to be build or NULL
119  * @return TRUE if the packet was recognized by the sub-dissector (stop dissection here)
120  */
121 typedef gboolean (*heur_dissector_t)(tvbuff_t *tvb, packet_info *pinfo,
122         proto_tree *tree, void *);
123
124 typedef enum {
125     HEURISTIC_DISABLE,
126     HEURISTIC_ENABLE
127 } heuristic_enable_e;
128
129 typedef void (*DATFunc) (const gchar *table_name, ftenum_t selector_type,
130     gpointer key, gpointer value, gpointer user_data);
131 typedef void (*DATFunc_handle) (const gchar *table_name, gpointer value,
132     gpointer user_data);
133 typedef void (*DATFunc_table) (const gchar *table_name, const gchar *ui_name,
134     gpointer user_data);
135
136 /* Opaque structure - provides type checking but no access to components */
137 typedef struct dtbl_entry dtbl_entry_t;
138
139 WS_DLL_PUBLIC dissector_handle_t dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry);
140 WS_DLL_PUBLIC dissector_handle_t dtbl_entry_get_initial_handle (dtbl_entry_t * entry);
141
142 /** Iterate over dissectors in a table with non-default "decode as" settings.
143  *
144  * Walk one dissector table calling a user supplied function only on
145  * any entry that has been changed from its original state.
146  *
147  * @param[in] table_name The name of the dissector table, e.g. "ip.proto".
148  * @param[in] func The function to call for each dissector.
149  * @param[in] user_data User data to pass to the function.
150  */
151 void dissector_table_foreach_changed (const char *table_name, DATFunc func,
152     gpointer user_data);
153
154 /** Iterate over dissectors in a table.
155  *
156  * Walk one dissector table's hash table calling a user supplied function
157  * on each entry.
158  *
159  * @param[in] table_name The name of the dissector table, e.g. "ip.proto".
160  * @param[in] func The function to call for each dissector.
161  * @param[in] user_data User data to pass to the function.
162  */
163 WS_DLL_PUBLIC void dissector_table_foreach (const char *table_name, DATFunc func,
164     gpointer user_data);
165
166 /** Iterate over dissectors with non-default "decode as" settings.
167  *
168  * Walk all dissector tables calling a user supplied function only on
169  * any "decode as" entry that has been changed from its original state.
170  *
171  * @param[in] func The function to call for each dissector.
172  * @param[in] user_data User data to pass to the function.
173  */
174 WS_DLL_PUBLIC void dissector_all_tables_foreach_changed (DATFunc func,
175     gpointer user_data);
176
177 /** Iterate over dissectors in a table by handle.
178  *
179  * Walk one dissector table's list of handles calling a user supplied
180  * function on each entry.
181  *
182  * @param[in] table_name The name of the dissector table, e.g. "ip.proto".
183  * @param[in] func The function to call for each dissector.
184  * @param[in] user_data User data to pass to the function.
185  */
186 WS_DLL_PUBLIC void dissector_table_foreach_handle(const char *table_name, DATFunc_handle func,
187     gpointer user_data);
188
189 /** Iterate over all dissector tables.
190  *
191  * Walk the set of dissector tables calling a user supplied function on each
192  * table.
193  * @param[in] func The function to call for each table.
194  * @param[in] user_data User data to pass to the function.
195  * @param[in] compare_key_func Function used to sort the set of tables before
196  * calling the function.  No sorting is done if NULL. */
197 WS_DLL_PUBLIC void dissector_all_tables_foreach_table (DATFunc_table func,
198     gpointer user_data, GCompareFunc compare_key_func);
199
200 /* a protocol uses the function to register a sub-dissector table
201  *
202  * 'param' is the display base for integer tables, and TRUE/FALSE for
203  * string tables (true indicating case-insensitive, false indicating
204  * case-sensitive)
205  */
206 WS_DLL_PUBLIC dissector_table_t register_dissector_table(const char *name,
207     const char *ui_name, const ftenum_t type, const int param);
208
209 /*
210  * Similar to register_dissector_table, but with a "custom" hash function
211  * to store subdissectors.
212  */
213 WS_DLL_PUBLIC dissector_table_t register_custom_dissector_table(const char *name,
214     const char *ui_name, GHashFunc hash_func, GEqualFunc key_equal_func);
215
216 /** Deregister the dissector table by table name. */
217 WS_DLL_PUBLIC void deregister_dissector_table(const char *name);
218
219 /* Find a dissector table by table name. */
220 WS_DLL_PUBLIC dissector_table_t find_dissector_table(const char *name);
221
222 /* Get the UI name for a sub-dissector table, given its internal name */
223 WS_DLL_PUBLIC const char *get_dissector_table_ui_name(const char *name);
224
225 /* Get the field type for values of the selector for a dissector table,
226    given the table's internal name */
227 WS_DLL_PUBLIC ftenum_t get_dissector_table_selector_type(const char *name);
228
229 /* Get the param set for the sub-dissector table,
230    given the table's internal name */
231 WS_DLL_PUBLIC int get_dissector_table_param(const char *name);
232
233 /* Dump all dissector tables to the standard output (not the entries,
234    just the information about the tables) */
235 WS_DLL_PUBLIC void dissector_dump_dissector_tables(void);
236
237 /* Add an entry to a uint dissector table. */
238 WS_DLL_PUBLIC void dissector_add_uint(const char *abbrev, const guint32 pattern,
239     dissector_handle_t handle);
240
241 /* Add an range of entries to a uint dissector table. */
242 WS_DLL_PUBLIC void dissector_add_uint_range(const char *abbrev, struct epan_range *range,
243     dissector_handle_t handle);
244
245 /* Delete the entry for a dissector in a uint dissector table
246    with a particular pattern. */
247 WS_DLL_PUBLIC void dissector_delete_uint(const char *name, const guint32 pattern,
248     dissector_handle_t handle);
249
250 /* Delete an range of entries from a uint dissector table. */
251 WS_DLL_PUBLIC void dissector_delete_uint_range(const char *abbrev, struct epan_range *range,
252     dissector_handle_t handle);
253
254 /* Delete all entries from a dissector table. */
255 WS_DLL_PUBLIC void dissector_delete_all(const char *name, dissector_handle_t handle);
256
257 /* Change the entry for a dissector in a uint dissector table
258    with a particular pattern to use a new dissector handle. */
259 WS_DLL_PUBLIC void dissector_change_uint(const char *abbrev, const guint32 pattern,
260     dissector_handle_t handle);
261
262 /* Reset an entry in a uint dissector table to its initial value. */
263 WS_DLL_PUBLIC void dissector_reset_uint(const char *name, const guint32 pattern);
264
265 /* Look for a given value in a given uint dissector table and, if found,
266    call the dissector with the arguments supplied, and return the number
267    of bytes consumed, otherwise return 0. */
268 WS_DLL_PUBLIC int dissector_try_uint(dissector_table_t sub_dissectors,
269     const guint32 uint_val, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
270
271 /* Look for a given value in a given uint dissector table and, if found,
272    call the dissector with the arguments supplied, and return the number
273    of bytes consumed, otherwise return 0. */
274 WS_DLL_PUBLIC int dissector_try_uint_new(dissector_table_t sub_dissectors,
275     const guint32 uint_val, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, const gboolean add_proto_name, void *data);
276
277 /** Look for a given value in a given uint dissector table and, if found,
278  * return the current dissector handle for that value.
279  *
280  * @param[in] sub_dissectors Dissector table to search.
281  * @param[in] uint_val Value to match, e.g. the port number for the TCP dissector.
282  * @return The matching dissector handle on success, NULL if no match is found.
283  */
284 WS_DLL_PUBLIC dissector_handle_t dissector_get_uint_handle(
285     dissector_table_t const sub_dissectors, const guint32 uint_val);
286
287 /** Look for a given value in a given uint dissector table and, if found,
288  * return the default dissector handle for that value.
289  *
290  * @param[in] name Dissector table name.
291  * @param[in] uint_val Value to match, e.g. the port number for the TCP dissector.
292  * @return The matching dissector handle on success, NULL if no match is found.
293  */
294 WS_DLL_PUBLIC dissector_handle_t dissector_get_default_uint_handle(
295     const char *name, const guint32 uint_val);
296
297 /* Add an entry to a string dissector table. */
298 WS_DLL_PUBLIC void dissector_add_string(const char *name, const gchar *pattern,
299     dissector_handle_t handle);
300
301 /* Delete the entry for a dissector in a string dissector table
302    with a particular pattern. */
303 WS_DLL_PUBLIC void dissector_delete_string(const char *name, const gchar *pattern,
304         dissector_handle_t handle);
305
306 /* Change the entry for a dissector in a string dissector table
307    with a particular pattern to use a new dissector handle. */
308 WS_DLL_PUBLIC void dissector_change_string(const char *name, const gchar *pattern,
309     dissector_handle_t handle);
310
311 /* Reset an entry in a string sub-dissector table to its initial value. */
312 WS_DLL_PUBLIC void dissector_reset_string(const char *name, const gchar *pattern);
313
314 /* Look for a given string in a given dissector table and, if found, call
315    the dissector with the arguments supplied, and return the number of
316    bytes consumed, otherwise return 0. */
317 WS_DLL_PUBLIC int dissector_try_string(dissector_table_t sub_dissectors,
318     const gchar *string, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);
319
320 /** Look for a given value in a given string dissector table and, if found,
321  * return the current dissector handle for that value.
322  *
323  * @param[in] sub_dissectors Dissector table to search.
324  * @param[in] string Value to match, e.g. the OID for the BER dissector.
325  * @return The matching dissector handle on success, NULL if no match is found.
326  */
327 WS_DLL_PUBLIC dissector_handle_t dissector_get_string_handle(
328     dissector_table_t sub_dissectors, const gchar *string);
329
330 /** Look for a given value in a given string dissector table and, if found,
331  * return the default dissector handle for that value.
332  *
333  * @param[in] name Dissector table name.
334  * @param[in] string Value to match, e.g. the OID for the BER dissector.
335  * @return The matching dissector handle on success, NULL if no match is found.
336  */
337 WS_DLL_PUBLIC dissector_handle_t dissector_get_default_string_handle(
338     const char *name, const gchar *string);
339
340 /* Add an entry to a "custom" dissector table. */
341 WS_DLL_PUBLIC void dissector_add_custom_table_handle(const char *name, void *pattern,
342     dissector_handle_t handle);
343
344 /** Look for a given key in a given "custom" dissector table and, if found,
345  * return the current dissector handle for that key.
346  *
347  * @param[in] sub_dissectors Dissector table to search.
348  * @param[in] key Value to match, e.g. RPC key for its subdissectors
349  * @return The matching dissector handle on success, NULL if no match is found.
350  */
351 WS_DLL_PUBLIC dissector_handle_t dissector_get_custom_table_handle(
352     dissector_table_t sub_dissectors, void *key);
353
354
355 /* Add a handle to the list of handles that *could* be used with this
356    table.  That list is used by the "Decode As"/"-d" code in the UI. */
357 WS_DLL_PUBLIC void dissector_add_for_decode_as(const char *name,
358     dissector_handle_t handle);
359
360 /* DEPRECATED, do not use in new code, call dissector_add_for_decode_as directly! */
361 #define dissector_add_handle dissector_add_for_decode_as
362
363 /** Get the list of handles for a dissector table
364  */
365 WS_DLL_PUBLIC GSList *dissector_table_get_dissector_handles(dissector_table_t dissector_table);
366
367 /** Get a dissector table's type
368  */
369 WS_DLL_PUBLIC ftenum_t dissector_table_get_type(dissector_table_t dissector_table);
370
371 /* List of "heuristic" dissectors (which get handed a packet, look at it,
372    and either recognize it as being for their protocol, dissect it, and
373    return TRUE, or don't recognize it and return FALSE) to be called
374    by another dissector.
375
376    This is opaque outside of "packet.c". */
377 struct heur_dissector_list;
378 typedef struct heur_dissector_list *heur_dissector_list_t;
379
380
381 typedef struct {
382         heur_dissector_t dissector;
383         protocol_t *protocol; /* this entry's protocol */
384         gchar *list_name;     /* the list name this entry is in the list of */
385         const gchar *display_name;     /* the string used to present heuristic to user */
386         const gchar *short_name;     /* string used for "internal" use to uniquely identify heuristic */
387         gboolean enabled;
388 } heur_dtbl_entry_t;
389
390 /** A protocol uses this function to register a heuristic sub-dissector list.
391  *  Call this in the parent dissectors proto_register function.
392  *
393  * @param name the name of this protocol
394  */
395 WS_DLL_PUBLIC heur_dissector_list_t register_heur_dissector_list(const char *name);
396
397 typedef void (*DATFunc_heur) (const gchar *table_name,
398     heur_dtbl_entry_t *entry, gpointer user_data);
399 typedef void (*DATFunc_heur_table) (const gchar *table_name,
400     heur_dissector_list_t *table, gpointer user_data);
401
402 /** Iterate over heuristic dissectors in a table.
403  *
404  * Walk one heuristic dissector table's list calling a user supplied function
405  * on each entry.
406  *
407  * @param[in] table_name The name of the dissector table, e.g. "tcp".
408  * @param[in] func The function to call for each dissector.
409  * @param[in] user_data User data to pass to the function.
410  */
411 WS_DLL_PUBLIC void heur_dissector_table_foreach(const char *table_name,
412     DATFunc_heur func, gpointer user_data);
413
414 /** Iterate over all heuristic dissector tables.
415  *
416  * Walk the set of heuristic dissector tables calling a user supplied function
417  * on each table.
418  * @param[in] func The function to call for each table.
419  * @param[in] user_data User data to pass to the function.
420  * @param[in] compare_key_func Function used to sort the set of tables before
421  * calling the function.  No sorting is done if NULL. */
422 WS_DLL_PUBLIC void dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
423     gpointer user_data, GCompareFunc compare_key_func);
424
425 /* true if a heur_dissector list of that anme exists to be registered into */
426 WS_DLL_PUBLIC gboolean has_heur_dissector_list(const gchar *name);
427
428 /** Try all the dissectors in a given heuristic dissector list. This is done,
429  *  until we find one that recognizes the protocol.
430  *  Call this while the parent dissector running.
431  *
432  * @param sub_dissectors the sub-dissector list
433  * @param tvb the tvbuff with the (remaining) packet data
434  * @param pinfo the packet info of this packet (additional info)
435  * @param tree the protocol tree to be build or NULL
436  * @param hdtbl_entry returns the last tried dissectors hdtbl_entry.
437  * @param data parameter to pass to subdissector
438  * @return TRUE if the packet was recognized by the sub-dissector (stop dissection here)
439  */
440 WS_DLL_PUBLIC gboolean dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
441     tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, heur_dtbl_entry_t **hdtbl_entry, void *data);
442
443 /** Find a heuristic dissector table by table name.
444  *
445  * @param name name of the dissector table
446  * @return pointer to the table on success, NULL if no such table exists
447  */
448 WS_DLL_PUBLIC heur_dissector_list_t find_heur_dissector_list(const char *name);
449
450 /** Find a heuristic dissector by the unique short protocol name provided during registration.
451  *
452  * @param short_name short name of the protocol to look at
453  * @return pointer to the heuristic dissector entry, NULL if not such dissector exists
454  */
455 WS_DLL_PUBLIC heur_dtbl_entry_t* find_heur_dissector_by_unique_short_name(const char *short_name);
456
457 /** Add a sub-dissector to a heuristic dissector list.
458  *  Call this in the proto_handoff function of the sub-dissector.
459  *
460  * @param name the name of the "parent" protocol, e.g. "tcp"
461  * @param dissector the sub-dissector to be registered
462  * @param display_name the string used to present heuristic to user, e.g. "HTTP over TCP"
463  * @param short_name the string used for "internal" use to identify heuristic, e.g. "http_tcp"
464  * @param proto the protocol id of the sub-dissector
465  * @param enable initially enabled or not
466  */
467 WS_DLL_PUBLIC void heur_dissector_add(const char *name, heur_dissector_t dissector,
468     const char *display_name, const char *short_name, const int proto, heuristic_enable_e enable);
469
470 /** Remove a sub-dissector from a heuristic dissector list.
471  *  Call this in the prefs_reinit function of the sub-dissector.
472  *
473  * @param name the name of the "parent" protocol, e.g. "tcp"
474  * @param dissector the sub-dissector to be unregistered
475  * @param proto the protocol id of the sub-dissector
476  */
477 WS_DLL_PUBLIC void heur_dissector_delete(const char *name, heur_dissector_t dissector, const int proto);
478
479 /** Enable/Disable a sub-dissector in a heuristic dissector list
480  *  Call this in the prefs_reinit function of the sub-dissector.
481  *
482  * @param name the name of the "parent" protocol, e.g. "tcp"
483  * @param dissector the sub-dissector to be disabled/enabled
484  * @param proto the protocol id of the sub-dissector
485  * @param enabled TRUE/FALSE to enable/disable the sub-dissector
486  */
487 extern void heur_dissector_set_enabled(const char *name, heur_dissector_t dissector, const int proto, const gboolean enabled);
488
489 /** Register a dissector. */
490 WS_DLL_PUBLIC dissector_handle_t register_dissector(const char *name, dissector_t dissector, const int proto);
491
492 /** Register a new dissector. */
493 WS_DLL_PUBLIC dissector_handle_t new_register_dissector(const char *name, new_dissector_t dissector, const int proto);
494
495 /** Deregister a dissector. */
496 WS_DLL_PUBLIC void deregister_dissector(const char *name);
497
498 /** Get the long name of the protocol for a dissector handle. */
499 extern const char *dissector_handle_get_long_name(const dissector_handle_t handle);
500
501 /** Get the short name of the protocol for a dissector handle. */
502 WS_DLL_PUBLIC const char *dissector_handle_get_short_name(const dissector_handle_t handle);
503
504 /** Get the index of the protocol for a dissector handle. */
505 WS_DLL_PUBLIC int dissector_handle_get_protocol_index(const dissector_handle_t handle);
506
507 /** Get a GList of all registered dissector names. */
508 WS_DLL_PUBLIC GList* get_dissector_names(void);
509
510 /** Find a dissector by name. */
511 WS_DLL_PUBLIC dissector_handle_t find_dissector(const char *name);
512
513 /** Get a dissector name from handle. */
514 WS_DLL_PUBLIC const char *dissector_handle_get_dissector_name(const dissector_handle_t handle);
515
516 /** Create an anonymous handle for a dissector. */
517 WS_DLL_PUBLIC dissector_handle_t create_dissector_handle(dissector_t dissector,
518     const int proto);
519 WS_DLL_PUBLIC dissector_handle_t new_create_dissector_handle(new_dissector_t dissector,
520     const int proto);
521 WS_DLL_PUBLIC dissector_handle_t new_create_dissector_handle_with_name(new_dissector_t dissector,
522     const int proto, const char* name);
523
524 /** Destroy an anonymous handle for a dissector. */
525 WS_DLL_PUBLIC void destroy_dissector_handle(dissector_handle_t handle);
526
527 /** Call a dissector through a handle and if no dissector was found
528  * pass it over to the "data" dissector instead.
529  *
530  *   @param handle The dissector to call.
531  *   @param  tvb The buffer to dissect.
532  *   @param  pinfo Packet Info.
533  *   @param  tree The protocol tree.
534  *   @param  data parameter to pass to dissector
535  *   @return  If the protocol for that handle isn't enabled call the data
536  *   dissector. Otherwise, if the handle refers to a new-style
537  *   dissector, call the dissector and return its return value, otherwise call
538  *   it and return the length of the tvbuff pointed to by the argument.
539  */
540 WS_DLL_PUBLIC int call_dissector_with_data(dissector_handle_t handle, tvbuff_t *tvb,
541     packet_info *pinfo, proto_tree *tree, void *data);
542 WS_DLL_PUBLIC int call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
543     packet_info *pinfo, proto_tree *tree);
544
545 /** Call a dissector through a handle but if no dissector was found
546  * just return 0 and do not call the "data" dissector instead.
547  *
548  *   @param handle The dissector to call.
549  *   @param  tvb The buffer to dissect.
550  *   @param  pinfo Packet Info.
551  *   @param  tree The protocol tree.
552  *   @param  data parameter to pass to dissector
553  *   @return  If the protocol for that handle isn't enabled, return 0 without
554  *   calling the dissector. Otherwise, if the handle refers to a new-style
555  *   dissector, call the dissector and return its return value, otherwise call
556  *   it and return the length of the tvbuff pointed to by the argument.
557  */
558 WS_DLL_PUBLIC int call_dissector_only(dissector_handle_t handle, tvbuff_t *tvb,
559     packet_info *pinfo, proto_tree *tree, void *data);
560
561 /**
562  *   @param heur_dtbl_entry The heur_dtbl_entry of the dissector to call.
563  *   @param  tvb The buffer to dissect.
564  *   @param  pinfo Packet Info.
565  *   @param  tree The protocol tree.
566  *   @param  data parameter to pass to dissector
567  */
568
569 WS_DLL_PUBLIC void call_heur_dissector_direct(heur_dtbl_entry_t *heur_dtbl_entry, tvbuff_t *tvb,
570     packet_info *pinfo, proto_tree *tree, void *data);
571
572 /* Do all one-time initialization. */
573 extern void dissect_init(void);
574
575 extern void dissect_cleanup(void);
576
577 /*
578  * Given a tvbuff, and a length from a packet header, adjust the length
579  * of the tvbuff to reflect the specified length.
580  */
581 WS_DLL_PUBLIC void set_actual_length(tvbuff_t *tvb, const guint specified_len);
582
583 /**
584  * Allow protocols to register "init" routines, which are called before
585  * we make a pass through a capture file and dissect all its packets
586  * (e.g., when we read in a new capture file, or run a "filter packets"
587  * or "colorize packets" pass over the current capture file or when the
588  * preferences are changed).
589  */
590 WS_DLL_PUBLIC void register_init_routine(void (*func)(void));
591
592 /**
593  * Allows protocols to register "cleanup" routines which are called
594  * after closing a capture file (or when preferences are changed, in
595  * that case these routines are called before the init routines are
596  * executed). It can be used to release resources that are allocated in
597  * register_init_routine.
598  */
599 WS_DLL_PUBLIC void register_cleanup_routine(void (*func)(void));
600
601 /* Initialize all data structures used for dissection. */
602 void init_dissection(void);
603
604 /* Free data structures allocated for dissection. */
605 void cleanup_dissection(void);
606
607 /* Allow protocols to register a "cleanup" routine to be
608  * run after the initial sequential run through the packets.
609  * Note that the file can still be open after this; this is not
610  * the final cleanup. */
611 WS_DLL_PUBLIC void register_postseq_cleanup_routine(void (*func)(void));
612
613 /* Call all the registered "postseq_cleanup" routines. */
614 WS_DLL_PUBLIC void postseq_cleanup_all_protocols(void);
615
616 /* Allow dissectors to register a "final_registration" routine
617  * that is run like the proto_register_XXX() routine, but the end
618  * end of the epan_init() function; that is, *after* all other
619  * subsystems, liked dfilters, have finished initializing. This is
620  * useful for dissector registration routines which need to compile
621  * display filters. dfilters can't initialize itself until all protocols
622  * have registereed themselvs. */
623 WS_DLL_PUBLIC void
624 register_final_registration_routine(void (*func)(void));
625
626 /* Call all the registered "final_registration" routines. */
627 extern void
628 final_registration_all_protocols(void);
629
630 /*
631  * Add a new data source to the list of data sources for a frame, given
632  * the tvbuff for the data source and its name.
633  */
634 WS_DLL_PUBLIC void add_new_data_source(packet_info *pinfo, tvbuff_t *tvb,
635     const char *name);
636 /* Removes the last-added data source, if it turns out it wasn't needed */
637 WS_DLL_PUBLIC void remove_last_data_source(packet_info *pinfo);
638
639
640 /*
641  * Return the data source name, tvb.
642  */
643 struct data_source;
644 WS_DLL_PUBLIC char *get_data_source_name(const struct data_source *src);
645 WS_DLL_PUBLIC tvbuff_t *get_data_source_tvb(const struct data_source *src);
646
647 /*
648  * Free up a frame's list of data sources.
649  */
650 extern void free_data_sources(packet_info *pinfo);
651
652 /* Mark another frame as depended upon by the current frame.
653  *
654  * This information is used to ensure that the dependend-upon frame is saved
655  * if the user does a File->Save-As of only the Displayed packets and the
656  * current frame passed the display filter.
657  */
658 WS_DLL_PUBLIC void mark_frame_as_depended_upon(packet_info *pinfo, guint32 frame_num);
659
660 /* Structure passed to the frame dissector */
661 typedef struct frame_data_s
662 {
663     int file_type_subtype;
664     const gchar  *pkt_comment; /**< NULL if not available */
665 } frame_data_t;
666
667 /*
668  * Dissectors should never modify the record data.
669  */
670 extern void dissect_record(struct epan_dissect *edt, int file_type_subtype,
671     struct wtap_pkthdr *phdr, tvbuff_t *tvb,
672     frame_data *fd, column_info *cinfo);
673
674 /*
675  * Dissectors should never modify the packet data.
676  */
677 extern void dissect_file(struct epan_dissect *edt,
678     struct wtap_pkthdr *phdr, tvbuff_t *tvb,
679     frame_data *fd, column_info *cinfo);
680
681 /* These functions are in packet-ethertype.c */
682 extern void capture_ethertype(guint16 etype, const guchar *pd, int offset,
683                 int len, packet_counts *ld);
684 /* Structure passed to the ethertype dissector */
685 typedef struct ethertype_data_s
686 {
687     guint16 etype;
688     int offset_after_ethertype;
689     proto_tree *fh_tree;
690     int etype_id;
691     int trailer_id;
692     int fcs_len;
693 } ethertype_data_t;
694
695 /*
696  * Dump layer/selector/dissector records in a fashion similar to the
697  * proto_registrar_dump_* routines.
698  */
699 WS_DLL_PUBLIC void dissector_dump_decodes(void);
700
701 /*
702  * For each heuristic dissector table, dump list of dissectors (filter_names) for that table
703  */
704 WS_DLL_PUBLIC void dissector_dump_heur_decodes(void);
705
706 /*
707  * post dissectors are to be called by packet-frame.c after every other
708  * dissector has been called.
709  */
710 WS_DLL_PUBLIC void register_postdissector(dissector_handle_t);
711 WS_DLL_PUBLIC void deregister_postdissector(dissector_handle_t handle);
712
713 extern gboolean have_postdissector(void);
714 extern void call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
715
716 /** @} */
717
718 #ifdef __cplusplus
719 }
720 #endif /* __cplusplus */
721
722 #endif /* packet.h */