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, 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 * This should only add a data source to the list of data sources for
230 * a frame if the data sources are being used. Note that they can
231 * be used even if the protocol tree isn't being built or isn't visible,
232 * e.g. if you run tshark with -x but without -V or anything else to
233 * cause the protocol tree to be built.
236 packet_add_new_data_source(packet_info *pinfo, proto_tree *tree _U_,
237 tvbuff_t *tvb, const char *name)
239 add_new_data_source(pinfo, tvb, name);
243 get_data_source_name(data_source *src)
245 if (!src->name_initialized) {
246 src->name = ep_strdup_printf("%s (%u bytes)", src->name, tvb_length(src->tvb));
247 src->name_initialized = TRUE;
254 * Free up a frame's list of data sources.
257 free_data_sources(packet_info *pinfo)
259 if (pinfo->data_src) {
260 g_slist_free(pinfo->data_src);
261 pinfo->data_src = NULL;
265 /* Allow dissectors to register a "final_registration" routine
266 * that is run like the proto_register_XXX() routine, but at the
267 * end of the epan_init() function; that is, *after* all other
268 * subsystems, like dfilters, have finished initializing. This is
269 * useful for dissector registration routines which need to compile
270 * display filters. dfilters can't initialize itself until all protocols
271 * have registered themselves. */
272 static GSList *final_registration_routines;
275 register_final_registration_routine(void (*func)(void))
277 final_registration_routines = g_slist_append(final_registration_routines,
281 /* Call all the registered "final_registration" routines. */
283 call_final_registration_routine(gpointer routine, gpointer dummy _U_)
285 void_func_t func = (void_func_t)routine;
291 final_registration_all_protocols(void)
293 g_slist_foreach(final_registration_routines,
294 &call_final_registration_routine, NULL);
298 /* Creates the top-most tvbuff and calls dissect_frame() */
300 dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header,
301 const guchar *pd, frame_data *fd, column_info *cinfo)
305 memset(&edt->pi, 0, sizeof(edt->pi));
306 edt->pi.current_proto = "<Missing Protocol Name>";
307 edt->pi.cinfo = cinfo;
309 edt->pi.pseudo_header = pseudo_header;
310 edt->pi.dl_src.type = AT_NONE;
311 edt->pi.dl_dst.type = AT_NONE;
312 edt->pi.net_src.type = AT_NONE;
313 edt->pi.net_dst.type = AT_NONE;
314 edt->pi.src.type = AT_NONE;
315 edt->pi.dst.type = AT_NONE;
316 edt->pi.ctype = CT_NONE;
317 edt->pi.noreassembly_reason = "";
318 edt->pi.ptype = PT_NONE;
319 edt->pi.p2p_dir = P2P_DIR_UNKNOWN;
320 edt->pi.dcetransporttype = -1;
321 edt->pi.annex_a_used = MTP2_ANNEX_A_USED_UNKNOWN;
322 edt->pi.dcerpc_procedure_name="";
323 edt->pi.link_dir = LINK_DIR_UNKNOWN;
325 EP_CHECK_CANARY(("before dissecting frame %d",fd->num));
328 edt->tvb = tvb_new_real_data(pd, fd->cap_len, fd->pkt_len);
329 /* Add this tvbuffer into the data_src list */
330 packet_add_new_data_source(&edt->pi, edt->tree, edt->tvb, "Frame");
332 /* Even though dissect_frame() catches all the exceptions a
333 * sub-dissector can throw, dissect_frame() itself may throw
334 * a ReportedBoundsError in bizarre cases. Thus, we catch the exception
335 * in this function. */
336 if(frame_handle != NULL)
337 call_dissector(frame_handle, edt->tvb, &edt->pi, edt->tree);
341 g_assert_not_reached();
343 CATCH(ReportedBoundsError) {
344 if(proto_malformed != -1){
345 proto_tree_add_protocol_format(edt->tree, proto_malformed, edt->tvb, 0, 0,
346 "[Malformed Frame: Packet Length]" );
348 g_assert_not_reached();
351 CATCH(OutOfMemoryError) {
356 EP_CHECK_CANARY(("after dissecting frame %d",fd->num));
358 fd->flags.visited = 1;
361 /*********************** code added for sub-dissector lookup *********************/
364 * An dissector handle.
366 struct dissector_handle {
367 const char *name; /* dissector name */
368 gboolean is_new; /* TRUE if new-style dissector */
373 protocol_t *protocol;
376 /* This function will return
377 * old style dissector :
378 * length of the payload or 1 of the payload is empty
380 * >0 this protocol was successfully dissected and this was this protocol.
381 * 0 this packet did not match this protocol.
383 * The only time this function will return 0 is if it is a new style dissector
384 * and if the dissector rejected the packet.
387 call_dissector_through_handle(dissector_handle_t handle, tvbuff_t *tvb,
388 packet_info *pinfo, proto_tree *tree)
390 const char *saved_proto;
393 saved_proto = pinfo->current_proto;
395 if (handle->protocol != NULL) {
396 pinfo->current_proto =
397 proto_get_protocol_short_name(handle->protocol);
400 if (handle->is_new) {
401 EP_CHECK_CANARY(("before calling handle->dissector.new for %s",handle->name));
402 ret = (*handle->dissector.new)(tvb, pinfo, tree);
403 EP_CHECK_CANARY(("after calling handle->dissector.new for %s",handle->name));
405 EP_CHECK_CANARY(("before calling handle->dissector.old for %s",handle->name));
406 (*handle->dissector.old)(tvb, pinfo, tree);
407 EP_CHECK_CANARY(("after calling handle->dissector.old for %s",handle->name));
408 ret = tvb_length(tvb);
411 * XXX - a tvbuff can have 0 bytes of data in
412 * it, so we have to make sure we don't return
419 pinfo->current_proto = saved_proto;
425 * Call a dissector through a handle.
426 * If the protocol for that handle isn't enabled, return 0 without
427 * calling the dissector.
428 * Otherwise, if the handle refers to a new-style dissector, call the
429 * dissector and return its return value, otherwise call it and return
430 * the length of the tvbuff pointed to by the argument.
434 call_dissector_work_error(dissector_handle_t handle, tvbuff_t *tvb,
435 packet_info *pinfo_arg, proto_tree *tree);
438 call_dissector_work(dissector_handle_t handle, tvbuff_t *tvb,
439 packet_info *pinfo_arg, proto_tree *tree, gboolean add_proto_name)
441 packet_info *pinfo = pinfo_arg;
442 const char *saved_proto;
443 guint16 saved_can_desegment;
445 gint saved_layer_names_len = 0;
447 if (handle->protocol != NULL &&
448 !proto_is_protocol_enabled(handle->protocol)) {
450 * The protocol isn't enabled.
455 saved_proto = pinfo->current_proto;
456 saved_can_desegment = pinfo->can_desegment;
458 if (pinfo->layer_names != NULL)
459 saved_layer_names_len = (gint) pinfo->layer_names->len;
462 * can_desegment is set to 2 by anyone which offers the
463 * desegmentation api/service.
464 * Then everytime a subdissector is called it is decremented
466 * Thus only the subdissector immediately on top of whoever
467 * offers this service can use it.
468 * We save the current value of "can_desegment" for the
469 * benefit of TCP proxying dissectors such as SOCKS, so they
470 * can restore it and allow the dissectors they call to use
471 * the desegmentation service.
473 pinfo->saved_can_desegment = saved_can_desegment;
474 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
475 if (handle->protocol != NULL) {
476 pinfo->current_proto =
477 proto_get_protocol_short_name(handle->protocol);
480 * Add the protocol name to the layers
481 * if not told not to. Asn2wrs generated dissectors may be added multiple times otherwise.
483 if ((pinfo->layer_names)&&(add_proto_name)) {
484 if (pinfo->layer_names->len > 0)
485 g_string_append(pinfo->layer_names, ":");
486 g_string_append(pinfo->layer_names,
487 proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
491 if (pinfo->in_error_pkt) {
492 ret = call_dissector_work_error(handle, tvb, pinfo, tree);
495 * Just call the subdissector.
497 ret = call_dissector_through_handle(handle, tvb, pinfo, tree);
501 * That dissector didn't accept the packet, so
502 * remove its protocol's name from the list
505 if ((pinfo->layer_names != NULL)&&(add_proto_name)) {
506 g_string_truncate(pinfo->layer_names, saved_layer_names_len);
509 pinfo->current_proto = saved_proto;
510 pinfo->can_desegment = saved_can_desegment;
516 call_dissector_work_error(dissector_handle_t handle, tvbuff_t *tvb,
517 packet_info *pinfo_arg, proto_tree *tree)
519 packet_info *pinfo = pinfo_arg;
520 const char *saved_proto;
521 guint16 saved_can_desegment;
522 volatile int ret = 0;
523 gboolean save_writable;
526 address save_net_src;
527 address save_net_dst;
532 * This isn't a packet being transported inside
533 * the protocol whose dissector is calling us,
534 * it's a copy of a packet that caused an error
535 * in some protocol included in a packet that
536 * reports the error (e.g., an ICMP Unreachable
541 * Save the current state of the writability of
542 * the columns, and restore them after the
543 * dissector returns, so that the columns
544 * don't reflect the packet that got the error,
545 * they reflect the packet that reported the
548 saved_proto = pinfo->current_proto;
549 saved_can_desegment = pinfo->can_desegment;
551 save_writable = col_get_writable(pinfo->cinfo);
552 col_set_writable(pinfo->cinfo, FALSE);
553 save_dl_src = pinfo->dl_src;
554 save_dl_dst = pinfo->dl_dst;
555 save_net_src = pinfo->net_src;
556 save_net_dst = pinfo->net_dst;
557 save_src = pinfo->src;
558 save_dst = pinfo->dst;
560 /* Dissect the contained packet. */
562 ret = call_dissector_through_handle(handle, tvb,pinfo, tree);
566 * Restore the column writability and addresses.
568 col_set_writable(pinfo->cinfo, save_writable);
569 pinfo->dl_src = save_dl_src;
570 pinfo->dl_dst = save_dl_dst;
571 pinfo->net_src = save_net_src;
572 pinfo->net_dst = save_net_dst;
573 pinfo->src = save_src;
574 pinfo->dst = save_dst;
577 * Restore the current protocol, so any
578 * "Short Frame" indication reflects that
579 * protocol, not the protocol for the
580 * packet that got the error.
582 pinfo->current_proto = saved_proto;
585 * Restore the desegmentability state.
587 pinfo->can_desegment = saved_can_desegment;
590 * Rethrow the exception, so this will be
591 * reported as a short frame.
595 CATCH(ReportedBoundsError) {
597 * "ret" wasn't set because an exception was thrown
598 * before "call_dissector_through_handle()" returned.
599 * As it called something, at least one dissector
600 * accepted the packet, and, as an exception was
601 * thrown, not only was all the tvbuff dissected,
602 * a dissector tried dissecting past the end of
603 * the data in some tvbuff, so we'll assume that
604 * the entire tvbuff was dissected.
606 ret = tvb_length(tvb);
608 CATCH(OutOfMemoryError) {
613 col_set_writable(pinfo->cinfo, save_writable);
614 pinfo->dl_src = save_dl_src;
615 pinfo->dl_dst = save_dl_dst;
616 pinfo->net_src = save_net_src;
617 pinfo->net_dst = save_net_dst;
618 pinfo->src = save_src;
619 pinfo->dst = save_dst;
620 pinfo->want_pdu_tracking = 0;
625 * An entry in the hash table portion of a dissector table.
628 dissector_handle_t initial;
629 dissector_handle_t current;
635 * "hash_table" is a hash table, indexed by port number, supplying
636 * a "struct dtbl_entry"; it records what dissector is assigned to
637 * that port number in that table.
639 * "dissector_handles" is a list of all dissectors that *could* be
640 * used in that table; not all of them are necessarily in the table,
641 * as they may be for protocols that don't have a fixed port number.
643 * "ui_name" is the name the dissector table has in the user interface.
645 * "type" is a field type giving the width of the port number for that
648 * "base" is the base in which to display the port number for that
651 struct dissector_table {
652 GHashTable *hash_table;
653 GSList *dissector_handles;
659 static GHashTable *dissector_tables = NULL;
661 /* Finds a dissector table by table name. */
663 find_dissector_table(const char *name)
665 g_assert(dissector_tables);
666 return g_hash_table_lookup( dissector_tables, name );
669 /* Find an entry in a uint dissector table. */
670 static dtbl_entry_t *
671 find_uint_dtbl_entry(dissector_table_t sub_dissectors, guint32 pattern)
673 switch (sub_dissectors->type) {
680 * You can do a port lookup in these tables.
686 * But you can't do a port lookup in any other types
689 g_assert_not_reached();
695 return g_hash_table_lookup(sub_dissectors->hash_table,
696 GUINT_TO_POINTER(pattern));
699 /* Add an entry to a uint dissector table. */
701 dissector_add(const char *name, guint32 pattern, dissector_handle_t handle)
703 dissector_table_t sub_dissectors;
704 dtbl_entry_t *dtbl_entry;
706 sub_dissectors = find_dissector_table(name);
708 g_assert(sub_dissectors);
709 switch (sub_dissectors->type) {
716 * You can do a port lookup in these tables.
722 * But you can't do a port lookup in any other types
725 g_assert_not_reached();
730 g_warning("%s: %s registering using a pattern of 0",
731 name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
734 dtbl_entry = g_hash_table_lookup(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern));
735 if (dtbl_entry != NULL) {
736 g_warning("%s: %s registering using pattern %d already registered by %s",
737 name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)),
738 pattern, proto_get_protocol_filter_name(proto_get_id(dtbl_entry->initial->protocol)));
741 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
742 dtbl_entry->current = handle;
743 dtbl_entry->initial = dtbl_entry->current;
745 /* do the table insertion */
746 g_hash_table_insert( sub_dissectors->hash_table,
747 GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
750 * Now add it to the list of handles that could be used with this
751 * table, because it *is* being used with this table.
753 dissector_add_handle(name, handle);
756 /* Delete the entry for a dissector in a uint dissector table
757 with a particular pattern. */
759 /* NOTE: this doesn't use the dissector call variable. It is included to */
760 /* be consistant with the dissector_add and more importantly to be used */
761 /* if the technique of adding a temporary dissector is implemented. */
762 /* If temporary dissectors are deleted, then the original dissector must */
765 dissector_delete(const char *name, guint32 pattern,
766 dissector_handle_t handle _U_)
768 dissector_table_t sub_dissectors = find_dissector_table( name);
769 dtbl_entry_t *dtbl_entry;
772 g_assert( sub_dissectors);
777 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
779 if (dtbl_entry != NULL) {
783 g_hash_table_remove(sub_dissectors->hash_table,
784 GUINT_TO_POINTER(pattern));
787 * Now free up the entry.
793 /* Change the entry for a dissector in a uint dissector table
794 with a particular pattern to use a new dissector handle. */
796 dissector_change(const char *name, guint32 pattern, dissector_handle_t handle)
798 dissector_table_t sub_dissectors = find_dissector_table( name);
799 dtbl_entry_t *dtbl_entry;
802 g_assert( sub_dissectors);
805 * See if the entry already exists. If so, reuse it.
807 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
808 if (dtbl_entry != NULL) {
809 dtbl_entry->current = handle;
814 * Don't create an entry if there is no dissector handle - I.E. the
815 * user said not to decode something that wasn't being decoded
816 * in the first place.
821 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
822 dtbl_entry->initial = NULL;
823 dtbl_entry->current = handle;
825 /* do the table insertion */
826 g_hash_table_insert( sub_dissectors->hash_table,
827 GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
830 /* Reset an entry in a uint dissector table to its initial value. */
832 dissector_reset(const char *name, guint32 pattern)
834 dissector_table_t sub_dissectors = find_dissector_table( name);
835 dtbl_entry_t *dtbl_entry;
838 g_assert( sub_dissectors);
843 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
845 if (dtbl_entry == NULL)
849 * Found - is there an initial value?
851 if (dtbl_entry->initial != NULL) {
852 dtbl_entry->current = dtbl_entry->initial;
854 g_hash_table_remove(sub_dissectors->hash_table,
855 GUINT_TO_POINTER(pattern));
860 /* Look for a given value in a given uint dissector table and, if found,
861 call the dissector with the arguments supplied, and return TRUE,
862 otherwise return FALSE. */
865 dissector_try_port_new(dissector_table_t sub_dissectors, guint32 port,
866 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean add_proto_name)
868 dtbl_entry_t *dtbl_entry;
869 struct dissector_handle *handle;
870 guint32 saved_match_port;
873 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, port);
874 if (dtbl_entry != NULL) {
876 * Is there currently a dissector handle for this entry?
878 handle = dtbl_entry->current;
879 if (handle == NULL) {
881 * No - pretend this dissector didn't exist,
882 * so that other dissectors might have a chance
883 * to dissect this packet.
889 * Save the current value of "pinfo->match_port",
890 * set it to the port that matched, call the
891 * dissector, and restore "pinfo->match_port".
893 saved_match_port = pinfo->match_port;
894 pinfo->match_port = port;
895 ret = call_dissector_work(handle, tvb, pinfo, tree, add_proto_name);
896 pinfo->match_port = saved_match_port;
899 * If a new-style dissector returned 0, it means that
900 * it didn't think this tvbuff represented a packet for
901 * its protocol, and didn't dissect anything.
903 * Old-style dissectors can't reject the packet.
905 * 0 is also returned if the protocol wasn't enabled.
907 * If the packet was rejected, we return FALSE, so that
908 * other dissectors might have a chance to dissect this
909 * packet, otherwise we return TRUE.
917 dissector_try_port(dissector_table_t sub_dissectors, guint32 port,
918 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
921 return dissector_try_port_new(sub_dissectors, port, tvb, pinfo, tree, TRUE);
923 /* Look for a given value in a given uint dissector table and, if found,
924 return the dissector handle for that value. */
926 dissector_get_port_handle(dissector_table_t sub_dissectors, guint32 port)
928 dtbl_entry_t *dtbl_entry;
930 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, port);
931 if (dtbl_entry != NULL)
932 return dtbl_entry->current;
937 /* Find an entry in a string dissector table. */
938 static dtbl_entry_t *
939 find_string_dtbl_entry(dissector_table_t sub_dissectors, const gchar *pattern)
941 switch (sub_dissectors->type) {
946 * You can do a string lookup in these tables.
952 * But you can't do a string lookup in any other types
955 g_assert_not_reached();
961 return g_hash_table_lookup(sub_dissectors->hash_table, pattern);
964 /* Add an entry to a string dissector table. */
966 dissector_add_string(const char *name, const gchar *pattern,
967 dissector_handle_t handle)
969 dissector_table_t sub_dissectors = find_dissector_table( name);
970 dtbl_entry_t *dtbl_entry;
973 g_assert( sub_dissectors);
975 switch (sub_dissectors->type) {
980 * You can do a string lookup in these tables.
986 * But you can't do a string lookup in any other types
989 g_assert_not_reached();
992 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
993 dtbl_entry->current = handle;
994 dtbl_entry->initial = dtbl_entry->current;
996 /* do the table insertion */
997 g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
998 (gpointer)dtbl_entry);
1001 * Now add it to the list of handles that could be used with this
1002 * table, because it *is* being used with this table.
1004 dissector_add_handle(name, handle);
1007 /* Delete the entry for a dissector in a string dissector table
1008 with a particular pattern. */
1010 /* NOTE: this doesn't use the dissector call variable. It is included to */
1011 /* be consistant with the dissector_add_string and more importantly to */
1012 /* be used if the technique of adding a temporary dissector is */
1014 /* If temporary dissectors are deleted, then the original dissector must */
1017 dissector_delete_string(const char *name, const gchar *pattern,
1018 dissector_handle_t handle _U_)
1020 dissector_table_t sub_dissectors = find_dissector_table( name);
1021 dtbl_entry_t *dtbl_entry;
1024 g_assert( sub_dissectors);
1029 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1031 if (dtbl_entry != NULL) {
1033 * Found - remove it.
1035 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1038 * Now free up the entry.
1044 /* Change the entry for a dissector in a string dissector table
1045 with a particular pattern to use a new dissector handle. */
1047 dissector_change_string(const char *name, gchar *pattern,
1048 dissector_handle_t handle)
1050 dissector_table_t sub_dissectors = find_dissector_table( name);
1051 dtbl_entry_t *dtbl_entry;
1054 g_assert( sub_dissectors);
1057 * See if the entry already exists. If so, reuse it.
1059 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1060 if (dtbl_entry != NULL) {
1061 dtbl_entry->current = handle;
1066 * Don't create an entry if there is no dissector handle - I.E. the
1067 * user said not to decode something that wasn't being decoded
1068 * in the first place.
1073 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1074 dtbl_entry->initial = NULL;
1075 dtbl_entry->current = handle;
1077 /* do the table insertion */
1078 g_hash_table_insert( sub_dissectors->hash_table, pattern,
1079 (gpointer)dtbl_entry);
1082 /* Reset an entry in a string sub-dissector table to its initial value. */
1084 dissector_reset_string(const char *name, const gchar *pattern)
1086 dissector_table_t sub_dissectors = find_dissector_table( name);
1087 dtbl_entry_t *dtbl_entry;
1090 g_assert( sub_dissectors);
1095 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1097 if (dtbl_entry == NULL)
1101 * Found - is there an initial value?
1103 if (dtbl_entry->initial != NULL) {
1104 dtbl_entry->current = dtbl_entry->initial;
1106 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1111 /* Look for a given string in a given dissector table and, if found, call
1112 the dissector with the arguments supplied, and return TRUE, otherwise
1115 dissector_try_string(dissector_table_t sub_dissectors, const gchar *string,
1116 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1118 dtbl_entry_t *dtbl_entry;
1119 struct dissector_handle *handle;
1121 const gchar *saved_match_string;
1123 /* XXX ASSERT instead ? */
1124 if (!string) return FALSE;
1125 dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1126 if (dtbl_entry != NULL) {
1128 * Is there currently a dissector handle for this entry?
1130 handle = dtbl_entry->current;
1131 if (handle == NULL) {
1133 * No - pretend this dissector didn't exist,
1134 * so that other dissectors might have a chance
1135 * to dissect this packet.
1141 * Save the current value of "pinfo->match_string",
1142 * set it to the string that matched, call the
1143 * dissector, and restore "pinfo->match_string".
1145 saved_match_string = pinfo->match_string;
1146 pinfo->match_string = string;
1147 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE);
1148 pinfo->match_string = saved_match_string;
1151 * If a new-style dissector returned 0, it means that
1152 * it didn't think this tvbuff represented a packet for
1153 * its protocol, and didn't dissect anything.
1155 * Old-style dissectors can't reject the packet.
1157 * 0 is also returned if the protocol wasn't enabled.
1159 * If the packet was rejected, we return FALSE, so that
1160 * other dissectors might have a chance to dissect this
1161 * packet, otherwise we return TRUE.
1168 /* Look for a given value in a given string dissector table and, if found,
1169 return the dissector handle for that value. */
1171 dissector_get_string_handle(dissector_table_t sub_dissectors,
1172 const gchar *string)
1174 dtbl_entry_t *dtbl_entry;
1176 dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1177 if (dtbl_entry != NULL)
1178 return dtbl_entry->current;
1184 dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry)
1186 return dtbl_entry->current;
1189 /* Add a handle to the list of handles that *could* be used with this
1190 table. That list is used by code in the UI. */
1192 dissector_add_handle(const char *name, dissector_handle_t handle)
1194 dissector_table_t sub_dissectors = find_dissector_table( name);
1198 g_assert(sub_dissectors != NULL);
1200 /* Is it already in this list? */
1201 entry = g_slist_find(sub_dissectors->dissector_handles, (gpointer)handle);
1202 if (entry != NULL) {
1204 * Yes - don't insert it again.
1209 /* Add it to the list. */
1210 sub_dissectors->dissector_handles =
1211 g_slist_append(sub_dissectors->dissector_handles, (gpointer)handle);
1215 dtbl_entry_get_initial_handle (dtbl_entry_t *dtbl_entry)
1217 return dtbl_entry->initial;
1220 /**************************************************/
1222 /* Routines to walk dissector tables */
1224 /**************************************************/
1226 typedef struct dissector_foreach_info {
1227 gpointer caller_data;
1228 DATFunc caller_func;
1230 const gchar *table_name;
1231 ftenum_t selector_type;
1232 } dissector_foreach_info_t;
1235 * Called for each entry in a dissector table.
1238 dissector_table_foreach_func (gpointer key, gpointer value, gpointer user_data)
1240 dissector_foreach_info_t *info;
1241 dtbl_entry_t *dtbl_entry;
1244 g_assert(user_data);
1247 if (dtbl_entry->current == NULL ||
1248 dtbl_entry->current->protocol == NULL) {
1250 * Either there is no dissector for this entry, or
1251 * the dissector doesn't have a protocol associated
1254 * XXX - should the latter check be done?
1260 info->caller_func(info->table_name, info->selector_type, key, value,
1265 * Called for each entry in the table of all dissector tables.
1268 dissector_all_tables_foreach_func (gpointer key, gpointer value, gpointer user_data)
1270 dissector_table_t sub_dissectors;
1271 dissector_foreach_info_t *info;
1274 g_assert(user_data);
1276 sub_dissectors = value;
1278 info->table_name = (gchar*) key;
1279 info->selector_type = get_dissector_table_selector_type(info->table_name);
1280 g_hash_table_foreach(sub_dissectors->hash_table, info->next_func, info);
1284 * Walk all dissector tables calling a user supplied function on each
1288 dissector_all_tables_foreach (DATFunc func,
1291 dissector_foreach_info_t info;
1293 info.caller_data = user_data;
1294 info.caller_func = func;
1295 info.next_func = dissector_table_foreach_func;
1296 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1300 * Walk one dissector table's hash table calling a user supplied function
1304 dissector_table_foreach (const char *name,
1308 dissector_foreach_info_t info;
1309 dissector_table_t sub_dissectors = find_dissector_table( name);
1311 info.table_name = name;
1312 info.selector_type = sub_dissectors->type;
1313 info.caller_func = func;
1314 info.caller_data = user_data;
1315 g_hash_table_foreach(sub_dissectors->hash_table, dissector_table_foreach_func, &info);
1319 * Walk one dissector table's list of handles calling a user supplied
1320 * function on each entry.
1323 dissector_table_foreach_handle(const char *name,
1324 DATFunc_handle func,
1327 dissector_table_t sub_dissectors = find_dissector_table( name);
1330 for (tmp = sub_dissectors->dissector_handles; tmp != NULL;
1331 tmp = g_slist_next(tmp))
1332 func(name, tmp->data, user_data);
1336 * Called for each entry in a dissector table.
1339 dissector_table_foreach_changed_func (gpointer key, gpointer value, gpointer user_data)
1341 dtbl_entry_t *dtbl_entry;
1342 dissector_foreach_info_t *info;
1345 g_assert(user_data);
1348 if (dtbl_entry->initial == dtbl_entry->current) {
1350 * Entry hasn't changed - don't call the function.
1356 info->caller_func(info->table_name, info->selector_type, key, value,
1361 * Walk all dissector tables calling a user supplied function only on
1362 * any entry that has been changed from its original state.
1365 dissector_all_tables_foreach_changed (DATFunc func,
1368 dissector_foreach_info_t info;
1370 info.caller_data = user_data;
1371 info.caller_func = func;
1372 info.next_func = dissector_table_foreach_changed_func;
1373 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1377 * Walk one dissector table calling a user supplied function only on
1378 * any entry that has been changed from its original state.
1381 dissector_table_foreach_changed (const char *name,
1385 dissector_foreach_info_t info;
1386 dissector_table_t sub_dissectors = find_dissector_table( name);
1388 info.table_name = name;
1389 info.selector_type = sub_dissectors->type;
1390 info.caller_func = func;
1391 info.caller_data = user_data;
1392 g_hash_table_foreach(sub_dissectors->hash_table,
1393 dissector_table_foreach_changed_func, &info);
1396 typedef struct dissector_foreach_table_info {
1397 gpointer caller_data;
1398 DATFunc_table caller_func;
1399 } dissector_foreach_table_info_t;
1402 * Called for each entry in the table of all dissector tables.
1405 dissector_all_tables_foreach_table_func (gpointer key, gpointer value, gpointer user_data)
1407 dissector_table_t table;
1408 dissector_foreach_table_info_t *info;
1412 (*info->caller_func)((gchar*)key, table->ui_name, info->caller_data);
1416 * Walk all dissector tables calling a user supplied function on each
1420 dissector_all_tables_foreach_table (DATFunc_table func,
1423 dissector_foreach_table_info_t info;
1425 info.caller_data = user_data;
1426 info.caller_func = func;
1427 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_table_func, &info);
1431 register_dissector_table(const char *name, const char *ui_name, ftenum_t type,
1434 dissector_table_t sub_dissectors;
1436 /* Create our hash-of-hashes if it doesn't already exist */
1437 if (!dissector_tables) {
1438 dissector_tables = g_hash_table_new( g_str_hash, g_str_equal );
1439 g_assert(dissector_tables);
1442 /* Make sure the registration is unique */
1443 if(g_hash_table_lookup( dissector_tables, name )) {
1444 g_error("The filter name %s (%s) is already registered - do you use a buggy plugin?", name, ui_name);
1447 /* Create and register the dissector table for this name; returns */
1448 /* a pointer to the dissector table. */
1449 sub_dissectors = g_malloc(sizeof (struct dissector_table));
1457 * XXX - there's no "g_uint_hash()" or "g_uint_equal()",
1458 * so we use "g_direct_hash()" and "g_direct_equal()".
1460 sub_dissectors->hash_table = g_hash_table_new( g_direct_hash,
1466 sub_dissectors->hash_table = g_hash_table_new( g_str_hash,
1471 g_assert_not_reached();
1473 sub_dissectors->dissector_handles = NULL;
1474 sub_dissectors->ui_name = ui_name;
1475 sub_dissectors->type = type;
1476 sub_dissectors->base = base;
1477 g_hash_table_insert( dissector_tables, (gpointer)name, (gpointer) sub_dissectors );
1478 return sub_dissectors;
1482 get_dissector_table_ui_name(const char *name)
1484 dissector_table_t sub_dissectors = find_dissector_table( name);
1486 return sub_dissectors->ui_name;
1490 get_dissector_table_selector_type(const char *name)
1492 dissector_table_t sub_dissectors = find_dissector_table( name);
1494 return sub_dissectors->type;
1498 get_dissector_table_base(const char *name)
1500 dissector_table_t sub_dissectors = find_dissector_table( name);
1502 return sub_dissectors->base;
1505 static GHashTable *heur_dissector_lists = NULL;
1508 heur_dissector_t dissector;
1509 protocol_t *protocol;
1510 } heur_dtbl_entry_t;
1512 /* Finds a heuristic dissector table by field name. */
1513 static heur_dissector_list_t *
1514 find_heur_dissector_list(const char *name)
1516 g_assert(heur_dissector_lists != NULL);
1517 return g_hash_table_lookup(heur_dissector_lists, name);
1521 heur_dissector_add(const char *name, heur_dissector_t dissector, int proto)
1523 heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1524 heur_dtbl_entry_t *dtbl_entry;
1527 g_assert(sub_dissectors != NULL);
1529 dtbl_entry = g_malloc(sizeof (heur_dtbl_entry_t));
1530 dtbl_entry->dissector = dissector;
1531 dtbl_entry->protocol = find_protocol_by_id(proto);
1533 /* do the table insertion */
1534 *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)dtbl_entry);
1539 static int find_matching_heur_dissector( gconstpointer a, gconstpointer b) {
1540 const heur_dtbl_entry_t *dtbl_entry_a = (const heur_dtbl_entry_t *) a;
1541 const heur_dtbl_entry_t *dtbl_entry_b = (const heur_dtbl_entry_t *) b;
1542 return (dtbl_entry_a->dissector == dtbl_entry_b->dissector) &&
1543 (dtbl_entry_a->protocol == dtbl_entry_b->protocol) ? 0 : 1;
1546 void heur_dissector_delete(const char *name, heur_dissector_t dissector, int proto) {
1547 heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1548 heur_dtbl_entry_t dtbl_entry;
1549 GSList* found_entry;
1552 g_assert(sub_dissectors != NULL);
1554 dtbl_entry.dissector = dissector;
1556 dtbl_entry.protocol = find_protocol_by_id(proto);
1558 found_entry = g_slist_find_custom(*sub_dissectors, (gpointer) &dtbl_entry, find_matching_heur_dissector);
1561 *sub_dissectors = g_slist_remove_link(*sub_dissectors, found_entry);
1562 g_free(g_slist_nth_data(found_entry, 1));
1563 g_slist_free_1(found_entry);
1569 dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
1570 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1573 const char *saved_proto;
1575 heur_dtbl_entry_t *dtbl_entry;
1576 guint16 saved_can_desegment;
1577 gint saved_layer_names_len = 0;
1579 /* can_desegment is set to 2 by anyone which offers this api/service.
1580 then everytime a subdissector is called it is decremented by one.
1581 thus only the subdissector immediately ontop of whoever offers this
1583 We save the current value of "can_desegment" for the
1584 benefit of TCP proxying dissectors such as SOCKS, so they
1585 can restore it and allow the dissectors they call to use
1586 the desegmentation service.
1588 saved_can_desegment=pinfo->can_desegment;
1589 pinfo->saved_can_desegment = saved_can_desegment;
1590 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1593 saved_proto = pinfo->current_proto;
1595 if (pinfo->layer_names != NULL)
1596 saved_layer_names_len = (gint) pinfo->layer_names->len;
1598 for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
1599 /* XXX - why set this now and above? */
1600 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1601 dtbl_entry = (heur_dtbl_entry_t *)entry->data;
1603 if (dtbl_entry->protocol != NULL &&
1604 !proto_is_protocol_enabled(dtbl_entry->protocol)) {
1606 * No - don't try this dissector.
1611 if (dtbl_entry->protocol != NULL) {
1612 pinfo->current_proto =
1613 proto_get_protocol_short_name(dtbl_entry->protocol);
1616 * Add the protocol name to the layers; we'll remove it
1617 * if the dissector fails.
1619 if (pinfo->layer_names) {
1620 if (pinfo->layer_names->len > 0)
1621 g_string_append(pinfo->layer_names, ":");
1622 g_string_append(pinfo->layer_names,
1623 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol)));
1626 EP_CHECK_CANARY(("before calling heuristic dissector for protocol: %s",
1627 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1628 if ((*dtbl_entry->dissector)(tvb, pinfo, tree)) {
1629 EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has accepted and dissected packet",
1630 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1634 EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has returned true",
1635 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1638 * That dissector didn't accept the packet, so
1639 * remove its protocol's name from the list
1642 if (pinfo->layer_names != NULL) {
1643 g_string_truncate(pinfo->layer_names, saved_layer_names_len);
1647 pinfo->current_proto = saved_proto;
1648 pinfo->can_desegment=saved_can_desegment;
1653 register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
1655 /* Create our hash-of-lists if it doesn't already exist */
1656 if (heur_dissector_lists == NULL) {
1657 heur_dissector_lists = g_hash_table_new(g_str_hash, g_str_equal);
1658 g_assert(heur_dissector_lists != NULL);
1661 /* Make sure the registration is unique */
1662 g_assert(g_hash_table_lookup(heur_dissector_lists, name) == NULL);
1664 *sub_dissectors = NULL; /* initially empty */
1665 g_hash_table_insert(heur_dissector_lists, (gpointer)name,
1666 (gpointer) sub_dissectors);
1670 * Register dissectors by name; used if one dissector always calls a
1671 * particular dissector, or if it bases the decision of which dissector
1672 * to call on something other than a numerical value or on "try a bunch
1673 * of dissectors until one likes the packet".
1677 * List of registered dissectors.
1679 static GHashTable *registered_dissectors = NULL;
1681 /* Get the short name of the protocol for a dissector handle, if it has
1684 dissector_handle_get_short_name(dissector_handle_t handle)
1686 if (handle->protocol == NULL) {
1688 * No protocol (see, for example, the handle for
1689 * dissecting the set of protocols where the first
1690 * octet of the payload is an OSI network layer protocol
1695 return proto_get_protocol_short_name(handle->protocol);
1698 /* Get the index of the protocol for a dissector handle, if it has
1701 dissector_handle_get_protocol_index(dissector_handle_t handle)
1703 if (handle->protocol == NULL) {
1705 * No protocol (see, for example, the handle for
1706 * dissecting the set of protocols where the first
1707 * octet of the payload is an OSI network layer protocol
1712 return proto_get_id(handle->protocol);
1715 /* Find a registered dissector by name. */
1717 find_dissector(const char *name)
1719 g_assert(registered_dissectors != NULL);
1720 return g_hash_table_lookup(registered_dissectors, name);
1723 /* Create an anonymous handle for a dissector. */
1725 create_dissector_handle(dissector_t dissector, int proto)
1727 struct dissector_handle *handle;
1729 handle = g_malloc(sizeof (struct dissector_handle));
1730 handle->name = NULL;
1731 handle->is_new = FALSE;
1732 handle->dissector.old = dissector;
1733 handle->protocol = find_protocol_by_id(proto);
1739 new_create_dissector_handle(new_dissector_t dissector, int proto)
1741 struct dissector_handle *handle;
1743 handle = g_malloc(sizeof (struct dissector_handle));
1744 handle->name = NULL;
1745 handle->is_new = TRUE;
1746 handle->dissector.new = dissector;
1747 handle->protocol = find_protocol_by_id(proto);
1752 /* Register a dissector by name. */
1754 register_dissector(const char *name, dissector_t dissector, int proto)
1756 struct dissector_handle *handle;
1758 /* Create our hash table if it doesn't already exist */
1759 if (registered_dissectors == NULL) {
1760 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1761 g_assert(registered_dissectors != NULL);
1764 /* Make sure the registration is unique */
1765 g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1767 handle = g_malloc(sizeof (struct dissector_handle));
1768 handle->name = name;
1769 handle->is_new = FALSE;
1770 handle->dissector.old = dissector;
1771 handle->protocol = find_protocol_by_id(proto);
1773 g_hash_table_insert(registered_dissectors, (gpointer)name,
1778 new_register_dissector(const char *name, new_dissector_t dissector, int proto)
1780 struct dissector_handle *handle;
1782 /* Create our hash table if it doesn't already exist */
1783 if (registered_dissectors == NULL) {
1784 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1785 g_assert(registered_dissectors != NULL);
1788 /* Make sure the registration is unique */
1789 g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1791 handle = g_malloc(sizeof (struct dissector_handle));
1792 handle->name = name;
1793 handle->is_new = TRUE;
1794 handle->dissector.new = dissector;
1795 handle->protocol = find_protocol_by_id(proto);
1797 g_hash_table_insert(registered_dissectors, (gpointer)name,
1801 /* Call a dissector through a handle but if the dissector rejected it
1805 call_dissector_only(dissector_handle_t handle, tvbuff_t *tvb,
1806 packet_info *pinfo, proto_tree *tree)
1810 g_assert(handle != NULL);
1811 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE);
1815 /* Call a dissector through a handle and if this fails call the "data"
1819 call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
1820 packet_info *pinfo, proto_tree *tree)
1824 ret = call_dissector_only(handle, tvb, pinfo, tree);
1827 * The protocol was disabled, or the dissector rejected
1828 * it. Just dissect this packet as data.
1830 g_assert(data_handle != NULL);
1831 g_assert(data_handle->protocol != NULL);
1832 call_dissector_work(data_handle, tvb, pinfo, tree, TRUE);
1833 return tvb_length(tvb);
1839 * Dumps the "layer type"/"decode as" associations to stdout, similar
1840 * to the proto_registrar_dump_*() routines.
1842 * There is one record per line. The fields are tab-delimited.
1844 * Field 1 = layer type, e.g. "tcp.port"
1845 * Field 2 = selector in decimal
1846 * Field 3 = "decode as" name, e.g. "http"
1851 dissector_dump_decodes_display(const gchar *table_name,
1852 ftenum_t selector_type _U_, gpointer key, gpointer value,
1853 gpointer user_data _U_)
1855 guint32 selector = (guint32)(unsigned long) key;
1856 dissector_table_t sub_dissectors = find_dissector_table(table_name);
1857 dtbl_entry_t *dtbl_entry;
1858 dissector_handle_t handle;
1860 const gchar *decode_as;
1862 g_assert(sub_dissectors);
1863 switch (sub_dissectors->type) {
1870 g_assert(dtbl_entry);
1872 handle = dtbl_entry->current;
1875 proto_id = dissector_handle_get_protocol_index(handle);
1877 if (proto_id != -1) {
1878 decode_as = proto_get_protocol_filter_name(proto_id);
1879 g_assert(decode_as != NULL);
1880 printf("%s\t%u\t%s\n", table_name, selector, decode_as);
1890 dissector_dump_decodes()
1892 dissector_all_tables_foreach(dissector_dump_decodes_display, NULL);
1895 static GPtrArray* post_dissectors = NULL;
1896 static guint num_of_postdissectors = 0;
1899 register_postdissector(dissector_handle_t handle)
1901 if (!post_dissectors)
1902 post_dissectors = g_ptr_array_new();
1904 g_ptr_array_add(post_dissectors, handle);
1905 num_of_postdissectors++;
1909 have_postdissector()
1912 dissector_handle_t handle;
1914 for(i = 0; i < num_of_postdissectors; i++) {
1915 handle = (dissector_handle_t) g_ptr_array_index(post_dissectors,i);
1917 if (handle->protocol != NULL
1918 && proto_is_protocol_enabled(handle->protocol)) {
1919 /* We have at least one enabled postdissector */
1927 call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1931 for(i = 0; i < num_of_postdissectors; i++) {
1932 call_dissector_only((dissector_handle_t) g_ptr_array_index(post_dissectors,i),