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