2 * Routines for packet disassembly
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
43 #include "timestamp.h"
45 #include "atalk-utils.h"
46 #include "sna-utils.h"
47 #include "osi-utils.h"
50 #include "addr_resolv.h"
53 #include "epan_dissect.h"
57 #include <epan/reassemble.h>
58 #include <epan/stream.h>
59 #include <epan/expert.h>
61 static gint proto_malformed = -1;
62 static dissector_handle_t frame_handle = NULL;
63 static dissector_handle_t data_handle = NULL;
68 frame_handle = find_dissector("frame");
69 data_handle = find_dissector("data");
70 proto_malformed = proto_get_id_by_filter_name("malformed");
80 * Given a tvbuff, and a length from a packet header, adjust the length
81 * of the tvbuff to reflect the specified length.
84 set_actual_length(tvbuff_t *tvb, const guint specified_len)
86 if (specified_len < tvb_reported_length(tvb)) {
87 /* Adjust the length of this tvbuff to include only the specified
90 The dissector above the one calling us (the dissector above is
91 probably us) may use that to determine how much of its packet
93 tvb_set_reported_length(tvb, specified_len);
97 /* Allow protocols to register "init" routines, which are called before
98 we make a pass through a capture file and dissect all its packets
99 (e.g., when we read in a new capture file, or run a "filter packets"
100 or "colorize packets" pass over the current capture file). */
101 static GSList *init_routines;
104 register_init_routine(void (*func)(void))
106 init_routines = g_slist_append(init_routines, (gpointer)func);
109 typedef void (*void_func_t)(void);
111 /* Initialize all data structures used for dissection. */
113 call_init_routine(gpointer routine, gpointer dummy _U_)
115 void_func_t func = (void_func_t)routine;
120 * XXX - for now, these are the same; the "init" routines free whatever
121 * stuff is left over from any previous dissection, and then initialize
124 * We should probably split that into "init" and "cleanup" routines, for
128 init_dissection(void)
130 /* Reclaim and reinitialize all memory of seasonal scope */
133 /* Initialize the table of conversations. */
134 epan_conversation_init();
136 /* Initialize the table of circuits. */
139 /* Initialize protocol-specific variables. */
140 g_slist_foreach(init_routines, &call_init_routine, NULL);
142 /* Initialize the common data structures for fragment reassembly.
143 Must be done *after* calling init routines, as those routines
144 may free up space for fragments, which they find by using the
145 data structures that "reassemble_cleanup()" frees. */
148 /* Initialize the stream-handling tables */
151 /* Initialize the expert infos */
156 cleanup_dissection(void)
158 /* Reclaim all memory of seasonal scope */
161 /* Cleanup the table of conversations. */
162 epan_conversation_cleanup();
164 /* Cleanup the table of circuits. */
165 epan_circuit_cleanup();
167 /* TODO: Introduce cleanup_routines */
168 /* Cleanup protocol-specific variables. */
169 g_slist_foreach(init_routines, &call_init_routine, NULL);
171 /* Cleanup the common data structures for fragment reassembly.
172 Must be done *after* calling init routines, as those routines
173 may free up space for fragments, which they find by using the
174 data structures that "reassemble_cleanup()" frees. */
175 reassemble_cleanup();
177 /* Cleanup the stream-handling tables */
180 /* Initialize the expert infos */
184 /* Allow protocols to register a "cleanup" routine to be
185 * run after the initial sequential run through the packets.
186 * Note that the file can still be open after this; this is not
187 * the final cleanup. */
188 static GSList *postseq_cleanup_routines;
191 register_postseq_cleanup_routine(void_func_t func)
193 postseq_cleanup_routines = g_slist_append(postseq_cleanup_routines,
197 /* Call all the registered "postseq_cleanup" routines. */
199 call_postseq_cleanup_routine(gpointer routine, gpointer dummy _U_)
201 void_func_t func = (void_func_t)routine;
206 postseq_cleanup_all_protocols(void)
208 g_slist_foreach(postseq_cleanup_routines,
209 &call_postseq_cleanup_routine, NULL);
213 * Add a new data source to the list of data sources for a frame, given
214 * the tvbuff for the data source and its name.
217 add_new_data_source(packet_info *pinfo, tvbuff_t *tvb, const char *name)
221 src = ep_alloc(sizeof (data_source));
223 src->name_initialized = FALSE;
225 pinfo->data_src = g_slist_append(pinfo->data_src, src);
229 get_data_source_name(data_source *src)
231 if (!src->name_initialized) {
232 src->name = ep_strdup_printf("%s (%u bytes)", src->name, tvb_length(src->tvb));
233 src->name_initialized = TRUE;
240 * Free up a frame's list of data sources.
243 free_data_sources(packet_info *pinfo)
245 if (pinfo->data_src) {
246 g_slist_free(pinfo->data_src);
247 pinfo->data_src = NULL;
251 /* Allow dissectors to register a "final_registration" routine
252 * that is run like the proto_register_XXX() routine, but at the
253 * end of the epan_init() function; that is, *after* all other
254 * subsystems, like dfilters, have finished initializing. This is
255 * useful for dissector registration routines which need to compile
256 * display filters. dfilters can't initialize itself until all protocols
257 * have registered themselves. */
258 static GSList *final_registration_routines;
261 register_final_registration_routine(void (*func)(void))
263 final_registration_routines = g_slist_append(final_registration_routines,
267 /* Call all the registered "final_registration" routines. */
269 call_final_registration_routine(gpointer routine, gpointer dummy _U_)
271 void_func_t func = (void_func_t)routine;
277 final_registration_all_protocols(void)
279 g_slist_foreach(final_registration_routines,
280 &call_final_registration_routine, NULL);
284 /* Creates the top-most tvbuff and calls dissect_frame() */
286 dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header,
287 const guchar *pd, frame_data *fd, column_info *cinfo)
291 memset(&edt->pi, 0, sizeof(edt->pi));
292 edt->pi.current_proto = "<Missing Protocol Name>";
293 edt->pi.cinfo = cinfo;
295 edt->pi.pseudo_header = pseudo_header;
296 edt->pi.dl_src.type = AT_NONE;
297 edt->pi.dl_dst.type = AT_NONE;
298 edt->pi.net_src.type = AT_NONE;
299 edt->pi.net_dst.type = AT_NONE;
300 edt->pi.src.type = AT_NONE;
301 edt->pi.dst.type = AT_NONE;
302 edt->pi.ctype = CT_NONE;
303 edt->pi.noreassembly_reason = "";
304 edt->pi.ptype = PT_NONE;
305 edt->pi.p2p_dir = P2P_DIR_UNKNOWN;
306 edt->pi.dcetransporttype = -1;
307 edt->pi.annex_a_used = MTP2_ANNEX_A_USED_UNKNOWN;
308 edt->pi.dcerpc_procedure_name="";
309 edt->pi.link_dir = LINK_DIR_UNKNOWN;
311 /* to enable decode as for ethertype=0x0000 (fix for bug 4721) */
312 edt->pi.ethertype = G_MAXINT;
314 EP_CHECK_CANARY(("before dissecting frame %d",fd->num));
317 edt->tvb = tvb_new_real_data(pd, fd->cap_len, fd->pkt_len);
318 /* Add this tvbuffer into the data_src list */
319 add_new_data_source(&edt->pi, edt->tvb, "Frame");
321 /* Even though dissect_frame() catches all the exceptions a
322 * sub-dissector can throw, dissect_frame() itself may throw
323 * a ReportedBoundsError in bizarre cases. Thus, we catch the exception
324 * in this function. */
325 if(frame_handle != NULL)
326 call_dissector(frame_handle, edt->tvb, &edt->pi, edt->tree);
330 g_assert_not_reached();
332 CATCH(ReportedBoundsError) {
333 if(proto_malformed != -1){
334 proto_tree_add_protocol_format(edt->tree, proto_malformed, edt->tvb, 0, 0,
335 "[Malformed Frame: Packet Length]" );
337 g_assert_not_reached();
340 CATCH(OutOfMemoryError) {
345 EP_CHECK_CANARY(("after dissecting frame %d",fd->num));
347 fd->flags.visited = 1;
350 /*********************** code added for sub-dissector lookup *********************/
353 * A dissector handle.
355 struct dissector_handle {
356 const char *name; /* dissector name */
357 gboolean is_new; /* TRUE if new-style dissector */
362 protocol_t *protocol;
365 /* This function will return
366 * old style dissector :
367 * length of the payload or 1 of the payload is empty
369 * >0 this protocol was successfully dissected and this was this protocol.
370 * 0 this packet did not match this protocol.
372 * The only time this function will return 0 is if it is a new style dissector
373 * and if the dissector rejected the packet.
376 call_dissector_through_handle(dissector_handle_t handle, tvbuff_t *tvb,
377 packet_info *pinfo, proto_tree *tree)
379 const char *saved_proto;
382 saved_proto = pinfo->current_proto;
384 if (handle->protocol != NULL) {
385 pinfo->current_proto =
386 proto_get_protocol_short_name(handle->protocol);
389 if (handle->is_new) {
390 EP_CHECK_CANARY(("before calling handle->dissector.new for %s",handle->name));
391 ret = (*handle->dissector.new)(tvb, pinfo, tree);
392 EP_CHECK_CANARY(("after calling handle->dissector.new for %s",handle->name));
394 EP_CHECK_CANARY(("before calling handle->dissector.old for %s",handle->name));
395 (*handle->dissector.old)(tvb, pinfo, tree);
396 EP_CHECK_CANARY(("after calling handle->dissector.old for %s",handle->name));
397 ret = tvb_length(tvb);
400 * XXX - a tvbuff can have 0 bytes of data in
401 * it, so we have to make sure we don't return
408 pinfo->current_proto = saved_proto;
414 * Call a dissector through a handle.
415 * If the protocol for that handle isn't enabled, return 0 without
416 * calling the dissector.
417 * Otherwise, if the handle refers to a new-style dissector, call the
418 * dissector and return its return value, otherwise call it and return
419 * the length of the tvbuff pointed to by the argument.
423 call_dissector_work_error(dissector_handle_t handle, tvbuff_t *tvb,
424 packet_info *pinfo_arg, proto_tree *tree);
427 call_dissector_work(dissector_handle_t handle, tvbuff_t *tvb,
428 packet_info *pinfo_arg, proto_tree *tree, gboolean add_proto_name)
430 packet_info *pinfo = pinfo_arg;
431 const char *saved_proto;
432 guint16 saved_can_desegment;
434 gint saved_layer_names_len = 0;
436 if (handle->protocol != NULL &&
437 !proto_is_protocol_enabled(handle->protocol)) {
439 * The protocol isn't enabled.
444 saved_proto = pinfo->current_proto;
445 saved_can_desegment = pinfo->can_desegment;
447 if (pinfo->layer_names != NULL)
448 saved_layer_names_len = (gint) pinfo->layer_names->len;
451 * can_desegment is set to 2 by anyone which offers the
452 * desegmentation api/service.
453 * Then everytime a subdissector is called it is decremented
455 * Thus only the subdissector immediately on top of whoever
456 * offers this service can use it.
457 * We save the current value of "can_desegment" for the
458 * benefit of TCP proxying dissectors such as SOCKS, so they
459 * can restore it and allow the dissectors they call to use
460 * the desegmentation service.
462 pinfo->saved_can_desegment = saved_can_desegment;
463 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
464 if (handle->protocol != NULL) {
465 pinfo->current_proto =
466 proto_get_protocol_short_name(handle->protocol);
469 * Add the protocol name to the layers
470 * if not told not to. Asn2wrs generated dissectors may be added multiple times otherwise.
472 if ((pinfo->layer_names)&&(add_proto_name)) {
473 if (pinfo->layer_names->len > 0)
474 g_string_append(pinfo->layer_names, ":");
475 g_string_append(pinfo->layer_names,
476 proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
480 if (pinfo->in_error_pkt) {
481 ret = call_dissector_work_error(handle, tvb, pinfo, tree);
484 * Just call the subdissector.
486 ret = call_dissector_through_handle(handle, tvb, pinfo, tree);
490 * That dissector didn't accept the packet, so
491 * remove its protocol's name from the list
494 if ((pinfo->layer_names != NULL)&&(add_proto_name)) {
495 g_string_truncate(pinfo->layer_names, saved_layer_names_len);
498 pinfo->current_proto = saved_proto;
499 pinfo->can_desegment = saved_can_desegment;
505 call_dissector_work_error(dissector_handle_t handle, tvbuff_t *tvb,
506 packet_info *pinfo_arg, proto_tree *tree)
508 packet_info *pinfo = pinfo_arg;
509 const char *saved_proto;
510 guint16 saved_can_desegment;
511 volatile int ret = 0;
512 gboolean save_writable;
515 address save_net_src;
516 address save_net_dst;
521 * This isn't a packet being transported inside
522 * the protocol whose dissector is calling us,
523 * it's a copy of a packet that caused an error
524 * in some protocol included in a packet that
525 * reports the error (e.g., an ICMP Unreachable
530 * Save the current state of the writability of
531 * the columns, and restore them after the
532 * dissector returns, so that the columns
533 * don't reflect the packet that got the error,
534 * they reflect the packet that reported the
537 saved_proto = pinfo->current_proto;
538 saved_can_desegment = pinfo->can_desegment;
540 save_writable = col_get_writable(pinfo->cinfo);
541 col_set_writable(pinfo->cinfo, FALSE);
542 save_dl_src = pinfo->dl_src;
543 save_dl_dst = pinfo->dl_dst;
544 save_net_src = pinfo->net_src;
545 save_net_dst = pinfo->net_dst;
546 save_src = pinfo->src;
547 save_dst = pinfo->dst;
549 /* Dissect the contained packet. */
551 ret = call_dissector_through_handle(handle, tvb,pinfo, tree);
555 * Restore the column writability and addresses.
557 col_set_writable(pinfo->cinfo, save_writable);
558 pinfo->dl_src = save_dl_src;
559 pinfo->dl_dst = save_dl_dst;
560 pinfo->net_src = save_net_src;
561 pinfo->net_dst = save_net_dst;
562 pinfo->src = save_src;
563 pinfo->dst = save_dst;
566 * Restore the current protocol, so any
567 * "Short Frame" indication reflects that
568 * protocol, not the protocol for the
569 * packet that got the error.
571 pinfo->current_proto = saved_proto;
574 * Restore the desegmentability state.
576 pinfo->can_desegment = saved_can_desegment;
579 * Rethrow the exception, so this will be
580 * reported as a short frame.
584 CATCH(ReportedBoundsError) {
586 * "ret" wasn't set because an exception was thrown
587 * before "call_dissector_through_handle()" returned.
588 * As it called something, at least one dissector
589 * accepted the packet, and, as an exception was
590 * thrown, not only was all the tvbuff dissected,
591 * a dissector tried dissecting past the end of
592 * the data in some tvbuff, so we'll assume that
593 * the entire tvbuff was dissected.
595 ret = tvb_length(tvb);
597 CATCH(OutOfMemoryError) {
602 col_set_writable(pinfo->cinfo, save_writable);
603 pinfo->dl_src = save_dl_src;
604 pinfo->dl_dst = save_dl_dst;
605 pinfo->net_src = save_net_src;
606 pinfo->net_dst = save_net_dst;
607 pinfo->src = save_src;
608 pinfo->dst = save_dst;
609 pinfo->want_pdu_tracking = 0;
614 * An entry in the hash table portion of a dissector table.
617 dissector_handle_t initial;
618 dissector_handle_t current;
624 * "hash_table" is a hash table, indexed by port number, supplying
625 * a "struct dtbl_entry"; it records what dissector is assigned to
626 * that port number in that table.
628 * "dissector_handles" is a list of all dissectors that *could* be
629 * used in that table; not all of them are necessarily in the table,
630 * as they may be for protocols that don't have a fixed port number.
632 * "ui_name" is the name the dissector table has in the user interface.
634 * "type" is a field type giving the width of the port number for that
637 * "base" is the base in which to display the port number for that
640 struct dissector_table {
641 GHashTable *hash_table;
642 GSList *dissector_handles;
648 static GHashTable *dissector_tables = NULL;
650 /* Finds a dissector table by table name. */
652 find_dissector_table(const char *name)
654 g_assert(dissector_tables);
655 return g_hash_table_lookup( dissector_tables, name );
658 /* Find an entry in a uint dissector table. */
659 static dtbl_entry_t *
660 find_uint_dtbl_entry(dissector_table_t sub_dissectors, const guint32 pattern)
662 switch (sub_dissectors->type) {
669 * You can do a port lookup in these tables.
675 * But you can't do a port lookup in any other types
678 g_assert_not_reached();
684 return g_hash_table_lookup(sub_dissectors->hash_table,
685 GUINT_TO_POINTER(pattern));
690 dissector_add_sanity_check(const char *name, guint32 pattern, dissector_handle_t handle, dissector_table_t sub_dissectors)
692 dtbl_entry_t *dtbl_entry;
695 g_warning("%s: %s registering using a pattern of 0",
696 name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
699 dtbl_entry = g_hash_table_lookup(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern));
700 if (dtbl_entry != NULL) {
701 g_warning("%s: %s registering using pattern %d already registered by %s",
702 name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)),
703 pattern, proto_get_protocol_filter_name(proto_get_id(dtbl_entry->initial->protocol)));
708 /* Add an entry to a uint dissector table. */
710 dissector_add(const char *name, const guint32 pattern, dissector_handle_t handle)
712 dissector_table_t sub_dissectors;
713 dtbl_entry_t *dtbl_entry;
715 sub_dissectors = find_dissector_table(name);
717 g_assert(sub_dissectors);
718 g_assert(handle!=NULL);
719 switch (sub_dissectors->type) {
726 * You can do a port lookup in these tables.
732 * But you can't do a port lookup in any other types
735 g_assert_not_reached();
739 dissector_add_sanity_check(name, pattern, handle, sub_dissectors);
742 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
743 dtbl_entry->current = handle;
744 dtbl_entry->initial = dtbl_entry->current;
746 /* do the table insertion */
747 g_hash_table_insert( sub_dissectors->hash_table,
748 GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
751 * Now add it to the list of handles that could be used with this
752 * table, because it *is* being used with this table.
754 dissector_add_handle(name, handle);
757 /* Delete the entry for a dissector in a uint dissector table
758 with a particular pattern. */
760 /* NOTE: this doesn't use the dissector call variable. It is included to */
761 /* be consistant with the dissector_add and more importantly to be used */
762 /* if the technique of adding a temporary dissector is implemented. */
763 /* If temporary dissectors are deleted, then the original dissector must */
766 dissector_delete(const char *name, const guint32 pattern,
767 dissector_handle_t handle _U_)
769 dissector_table_t sub_dissectors = find_dissector_table( name);
770 dtbl_entry_t *dtbl_entry;
773 g_assert( sub_dissectors);
778 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
780 if (dtbl_entry != NULL) {
784 g_hash_table_remove(sub_dissectors->hash_table,
785 GUINT_TO_POINTER(pattern));
788 * Now free up the entry.
794 /* Change the entry for a dissector in a uint dissector table
795 with a particular pattern to use a new dissector handle. */
797 dissector_change(const char *name, const guint32 pattern, dissector_handle_t handle)
799 dissector_table_t sub_dissectors = find_dissector_table( name);
800 dtbl_entry_t *dtbl_entry;
803 g_assert( sub_dissectors);
806 * See if the entry already exists. If so, reuse it.
808 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
809 if (dtbl_entry != NULL) {
810 dtbl_entry->current = handle;
815 * Don't create an entry if there is no dissector handle - I.E. the
816 * user said not to decode something that wasn't being decoded
817 * in the first place.
822 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
823 dtbl_entry->initial = NULL;
824 dtbl_entry->current = handle;
826 /* do the table insertion */
827 g_hash_table_insert( sub_dissectors->hash_table,
828 GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
831 /* Reset an entry in a uint dissector table to its initial value. */
833 dissector_reset(const char *name, const guint32 pattern)
835 dissector_table_t sub_dissectors = find_dissector_table( name);
836 dtbl_entry_t *dtbl_entry;
839 g_assert( sub_dissectors);
844 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
846 if (dtbl_entry == NULL)
850 * Found - is there an initial value?
852 if (dtbl_entry->initial != NULL) {
853 dtbl_entry->current = dtbl_entry->initial;
855 g_hash_table_remove(sub_dissectors->hash_table,
856 GUINT_TO_POINTER(pattern));
861 /* Look for a given value in a given uint dissector table and, if found,
862 call the dissector with the arguments supplied, and return TRUE,
863 otherwise return FALSE. */
866 dissector_try_port_new(dissector_table_t sub_dissectors, const guint32 port,
867 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, const gboolean add_proto_name)
869 dtbl_entry_t *dtbl_entry;
870 struct dissector_handle *handle;
871 guint32 saved_match_port;
874 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, port);
875 if (dtbl_entry != NULL) {
877 * Is there currently a dissector handle for this entry?
879 handle = dtbl_entry->current;
880 if (handle == NULL) {
882 * No - pretend this dissector didn't exist,
883 * so that other dissectors might have a chance
884 * to dissect this packet.
890 * Save the current value of "pinfo->match_port",
891 * set it to the port that matched, call the
892 * dissector, and restore "pinfo->match_port".
894 saved_match_port = pinfo->match_port;
895 pinfo->match_port = port;
896 ret = call_dissector_work(handle, tvb, pinfo, tree, add_proto_name);
897 pinfo->match_port = saved_match_port;
900 * If a new-style dissector returned 0, it means that
901 * it didn't think this tvbuff represented a packet for
902 * its protocol, and didn't dissect anything.
904 * Old-style dissectors can't reject the packet.
906 * 0 is also returned if the protocol wasn't enabled.
908 * If the packet was rejected, we return FALSE, so that
909 * other dissectors might have a chance to dissect this
910 * packet, otherwise we return TRUE.
918 dissector_try_port(dissector_table_t sub_dissectors, const guint32 port,
919 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
922 return dissector_try_port_new(sub_dissectors, port, tvb, pinfo, tree, TRUE);
924 /* Look for a given value in a given uint dissector table and, if found,
925 return the dissector handle for that value. */
927 dissector_get_port_handle(dissector_table_t const sub_dissectors, const guint32 port)
929 dtbl_entry_t *dtbl_entry;
931 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, port);
932 if (dtbl_entry != NULL)
933 return dtbl_entry->current;
938 /* Find an entry in a string dissector table. */
939 static dtbl_entry_t *
940 find_string_dtbl_entry(dissector_table_t const sub_dissectors, const gchar *pattern)
942 switch (sub_dissectors->type) {
947 * You can do a string lookup in these tables.
953 * But you can't do a string lookup in any other types
956 g_assert_not_reached();
962 return g_hash_table_lookup(sub_dissectors->hash_table, pattern);
965 /* Add an entry to a string dissector table. */
967 dissector_add_string(const char *name, const gchar *pattern,
968 dissector_handle_t handle)
970 dissector_table_t sub_dissectors = find_dissector_table( name);
971 dtbl_entry_t *dtbl_entry;
974 g_assert( sub_dissectors);
976 switch (sub_dissectors->type) {
981 * You can do a string lookup in these tables.
987 * But you can't do a string lookup in any other types
990 g_assert_not_reached();
993 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
994 dtbl_entry->current = handle;
995 dtbl_entry->initial = dtbl_entry->current;
997 /* do the table insertion */
998 g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
999 (gpointer)dtbl_entry);
1002 * Now add it to the list of handles that could be used with this
1003 * table, because it *is* being used with this table.
1005 dissector_add_handle(name, handle);
1008 /* Delete the entry for a dissector in a string dissector table
1009 with a particular pattern. */
1011 /* NOTE: this doesn't use the dissector call variable. It is included to */
1012 /* be consistant with the dissector_add_string and more importantly to */
1013 /* be used if the technique of adding a temporary dissector is */
1015 /* If temporary dissectors are deleted, then the original dissector must */
1018 dissector_delete_string(const char *name, const gchar *pattern,
1019 dissector_handle_t handle _U_)
1021 dissector_table_t sub_dissectors = find_dissector_table( name);
1022 dtbl_entry_t *dtbl_entry;
1025 g_assert( sub_dissectors);
1030 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1032 if (dtbl_entry != NULL) {
1034 * Found - remove it.
1036 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1039 * Now free up the entry.
1045 /* Change the entry for a dissector in a string dissector table
1046 with a particular pattern to use a new dissector handle. */
1048 dissector_change_string(const char *name, const gchar *pattern,
1049 dissector_handle_t handle)
1051 dissector_table_t sub_dissectors = find_dissector_table( name);
1052 dtbl_entry_t *dtbl_entry;
1055 g_assert( sub_dissectors);
1058 * See if the entry already exists. If so, reuse it.
1060 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1061 if (dtbl_entry != NULL) {
1062 dtbl_entry->current = handle;
1067 * Don't create an entry if there is no dissector handle - I.E. the
1068 * user said not to decode something that wasn't being decoded
1069 * in the first place.
1074 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1075 dtbl_entry->initial = NULL;
1076 dtbl_entry->current = handle;
1078 /* do the table insertion */
1079 g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
1080 (gpointer)dtbl_entry);
1083 /* Reset an entry in a string sub-dissector table to its initial value. */
1085 dissector_reset_string(const char *name, const gchar *pattern)
1087 dissector_table_t sub_dissectors = find_dissector_table( name);
1088 dtbl_entry_t *dtbl_entry;
1091 g_assert( sub_dissectors);
1096 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1098 if (dtbl_entry == NULL)
1102 * Found - is there an initial value?
1104 if (dtbl_entry->initial != NULL) {
1105 dtbl_entry->current = dtbl_entry->initial;
1107 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1112 /* Look for a given string in a given dissector table and, if found, call
1113 the dissector with the arguments supplied, and return TRUE, otherwise
1116 dissector_try_string(dissector_table_t sub_dissectors, const gchar *string,
1117 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1119 dtbl_entry_t *dtbl_entry;
1120 struct dissector_handle *handle;
1122 const gchar *saved_match_string;
1124 /* XXX ASSERT instead ? */
1125 if (!string) return FALSE;
1126 dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1127 if (dtbl_entry != NULL) {
1129 * Is there currently a dissector handle for this entry?
1131 handle = dtbl_entry->current;
1132 if (handle == NULL) {
1134 * No - pretend this dissector didn't exist,
1135 * so that other dissectors might have a chance
1136 * to dissect this packet.
1142 * Save the current value of "pinfo->match_string",
1143 * set it to the string that matched, call the
1144 * dissector, and restore "pinfo->match_string".
1146 saved_match_string = pinfo->match_string;
1147 pinfo->match_string = string;
1148 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE);
1149 pinfo->match_string = saved_match_string;
1152 * If a new-style dissector returned 0, it means that
1153 * it didn't think this tvbuff represented a packet for
1154 * its protocol, and didn't dissect anything.
1156 * Old-style dissectors can't reject the packet.
1158 * 0 is also returned if the protocol wasn't enabled.
1160 * If the packet was rejected, we return FALSE, so that
1161 * other dissectors might have a chance to dissect this
1162 * packet, otherwise we return TRUE.
1169 /* Look for a given value in a given string dissector table and, if found,
1170 return the dissector handle for that value. */
1172 dissector_get_string_handle(dissector_table_t sub_dissectors,
1173 const gchar *string)
1175 dtbl_entry_t *dtbl_entry;
1177 dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1178 if (dtbl_entry != NULL)
1179 return dtbl_entry->current;
1185 dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry)
1187 return dtbl_entry->current;
1190 /* Add a handle to the list of handles that *could* be used with this
1191 table. That list is used by code in the UI. */
1193 dissector_add_handle(const char *name, dissector_handle_t handle)
1195 dissector_table_t sub_dissectors = find_dissector_table( name);
1199 g_assert(sub_dissectors != NULL);
1201 /* Is it already in this list? */
1202 entry = g_slist_find(sub_dissectors->dissector_handles, (gpointer)handle);
1203 if (entry != NULL) {
1205 * Yes - don't insert it again.
1210 /* Add it to the list. */
1211 sub_dissectors->dissector_handles =
1212 g_slist_append(sub_dissectors->dissector_handles, (gpointer)handle);
1216 dtbl_entry_get_initial_handle (dtbl_entry_t *dtbl_entry)
1218 return dtbl_entry->initial;
1221 /**************************************************/
1223 /* Routines to walk dissector tables */
1225 /**************************************************/
1227 typedef struct dissector_foreach_info {
1228 gpointer caller_data;
1229 DATFunc caller_func;
1231 const gchar *table_name;
1232 ftenum_t selector_type;
1233 } dissector_foreach_info_t;
1236 * Called for each entry in a dissector table.
1239 dissector_table_foreach_func (gpointer key, gpointer value, gpointer user_data)
1241 dissector_foreach_info_t *info;
1242 dtbl_entry_t *dtbl_entry;
1245 g_assert(user_data);
1248 if (dtbl_entry->current == NULL ||
1249 dtbl_entry->current->protocol == NULL) {
1251 * Either there is no dissector for this entry, or
1252 * the dissector doesn't have a protocol associated
1255 * XXX - should the latter check be done?
1261 info->caller_func(info->table_name, info->selector_type, key, value,
1266 * Called for each entry in the table of all dissector tables.
1269 dissector_all_tables_foreach_func (gpointer key, gpointer value, gpointer user_data)
1271 dissector_table_t sub_dissectors;
1272 dissector_foreach_info_t *info;
1275 g_assert(user_data);
1277 sub_dissectors = value;
1279 info->table_name = (gchar*) key;
1280 info->selector_type = get_dissector_table_selector_type(info->table_name);
1281 g_hash_table_foreach(sub_dissectors->hash_table, info->next_func, info);
1285 * Walk all dissector tables calling a user supplied function on each
1289 dissector_all_tables_foreach (DATFunc func,
1292 dissector_foreach_info_t info;
1294 info.caller_data = user_data;
1295 info.caller_func = func;
1296 info.next_func = dissector_table_foreach_func;
1297 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1301 * Walk one dissector table's hash table calling a user supplied function
1305 dissector_table_foreach (const char *name,
1309 dissector_foreach_info_t info;
1310 dissector_table_t sub_dissectors = find_dissector_table( name);
1312 info.table_name = name;
1313 info.selector_type = sub_dissectors->type;
1314 info.caller_func = func;
1315 info.caller_data = user_data;
1316 g_hash_table_foreach(sub_dissectors->hash_table, dissector_table_foreach_func, &info);
1320 * Walk one dissector table's list of handles calling a user supplied
1321 * function on each entry.
1324 dissector_table_foreach_handle(const char *name,
1325 DATFunc_handle func,
1328 dissector_table_t sub_dissectors = find_dissector_table( name);
1331 for (tmp = sub_dissectors->dissector_handles; tmp != NULL;
1332 tmp = g_slist_next(tmp))
1333 func(name, tmp->data, user_data);
1337 * Called for each entry in a dissector table.
1340 dissector_table_foreach_changed_func (gpointer key, gpointer value, gpointer user_data)
1342 dtbl_entry_t *dtbl_entry;
1343 dissector_foreach_info_t *info;
1346 g_assert(user_data);
1349 if (dtbl_entry->initial == dtbl_entry->current) {
1351 * Entry hasn't changed - don't call the function.
1357 info->caller_func(info->table_name, info->selector_type, key, value,
1362 * Walk all dissector tables calling a user supplied function only on
1363 * any entry that has been changed from its original state.
1366 dissector_all_tables_foreach_changed (DATFunc func,
1369 dissector_foreach_info_t info;
1371 info.caller_data = user_data;
1372 info.caller_func = func;
1373 info.next_func = dissector_table_foreach_changed_func;
1374 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1378 * Walk one dissector table calling a user supplied function only on
1379 * any entry that has been changed from its original state.
1382 dissector_table_foreach_changed (const char *name,
1386 dissector_foreach_info_t info;
1387 dissector_table_t sub_dissectors = find_dissector_table( name);
1389 info.table_name = name;
1390 info.selector_type = sub_dissectors->type;
1391 info.caller_func = func;
1392 info.caller_data = user_data;
1393 g_hash_table_foreach(sub_dissectors->hash_table,
1394 dissector_table_foreach_changed_func, &info);
1397 typedef struct dissector_foreach_table_info {
1398 gpointer caller_data;
1399 DATFunc_table caller_func;
1400 } dissector_foreach_table_info_t;
1403 * Called for each entry in the table of all dissector tables.
1406 dissector_all_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
1408 dissector_table_t table;
1409 dissector_foreach_table_info_t *info;
1413 (*info->caller_func)((gchar*)key, table->ui_name, info->caller_data);
1417 * Walk all dissector tables calling a user supplied function on each
1421 dissector_all_tables_foreach_table (DATFunc_table func,
1424 dissector_foreach_table_info_t info;
1426 info.caller_data = user_data;
1427 info.caller_func = func;
1428 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_table_func, &info);
1432 register_dissector_table(const char *name, const char *ui_name, const ftenum_t type,
1435 dissector_table_t sub_dissectors;
1437 /* Create our hash-of-hashes if it doesn't already exist */
1438 if (!dissector_tables) {
1439 dissector_tables = g_hash_table_new( g_str_hash, g_str_equal );
1440 g_assert(dissector_tables);
1443 /* Make sure the registration is unique */
1444 if(g_hash_table_lookup( dissector_tables, name )) {
1445 g_error("The filter name %s (%s) is already registered - do you use a buggy plugin?", name, ui_name);
1448 /* Create and register the dissector table for this name; returns */
1449 /* a pointer to the dissector table. */
1450 sub_dissectors = g_malloc(sizeof (struct dissector_table));
1458 * XXX - there's no "g_uint_hash()" or "g_uint_equal()",
1459 * so we use "g_direct_hash()" and "g_direct_equal()".
1461 sub_dissectors->hash_table = g_hash_table_new( g_direct_hash,
1467 sub_dissectors->hash_table = g_hash_table_new( g_str_hash,
1472 g_assert_not_reached();
1474 sub_dissectors->dissector_handles = NULL;
1475 sub_dissectors->ui_name = ui_name;
1476 sub_dissectors->type = type;
1477 sub_dissectors->base = base;
1478 g_hash_table_insert( dissector_tables, (gpointer)name, (gpointer) sub_dissectors );
1479 return sub_dissectors;
1483 get_dissector_table_ui_name(const char *name)
1485 dissector_table_t sub_dissectors = find_dissector_table( name);
1487 return sub_dissectors->ui_name;
1491 get_dissector_table_selector_type(const char *name)
1493 dissector_table_t sub_dissectors = find_dissector_table( name);
1495 return sub_dissectors->type;
1499 get_dissector_table_base(const char *name)
1501 dissector_table_t sub_dissectors = find_dissector_table( name);
1503 return sub_dissectors->base;
1506 static GHashTable *heur_dissector_lists = NULL;
1509 heur_dissector_t dissector;
1510 protocol_t *protocol;
1511 } heur_dtbl_entry_t;
1513 /* Finds a heuristic dissector table by field name. */
1514 static heur_dissector_list_t *
1515 find_heur_dissector_list(const char *name)
1517 g_assert(heur_dissector_lists != NULL);
1518 return g_hash_table_lookup(heur_dissector_lists, name);
1522 heur_dissector_add(const char *name, heur_dissector_t dissector, const int proto)
1524 heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1525 heur_dtbl_entry_t *dtbl_entry;
1528 g_assert(sub_dissectors != NULL);
1530 dtbl_entry = g_malloc(sizeof (heur_dtbl_entry_t));
1531 dtbl_entry->dissector = dissector;
1532 dtbl_entry->protocol = find_protocol_by_id(proto);
1534 /* do the table insertion */
1535 *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)dtbl_entry);
1540 static int find_matching_heur_dissector( gconstpointer a, gconstpointer b) {
1541 const heur_dtbl_entry_t *dtbl_entry_a = (const heur_dtbl_entry_t *) a;
1542 const heur_dtbl_entry_t *dtbl_entry_b = (const heur_dtbl_entry_t *) b;
1543 return (dtbl_entry_a->dissector == dtbl_entry_b->dissector) &&
1544 (dtbl_entry_a->protocol == dtbl_entry_b->protocol) ? 0 : 1;
1547 void heur_dissector_delete(const char *name, heur_dissector_t dissector, const int proto) {
1548 heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1549 heur_dtbl_entry_t dtbl_entry;
1550 GSList* found_entry;
1553 g_assert(sub_dissectors != NULL);
1555 dtbl_entry.dissector = dissector;
1557 dtbl_entry.protocol = find_protocol_by_id(proto);
1559 found_entry = g_slist_find_custom(*sub_dissectors, (gpointer) &dtbl_entry, find_matching_heur_dissector);
1562 *sub_dissectors = g_slist_remove_link(*sub_dissectors, found_entry);
1563 g_free(g_slist_nth_data(found_entry, 1));
1564 g_slist_free_1(found_entry);
1570 dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
1571 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1574 const char *saved_proto;
1576 heur_dtbl_entry_t *dtbl_entry;
1577 guint16 saved_can_desegment;
1578 gint saved_layer_names_len = 0;
1580 /* can_desegment is set to 2 by anyone which offers this api/service.
1581 then everytime a subdissector is called it is decremented by one.
1582 thus only the subdissector immediately ontop of whoever offers this
1584 We save the current value of "can_desegment" for the
1585 benefit of TCP proxying dissectors such as SOCKS, so they
1586 can restore it and allow the dissectors they call to use
1587 the desegmentation service.
1589 saved_can_desegment=pinfo->can_desegment;
1590 pinfo->saved_can_desegment = saved_can_desegment;
1591 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1594 saved_proto = pinfo->current_proto;
1596 if (pinfo->layer_names != NULL)
1597 saved_layer_names_len = (gint) pinfo->layer_names->len;
1599 for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
1600 /* XXX - why set this now and above? */
1601 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1602 dtbl_entry = (heur_dtbl_entry_t *)entry->data;
1604 if (dtbl_entry->protocol != NULL &&
1605 !proto_is_protocol_enabled(dtbl_entry->protocol)) {
1607 * No - don't try this dissector.
1612 if (dtbl_entry->protocol != NULL) {
1613 pinfo->current_proto =
1614 proto_get_protocol_short_name(dtbl_entry->protocol);
1617 * Add the protocol name to the layers; we'll remove it
1618 * if the dissector fails.
1620 if (pinfo->layer_names) {
1621 if (pinfo->layer_names->len > 0)
1622 g_string_append(pinfo->layer_names, ":");
1623 g_string_append(pinfo->layer_names,
1624 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol)));
1627 EP_CHECK_CANARY(("before calling heuristic dissector for protocol: %s",
1628 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1629 if ((*dtbl_entry->dissector)(tvb, pinfo, tree)) {
1630 EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has accepted and dissected packet",
1631 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1635 EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has returned true",
1636 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1639 * That dissector didn't accept the packet, so
1640 * remove its protocol's name from the list
1643 if (pinfo->layer_names != NULL) {
1644 g_string_truncate(pinfo->layer_names, saved_layer_names_len);
1648 pinfo->current_proto = saved_proto;
1649 pinfo->can_desegment=saved_can_desegment;
1654 register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
1656 /* Create our hash-of-lists if it doesn't already exist */
1657 if (heur_dissector_lists == NULL) {
1658 heur_dissector_lists = g_hash_table_new(g_str_hash, g_str_equal);
1659 g_assert(heur_dissector_lists != NULL);
1662 /* Make sure the registration is unique */
1663 g_assert(g_hash_table_lookup(heur_dissector_lists, name) == NULL);
1665 *sub_dissectors = NULL; /* initially empty */
1666 g_hash_table_insert(heur_dissector_lists, (gpointer)name,
1667 (gpointer) sub_dissectors);
1671 * Register dissectors by name; used if one dissector always calls a
1672 * particular dissector, or if it bases the decision of which dissector
1673 * to call on something other than a numerical value or on "try a bunch
1674 * of dissectors until one likes the packet".
1678 * List of registered dissectors.
1680 static GHashTable *registered_dissectors = NULL;
1682 /* Get the short name of the protocol for a dissector handle, if it has
1685 dissector_handle_get_short_name(const dissector_handle_t handle)
1687 if (handle->protocol == NULL) {
1689 * No protocol (see, for example, the handle for
1690 * dissecting the set of protocols where the first
1691 * octet of the payload is an OSI network layer protocol
1696 return proto_get_protocol_short_name(handle->protocol);
1699 /* Get the index of the protocol for a dissector handle, if it has
1702 dissector_handle_get_protocol_index(const dissector_handle_t handle)
1704 if (handle->protocol == NULL) {
1706 * No protocol (see, for example, the handle for
1707 * dissecting the set of protocols where the first
1708 * octet of the payload is an OSI network layer protocol
1713 return proto_get_id(handle->protocol);
1716 /* Find a registered dissector by name. */
1718 find_dissector(const char *name)
1720 g_assert(registered_dissectors != NULL);
1721 return g_hash_table_lookup(registered_dissectors, name);
1724 /* Create an anonymous handle for a dissector. */
1726 create_dissector_handle(dissector_t dissector, const int proto)
1728 struct dissector_handle *handle;
1730 handle = g_malloc(sizeof (struct dissector_handle));
1731 handle->name = NULL;
1732 handle->is_new = FALSE;
1733 handle->dissector.old = dissector;
1734 handle->protocol = find_protocol_by_id(proto);
1740 new_create_dissector_handle(new_dissector_t dissector, const int proto)
1742 struct dissector_handle *handle;
1744 handle = g_malloc(sizeof (struct dissector_handle));
1745 handle->name = NULL;
1746 handle->is_new = TRUE;
1747 handle->dissector.new = dissector;
1748 handle->protocol = find_protocol_by_id(proto);
1753 /* Register a dissector by name. */
1755 register_dissector(const char *name, dissector_t dissector, const int proto)
1757 struct dissector_handle *handle;
1759 /* Create our hash table if it doesn't already exist */
1760 if (registered_dissectors == NULL) {
1761 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1762 g_assert(registered_dissectors != NULL);
1765 /* Make sure the registration is unique */
1766 g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1768 handle = g_malloc(sizeof (struct dissector_handle));
1769 handle->name = name;
1770 handle->is_new = FALSE;
1771 handle->dissector.old = dissector;
1772 handle->protocol = find_protocol_by_id(proto);
1774 g_hash_table_insert(registered_dissectors, (gpointer)name,
1779 new_register_dissector(const char *name, new_dissector_t dissector, const int proto)
1781 struct dissector_handle *handle;
1783 /* Create our hash table if it doesn't already exist */
1784 if (registered_dissectors == NULL) {
1785 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1786 g_assert(registered_dissectors != NULL);
1789 /* Make sure the registration is unique */
1790 g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1792 handle = g_malloc(sizeof (struct dissector_handle));
1793 handle->name = name;
1794 handle->is_new = TRUE;
1795 handle->dissector.new = dissector;
1796 handle->protocol = find_protocol_by_id(proto);
1798 g_hash_table_insert(registered_dissectors, (gpointer)name,
1802 /* Call a dissector through a handle but if the dissector rejected it
1806 call_dissector_only(dissector_handle_t handle, tvbuff_t *tvb,
1807 packet_info *pinfo, proto_tree *tree)
1811 g_assert(handle != NULL);
1812 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE);
1816 /* Call a dissector through a handle and if this fails call the "data"
1820 call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
1821 packet_info *pinfo, proto_tree *tree)
1825 ret = call_dissector_only(handle, tvb, pinfo, tree);
1828 * The protocol was disabled, or the dissector rejected
1829 * it. Just dissect this packet as data.
1831 g_assert(data_handle != NULL);
1832 g_assert(data_handle->protocol != NULL);
1833 call_dissector_work(data_handle, tvb, pinfo, tree, TRUE);
1834 return tvb_length(tvb);
1840 * Dumps the "layer type"/"decode as" associations to stdout, similar
1841 * to the proto_registrar_dump_*() routines.
1843 * There is one record per line. The fields are tab-delimited.
1845 * Field 1 = layer type, e.g. "tcp.port"
1846 * Field 2 = selector in decimal
1847 * Field 3 = "decode as" name, e.g. "http"
1852 dissector_dump_decodes_display(const gchar *table_name,
1853 ftenum_t selector_type _U_, const gpointer key, const gpointer value,
1854 gpointer user_data _U_)
1856 guint32 selector = (guint32)(unsigned long) key;
1857 dissector_table_t sub_dissectors = find_dissector_table(table_name);
1858 dtbl_entry_t *dtbl_entry;
1859 dissector_handle_t handle;
1861 const gchar *decode_as;
1863 g_assert(sub_dissectors);
1864 switch (sub_dissectors->type) {
1871 g_assert(dtbl_entry);
1873 handle = dtbl_entry->current;
1876 proto_id = dissector_handle_get_protocol_index(handle);
1878 if (proto_id != -1) {
1879 decode_as = proto_get_protocol_filter_name(proto_id);
1880 g_assert(decode_as != NULL);
1881 printf("%s\t%u\t%s\n", table_name, selector, decode_as);
1891 dissector_dump_decodes()
1893 dissector_all_tables_foreach(dissector_dump_decodes_display, NULL);
1896 static GPtrArray* post_dissectors = NULL;
1897 static guint num_of_postdissectors = 0;
1900 register_postdissector(dissector_handle_t handle)
1902 if (!post_dissectors)
1903 post_dissectors = g_ptr_array_new();
1905 g_ptr_array_add(post_dissectors, handle);
1906 num_of_postdissectors++;
1910 have_postdissector()
1913 dissector_handle_t handle;
1915 for(i = 0; i < num_of_postdissectors; i++) {
1916 handle = (dissector_handle_t) g_ptr_array_index(post_dissectors,i);
1918 if (handle->protocol != NULL
1919 && proto_is_protocol_enabled(handle->protocol)) {
1920 /* We have at least one enabled postdissector */
1928 call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1932 for(i = 0; i < num_of_postdissectors; i++) {
1933 call_dissector_only((dissector_handle_t) g_ptr_array_index(post_dissectors,i),