2 * Definitions for packet disassembly structures and routines
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
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.
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.
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.
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"
35 #include "unit_strings.h"
36 #include "ws_symbol_export.h"
40 #endif /* __cplusplus */
44 /** @defgroup packet General Packet Dissection
49 #define hi_nibble(b) (((b) & 0xf0) >> 4)
50 #define lo_nibble(b) ((b) & 0x0f)
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])
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))
61 extern void packet_init(void);
62 extern void packet_cache_proto_handles(void);
63 extern void packet_cleanup(void);
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;
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;
76 * Dissector that returns:
78 * The amount of data in the protocol's PDU, if it was able to
79 * dissect all the data;
81 * 0, if the tvbuff doesn't contain a PDU for that protocol;
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.
87 typedef int (*dissector_t)(tvbuff_t *, packet_info *, proto_tree *, void *);
89 /** Type of a heuristic dissector, used in heur_dissector_add().
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)
96 typedef gboolean (*heur_dissector_t)(tvbuff_t *tvb, packet_info *pinfo,
97 proto_tree *tree, void *);
102 } heuristic_enable_e;
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,
108 typedef void (*DATFunc_table) (const gchar *table_name, const gchar *ui_name,
111 /* Opaque structure - provides type checking but no access to components */
112 typedef struct dtbl_entry dtbl_entry_t;
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);
117 /** Iterate over dissectors in a table with non-default "decode as" settings.
119 * Walk one dissector table calling a user supplied function only on
120 * any entry that has been changed from its original state.
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.
126 void dissector_table_foreach_changed (const char *table_name, DATFunc func,
129 /** Iterate over dissectors in a table.
131 * Walk one dissector table's hash table calling a user supplied function
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.
138 WS_DLL_PUBLIC void dissector_table_foreach (const char *table_name, DATFunc func,
141 /** Iterate over dissectors with non-default "decode as" settings.
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.
146 * @param[in] func The function to call for each dissector.
147 * @param[in] user_data User data to pass to the function.
149 WS_DLL_PUBLIC void dissector_all_tables_foreach_changed (DATFunc func,
152 /** Iterate over dissectors in a table by handle.
154 * Walk one dissector table's list of handles calling a user supplied
155 * function on each entry.
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.
161 WS_DLL_PUBLIC void dissector_table_foreach_handle(const char *table_name, DATFunc_handle func,
164 /** Iterate over all dissector tables.
166 * Walk the set of dissector tables calling a user supplied function on each
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);
175 /* a protocol uses the function to register a sub-dissector table
177 * 'param' is the display base for integer tables, and TRUE/FALSE for
178 * string tables (true indicating case-insensitive, false indicating
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);
185 * Similar to register_dissector_table, but with a "custom" hash function
186 * to store subdissectors.
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);
191 /** Deregister the dissector table by table name. */
192 void deregister_dissector_table(const char *name);
194 /* Find a dissector table by table name. */
195 WS_DLL_PUBLIC dissector_table_t find_dissector_table(const char *name);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
237 /* Delete all entries from a dissector table. */
238 WS_DLL_PUBLIC void dissector_delete_all(const char *name, dissector_handle_t handle);
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);
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);
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);
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);
260 /** Look for a given value in a given uint dissector table and, if found,
261 * return the current dissector handle for that value.
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.
267 WS_DLL_PUBLIC dissector_handle_t dissector_get_uint_handle(
268 dissector_table_t const sub_dissectors, const guint32 uint_val);
270 /** Look for a given value in a given uint dissector table and, if found,
271 * return the default dissector handle for that value.
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.
277 WS_DLL_PUBLIC dissector_handle_t dissector_get_default_uint_handle(
278 const char *name, const guint32 uint_val);
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);
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);
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);
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);
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);
303 /** Look for a given value in a given string dissector table and, if found,
304 * return the current dissector handle for that value.
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.
310 WS_DLL_PUBLIC dissector_handle_t dissector_get_string_handle(
311 dissector_table_t sub_dissectors, const gchar *string);
313 /** Look for a given value in a given string dissector table and, if found,
314 * return the default dissector handle for that value.
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.
320 WS_DLL_PUBLIC dissector_handle_t dissector_get_default_string_handle(
321 const char *name, const gchar *string);
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);
327 /** Look for a given key in a given "custom" dissector table and, if found,
328 * return the current dissector handle for that key.
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.
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
339 typedef struct _guid_key {
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);
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);
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);
360 /** Look for a given value in a given guid dissector table and, if found,
361 * return the current dissector handle for that value.
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.
367 WS_DLL_PUBLIC dissector_handle_t dissector_get_guid_handle(
368 dissector_table_t const sub_dissectors, guid_key* guid_val);
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);
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);
379 /** Get the list of handles for a dissector table
381 WS_DLL_PUBLIC GSList *dissector_table_get_dissector_handles(dissector_table_t dissector_table);
383 /** Get a handle to dissector out of a dissector table
385 WS_DLL_PUBLIC dissector_handle_t dissector_table_get_dissector_handle(dissector_table_t dissector_table, gchar* short_name);
387 /** Get a dissector table's type
389 WS_DLL_PUBLIC ftenum_t dissector_table_get_type(dissector_table_t dissector_table);
391 /** Mark a dissector table as allowing "Decode As"
393 WS_DLL_PUBLIC void dissector_table_allow_decode_as(dissector_table_t dissector_table);
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.
400 This is opaque outside of "packet.c". */
401 struct heur_dissector_list;
402 typedef struct heur_dissector_list *heur_dissector_list_t;
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 */
414 /** A protocol uses this function to register a heuristic sub-dissector list.
415 * Call this in the parent dissectors proto_register function.
417 * @param name the name of this protocol
419 WS_DLL_PUBLIC heur_dissector_list_t register_heur_dissector_list(const char *name, const int proto);
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);
426 /** Iterate over heuristic dissectors in a table.
428 * Walk one heuristic dissector table's list calling a user supplied function
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.
435 WS_DLL_PUBLIC void heur_dissector_table_foreach(const char *table_name,
436 DATFunc_heur func, gpointer user_data);
438 /** Iterate over all heuristic dissector tables.
440 * Walk the set of heuristic dissector tables calling a user supplied function
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);
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);
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.
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)
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);
467 /** Find a heuristic dissector table by table name.
469 * @param name name of the dissector table
470 * @return pointer to the table on success, NULL if no such table exists
472 WS_DLL_PUBLIC heur_dissector_list_t find_heur_dissector_list(const char *name);
474 /** Find a heuristic dissector by the unique short protocol name provided during registration.
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
479 WS_DLL_PUBLIC heur_dtbl_entry_t* find_heur_dissector_by_unique_short_name(const char *short_name);
481 /** Add a sub-dissector to a heuristic dissector list.
482 * Call this in the proto_handoff function of the sub-dissector.
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
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);
494 /** Remove a sub-dissector from a heuristic dissector list.
495 * Call this in the prefs_reinit function of the sub-dissector.
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
501 WS_DLL_PUBLIC void heur_dissector_delete(const char *name, heur_dissector_t dissector, const int proto);
503 /** Register a new dissector. */
504 WS_DLL_PUBLIC dissector_handle_t register_dissector(const char *name, dissector_t dissector, const int proto);
506 /** Deregister a dissector. */
507 void deregister_dissector(const char *name);
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);
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);
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);
518 /** Get a GList of all registered dissector names. */
519 WS_DLL_PUBLIC GList* get_dissector_names(void);
521 /** Find a dissector by name. */
522 WS_DLL_PUBLIC dissector_handle_t find_dissector(const char *name);
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);
527 /** Get a dissector name from handle. */
528 WS_DLL_PUBLIC const char *dissector_handle_get_dissector_name(const dissector_handle_t handle);
530 /** Create an anonymous handle for a dissector. */
531 WS_DLL_PUBLIC dissector_handle_t create_dissector_handle(dissector_t dissector,
533 WS_DLL_PUBLIC dissector_handle_t create_dissector_handle_with_name(dissector_t dissector,
534 const int proto, const char* name);
536 /** Call a dissector through a handle and if no dissector was found
537 * pass it over to the "data" dissector instead.
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.
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);
554 WS_DLL_PUBLIC int call_data_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
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.
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.
569 WS_DLL_PUBLIC int call_dissector_only(dissector_handle_t handle, tvbuff_t *tvb,
570 packet_info *pinfo, proto_tree *tree, void *data);
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
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);
583 /* This is opaque outside of "packet.c". */
584 struct depend_dissector_list;
585 typedef struct depend_dissector_list *depend_dissector_list_t;
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
593 * @param parent "Parent" protocol short name
594 * @param dependent "Dependent" protocol short name
595 * @return return TRUE if dependency was successfully registered
597 WS_DLL_PUBLIC gboolean register_depend_dissector(const char* parent, const char* dependent);
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
604 * @param parent "Parent" protocol short name
605 * @param dependent "Dependent" protocol short name
606 * @return return TRUE if dependency was successfully unregistered
608 WS_DLL_PUBLIC gboolean deregister_depend_dissector(const char* parent, const char* dependent);
610 /** Find the list of protocol dependencies
612 * @param name Protocol short name to search for
613 * @return return list of dependent was successfully registered
615 WS_DLL_PUBLIC depend_dissector_list_t find_depend_dissector_list(const char* name);
618 /* Do all one-time initialization. */
619 extern void dissect_init(void);
621 extern void dissect_cleanup(void);
624 * Given a tvbuff, and a length from a packet header, adjust the length
625 * of the tvbuff to reflect the specified length.
627 WS_DLL_PUBLIC void set_actual_length(tvbuff_t *tvb, const guint specified_len);
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).
636 WS_DLL_PUBLIC void register_init_routine(void (*func)(void));
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.
645 WS_DLL_PUBLIC void register_cleanup_routine(void (*func)(void));
648 * Register a shutdown routine to call once just before program exit
650 WS_DLL_PUBLIC void register_shutdown_routine(void (*func)(void));
652 /* Initialize all data structures used for dissection. */
653 void init_dissection(void);
655 /* Free data structures allocated for dissection. */
656 void cleanup_dissection(void);
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));
664 /* Call all the registered "postseq_cleanup" routines. */
665 WS_DLL_PUBLIC void postseq_cleanup_all_protocols(void);
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. */
675 register_final_registration_routine(void (*func)(void));
677 /* Call all the registered "final_registration" routines. */
679 final_registration_all_protocols(void);
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.
685 WS_DLL_PUBLIC void add_new_data_source(packet_info *pinfo, tvbuff_t *tvb,
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);
691 * Return the data source name, tvb.
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);
699 * Free up a frame's list of data sources.
701 extern void free_data_sources(packet_info *pinfo);
703 /* Mark another frame as depended upon by the current frame.
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.
709 WS_DLL_PUBLIC void mark_frame_as_depended_upon(packet_info *pinfo, guint32 frame_num);
711 /* Structure passed to the frame dissector */
712 typedef struct frame_data_s
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" */
720 /* Structure passed to the file dissector */
721 typedef struct file_data_s
723 const gchar *pkt_comment; /**< NULL if not available */
724 struct epan_dissect *color_edt; /** Used strictly for "coloring rules" */
729 * Dissectors should never modify the record data.
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);
736 * Dissectors should never modify the packet data.
738 extern void dissect_file(struct epan_dissect *edt,
739 struct wtap_pkthdr *phdr, tvbuff_t *tvb,
740 frame_data *fd, column_info *cinfo);
742 /* Structure passed to the ethertype dissector */
743 typedef struct ethertype_data_s
746 int offset_after_ethertype;
754 * Dump layer/selector/dissector records in a fashion similar to the
755 * proto_registrar_dump_* routines.
757 WS_DLL_PUBLIC void dissector_dump_decodes(void);
760 * For each heuristic dissector table, dump list of dissectors (filter_names) for that table
762 WS_DLL_PUBLIC void dissector_dump_heur_decodes(void);
765 * postdissectors are to be called by packet-frame.c after every other
766 * dissector has been called.
770 * Register a postdissector; the argument is the dissector handle for it.
772 WS_DLL_PUBLIC void register_postdissector(dissector_handle_t handle);
775 * Specify a set of hfids that the postdissector will need.
776 * The GArray is an array of hfids.
778 WS_DLL_PUBLIC void set_postdissector_wanted_hfids(dissector_handle_t handle,
779 GArray *wanted_hfids);
782 * Deregister a postdissector. Not for use in (post)dissectors or
783 * applications; only to be used by libwireshark itself.
785 void deregister_postdissector(dissector_handle_t handle);
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.
792 extern gboolean have_postdissector(void);
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.
799 extern void call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
802 * Return TRUE if at least one postdissector needs at least one hfid,
805 WS_DLL_PUBLIC gboolean postdissectors_want_hfids(void);
808 * Prime an epan_dissect_t with all the hfids wanted by postdissectors.
811 prime_epan_dissect_with_postdissector_wanted_hfids(epan_dissect_t *edt);
817 #endif /* __cplusplus */
819 #endif /* packet.h */