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 * 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, const 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));
701 dissector_add_sanity_check(const char *name, guint32 pattern, dissector_handle_t handle, dissector_table_t sub_dissectors)
703 dtbl_entry_t *dtbl_entry;
706 g_warning("%s: %s registering using a pattern of 0",
707 name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
710 dtbl_entry = g_hash_table_lookup(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern));
711 if (dtbl_entry != NULL) {
712 g_warning("%s: %s registering using pattern %d already registered by %s",
713 name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)),
714 pattern, proto_get_protocol_filter_name(proto_get_id(dtbl_entry->initial->protocol)));
719 /* Add an entry to a uint dissector table. */
721 dissector_add(const char *name, const guint32 pattern, dissector_handle_t handle)
723 dissector_table_t sub_dissectors;
724 dtbl_entry_t *dtbl_entry;
726 sub_dissectors = find_dissector_table(name);
728 g_assert(sub_dissectors);
729 g_assert(handle!=NULL);
730 switch (sub_dissectors->type) {
737 * You can do a port lookup in these tables.
743 * But you can't do a port lookup in any other types
746 g_assert_not_reached();
750 dissector_add_sanity_check(name, pattern, handle, sub_dissectors);
753 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
754 dtbl_entry->current = handle;
755 dtbl_entry->initial = dtbl_entry->current;
757 /* do the table insertion */
758 g_hash_table_insert( sub_dissectors->hash_table,
759 GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
762 * Now add it to the list of handles that could be used with this
763 * table, because it *is* being used with this table.
765 dissector_add_handle(name, handle);
768 /* Delete the entry for a dissector in a uint dissector table
769 with a particular pattern. */
771 /* NOTE: this doesn't use the dissector call variable. It is included to */
772 /* be consistant with the dissector_add and more importantly to be used */
773 /* if the technique of adding a temporary dissector is implemented. */
774 /* If temporary dissectors are deleted, then the original dissector must */
777 dissector_delete(const char *name, const guint32 pattern,
778 dissector_handle_t handle _U_)
780 dissector_table_t sub_dissectors = find_dissector_table( name);
781 dtbl_entry_t *dtbl_entry;
784 g_assert( sub_dissectors);
789 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
791 if (dtbl_entry != NULL) {
795 g_hash_table_remove(sub_dissectors->hash_table,
796 GUINT_TO_POINTER(pattern));
799 * Now free up the entry.
805 /* Change the entry for a dissector in a uint dissector table
806 with a particular pattern to use a new dissector handle. */
808 dissector_change(const char *name, const guint32 pattern, dissector_handle_t handle)
810 dissector_table_t sub_dissectors = find_dissector_table( name);
811 dtbl_entry_t *dtbl_entry;
814 g_assert( sub_dissectors);
817 * See if the entry already exists. If so, reuse it.
819 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
820 if (dtbl_entry != NULL) {
821 dtbl_entry->current = handle;
826 * Don't create an entry if there is no dissector handle - I.E. the
827 * user said not to decode something that wasn't being decoded
828 * in the first place.
833 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
834 dtbl_entry->initial = NULL;
835 dtbl_entry->current = handle;
837 /* do the table insertion */
838 g_hash_table_insert( sub_dissectors->hash_table,
839 GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
842 /* Reset an entry in a uint dissector table to its initial value. */
844 dissector_reset(const char *name, const guint32 pattern)
846 dissector_table_t sub_dissectors = find_dissector_table( name);
847 dtbl_entry_t *dtbl_entry;
850 g_assert( sub_dissectors);
855 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
857 if (dtbl_entry == NULL)
861 * Found - is there an initial value?
863 if (dtbl_entry->initial != NULL) {
864 dtbl_entry->current = dtbl_entry->initial;
866 g_hash_table_remove(sub_dissectors->hash_table,
867 GUINT_TO_POINTER(pattern));
872 /* Look for a given value in a given uint dissector table and, if found,
873 call the dissector with the arguments supplied, and return TRUE,
874 otherwise return FALSE. */
877 dissector_try_port_new(dissector_table_t sub_dissectors, const guint32 port,
878 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, const gboolean add_proto_name)
880 dtbl_entry_t *dtbl_entry;
881 struct dissector_handle *handle;
882 guint32 saved_match_port;
885 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, port);
886 if (dtbl_entry != NULL) {
888 * Is there currently a dissector handle for this entry?
890 handle = dtbl_entry->current;
891 if (handle == NULL) {
893 * No - pretend this dissector didn't exist,
894 * so that other dissectors might have a chance
895 * to dissect this packet.
901 * Save the current value of "pinfo->match_port",
902 * set it to the port that matched, call the
903 * dissector, and restore "pinfo->match_port".
905 saved_match_port = pinfo->match_port;
906 pinfo->match_port = port;
907 ret = call_dissector_work(handle, tvb, pinfo, tree, add_proto_name);
908 pinfo->match_port = saved_match_port;
911 * If a new-style dissector returned 0, it means that
912 * it didn't think this tvbuff represented a packet for
913 * its protocol, and didn't dissect anything.
915 * Old-style dissectors can't reject the packet.
917 * 0 is also returned if the protocol wasn't enabled.
919 * If the packet was rejected, we return FALSE, so that
920 * other dissectors might have a chance to dissect this
921 * packet, otherwise we return TRUE.
929 dissector_try_port(dissector_table_t sub_dissectors, const guint32 port,
930 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
933 return dissector_try_port_new(sub_dissectors, port, tvb, pinfo, tree, TRUE);
935 /* Look for a given value in a given uint dissector table and, if found,
936 return the dissector handle for that value. */
938 dissector_get_port_handle(dissector_table_t sub_dissectors, guint32 port)
940 dtbl_entry_t *dtbl_entry;
942 dtbl_entry = find_uint_dtbl_entry(sub_dissectors, port);
943 if (dtbl_entry != NULL)
944 return dtbl_entry->current;
949 /* Find an entry in a string dissector table. */
950 static dtbl_entry_t *
951 find_string_dtbl_entry(dissector_table_t sub_dissectors, const gchar *pattern)
953 switch (sub_dissectors->type) {
958 * You can do a string lookup in these tables.
964 * But you can't do a string lookup in any other types
967 g_assert_not_reached();
973 return g_hash_table_lookup(sub_dissectors->hash_table, pattern);
976 /* Add an entry to a string dissector table. */
978 dissector_add_string(const char *name, const gchar *pattern,
979 dissector_handle_t handle)
981 dissector_table_t sub_dissectors = find_dissector_table( name);
982 dtbl_entry_t *dtbl_entry;
985 g_assert( sub_dissectors);
987 switch (sub_dissectors->type) {
992 * You can do a string lookup in these tables.
998 * But you can't do a string lookup in any other types
1001 g_assert_not_reached();
1004 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1005 dtbl_entry->current = handle;
1006 dtbl_entry->initial = dtbl_entry->current;
1008 /* do the table insertion */
1009 g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
1010 (gpointer)dtbl_entry);
1013 * Now add it to the list of handles that could be used with this
1014 * table, because it *is* being used with this table.
1016 dissector_add_handle(name, handle);
1019 /* Delete the entry for a dissector in a string dissector table
1020 with a particular pattern. */
1022 /* NOTE: this doesn't use the dissector call variable. It is included to */
1023 /* be consistant with the dissector_add_string and more importantly to */
1024 /* be used if the technique of adding a temporary dissector is */
1026 /* If temporary dissectors are deleted, then the original dissector must */
1029 dissector_delete_string(const char *name, const gchar *pattern,
1030 dissector_handle_t handle _U_)
1032 dissector_table_t sub_dissectors = find_dissector_table( name);
1033 dtbl_entry_t *dtbl_entry;
1036 g_assert( sub_dissectors);
1041 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1043 if (dtbl_entry != NULL) {
1045 * Found - remove it.
1047 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1050 * Now free up the entry.
1056 /* Change the entry for a dissector in a string dissector table
1057 with a particular pattern to use a new dissector handle. */
1059 dissector_change_string(const char *name, const gchar *pattern,
1060 dissector_handle_t handle)
1062 dissector_table_t sub_dissectors = find_dissector_table( name);
1063 dtbl_entry_t *dtbl_entry;
1066 g_assert( sub_dissectors);
1069 * See if the entry already exists. If so, reuse it.
1071 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1072 if (dtbl_entry != NULL) {
1073 dtbl_entry->current = handle;
1078 * Don't create an entry if there is no dissector handle - I.E. the
1079 * user said not to decode something that wasn't being decoded
1080 * in the first place.
1085 dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1086 dtbl_entry->initial = NULL;
1087 dtbl_entry->current = handle;
1089 /* do the table insertion */
1090 g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
1091 (gpointer)dtbl_entry);
1094 /* Reset an entry in a string sub-dissector table to its initial value. */
1096 dissector_reset_string(const char *name, const gchar *pattern)
1098 dissector_table_t sub_dissectors = find_dissector_table( name);
1099 dtbl_entry_t *dtbl_entry;
1102 g_assert( sub_dissectors);
1107 dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1109 if (dtbl_entry == NULL)
1113 * Found - is there an initial value?
1115 if (dtbl_entry->initial != NULL) {
1116 dtbl_entry->current = dtbl_entry->initial;
1118 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1123 /* Look for a given string in a given dissector table and, if found, call
1124 the dissector with the arguments supplied, and return TRUE, otherwise
1127 dissector_try_string(dissector_table_t sub_dissectors, const gchar *string,
1128 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1130 dtbl_entry_t *dtbl_entry;
1131 struct dissector_handle *handle;
1133 const gchar *saved_match_string;
1135 /* XXX ASSERT instead ? */
1136 if (!string) return FALSE;
1137 dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1138 if (dtbl_entry != NULL) {
1140 * Is there currently a dissector handle for this entry?
1142 handle = dtbl_entry->current;
1143 if (handle == NULL) {
1145 * No - pretend this dissector didn't exist,
1146 * so that other dissectors might have a chance
1147 * to dissect this packet.
1153 * Save the current value of "pinfo->match_string",
1154 * set it to the string that matched, call the
1155 * dissector, and restore "pinfo->match_string".
1157 saved_match_string = pinfo->match_string;
1158 pinfo->match_string = string;
1159 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE);
1160 pinfo->match_string = saved_match_string;
1163 * If a new-style dissector returned 0, it means that
1164 * it didn't think this tvbuff represented a packet for
1165 * its protocol, and didn't dissect anything.
1167 * Old-style dissectors can't reject the packet.
1169 * 0 is also returned if the protocol wasn't enabled.
1171 * If the packet was rejected, we return FALSE, so that
1172 * other dissectors might have a chance to dissect this
1173 * packet, otherwise we return TRUE.
1180 /* Look for a given value in a given string dissector table and, if found,
1181 return the dissector handle for that value. */
1183 dissector_get_string_handle(dissector_table_t sub_dissectors,
1184 const gchar *string)
1186 dtbl_entry_t *dtbl_entry;
1188 dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1189 if (dtbl_entry != NULL)
1190 return dtbl_entry->current;
1196 dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry)
1198 return dtbl_entry->current;
1201 /* Add a handle to the list of handles that *could* be used with this
1202 table. That list is used by code in the UI. */
1204 dissector_add_handle(const char *name, dissector_handle_t handle)
1206 dissector_table_t sub_dissectors = find_dissector_table( name);
1210 g_assert(sub_dissectors != NULL);
1212 /* Is it already in this list? */
1213 entry = g_slist_find(sub_dissectors->dissector_handles, (gpointer)handle);
1214 if (entry != NULL) {
1216 * Yes - don't insert it again.
1221 /* Add it to the list. */
1222 sub_dissectors->dissector_handles =
1223 g_slist_append(sub_dissectors->dissector_handles, (gpointer)handle);
1227 dtbl_entry_get_initial_handle (dtbl_entry_t *dtbl_entry)
1229 return dtbl_entry->initial;
1232 /**************************************************/
1234 /* Routines to walk dissector tables */
1236 /**************************************************/
1238 typedef struct dissector_foreach_info {
1239 gpointer caller_data;
1240 DATFunc caller_func;
1242 const gchar *table_name;
1243 ftenum_t selector_type;
1244 } dissector_foreach_info_t;
1247 * Called for each entry in a dissector table.
1250 dissector_table_foreach_func (gpointer key, gpointer value, gpointer user_data)
1252 dissector_foreach_info_t *info;
1253 dtbl_entry_t *dtbl_entry;
1256 g_assert(user_data);
1259 if (dtbl_entry->current == NULL ||
1260 dtbl_entry->current->protocol == NULL) {
1262 * Either there is no dissector for this entry, or
1263 * the dissector doesn't have a protocol associated
1266 * XXX - should the latter check be done?
1272 info->caller_func(info->table_name, info->selector_type, key, value,
1277 * Called for each entry in the table of all dissector tables.
1280 dissector_all_tables_foreach_func (gpointer key, gpointer value, gpointer user_data)
1282 dissector_table_t sub_dissectors;
1283 dissector_foreach_info_t *info;
1286 g_assert(user_data);
1288 sub_dissectors = value;
1290 info->table_name = (gchar*) key;
1291 info->selector_type = get_dissector_table_selector_type(info->table_name);
1292 g_hash_table_foreach(sub_dissectors->hash_table, info->next_func, info);
1296 * Walk all dissector tables calling a user supplied function on each
1300 dissector_all_tables_foreach (DATFunc func,
1303 dissector_foreach_info_t info;
1305 info.caller_data = user_data;
1306 info.caller_func = func;
1307 info.next_func = dissector_table_foreach_func;
1308 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1312 * Walk one dissector table's hash table calling a user supplied function
1316 dissector_table_foreach (const char *name,
1320 dissector_foreach_info_t info;
1321 dissector_table_t sub_dissectors = find_dissector_table( name);
1323 info.table_name = name;
1324 info.selector_type = sub_dissectors->type;
1325 info.caller_func = func;
1326 info.caller_data = user_data;
1327 g_hash_table_foreach(sub_dissectors->hash_table, dissector_table_foreach_func, &info);
1331 * Walk one dissector table's list of handles calling a user supplied
1332 * function on each entry.
1335 dissector_table_foreach_handle(const char *name,
1336 DATFunc_handle func,
1339 dissector_table_t sub_dissectors = find_dissector_table( name);
1342 for (tmp = sub_dissectors->dissector_handles; tmp != NULL;
1343 tmp = g_slist_next(tmp))
1344 func(name, tmp->data, user_data);
1348 * Called for each entry in a dissector table.
1351 dissector_table_foreach_changed_func (gpointer key, gpointer value, gpointer user_data)
1353 dtbl_entry_t *dtbl_entry;
1354 dissector_foreach_info_t *info;
1357 g_assert(user_data);
1360 if (dtbl_entry->initial == dtbl_entry->current) {
1362 * Entry hasn't changed - don't call the function.
1368 info->caller_func(info->table_name, info->selector_type, key, value,
1373 * Walk all dissector tables calling a user supplied function only on
1374 * any entry that has been changed from its original state.
1377 dissector_all_tables_foreach_changed (DATFunc func,
1380 dissector_foreach_info_t info;
1382 info.caller_data = user_data;
1383 info.caller_func = func;
1384 info.next_func = dissector_table_foreach_changed_func;
1385 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1389 * Walk one dissector table calling a user supplied function only on
1390 * any entry that has been changed from its original state.
1393 dissector_table_foreach_changed (const char *name,
1397 dissector_foreach_info_t info;
1398 dissector_table_t sub_dissectors = find_dissector_table( name);
1400 info.table_name = name;
1401 info.selector_type = sub_dissectors->type;
1402 info.caller_func = func;
1403 info.caller_data = user_data;
1404 g_hash_table_foreach(sub_dissectors->hash_table,
1405 dissector_table_foreach_changed_func, &info);
1408 typedef struct dissector_foreach_table_info {
1409 gpointer caller_data;
1410 DATFunc_table caller_func;
1411 } dissector_foreach_table_info_t;
1414 * Called for each entry in the table of all dissector tables.
1417 dissector_all_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
1419 dissector_table_t table;
1420 dissector_foreach_table_info_t *info;
1424 (*info->caller_func)((gchar*)key, table->ui_name, info->caller_data);
1428 * Walk all dissector tables calling a user supplied function on each
1432 dissector_all_tables_foreach_table (DATFunc_table func,
1435 dissector_foreach_table_info_t info;
1437 info.caller_data = user_data;
1438 info.caller_func = func;
1439 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_table_func, &info);
1443 register_dissector_table(const char *name, const char *ui_name, const ftenum_t type,
1446 dissector_table_t sub_dissectors;
1448 /* Create our hash-of-hashes if it doesn't already exist */
1449 if (!dissector_tables) {
1450 dissector_tables = g_hash_table_new( g_str_hash, g_str_equal );
1451 g_assert(dissector_tables);
1454 /* Make sure the registration is unique */
1455 if(g_hash_table_lookup( dissector_tables, name )) {
1456 g_error("The filter name %s (%s) is already registered - do you use a buggy plugin?", name, ui_name);
1459 /* Create and register the dissector table for this name; returns */
1460 /* a pointer to the dissector table. */
1461 sub_dissectors = g_malloc(sizeof (struct dissector_table));
1469 * XXX - there's no "g_uint_hash()" or "g_uint_equal()",
1470 * so we use "g_direct_hash()" and "g_direct_equal()".
1472 sub_dissectors->hash_table = g_hash_table_new( g_direct_hash,
1478 sub_dissectors->hash_table = g_hash_table_new( g_str_hash,
1483 g_assert_not_reached();
1485 sub_dissectors->dissector_handles = NULL;
1486 sub_dissectors->ui_name = ui_name;
1487 sub_dissectors->type = type;
1488 sub_dissectors->base = base;
1489 g_hash_table_insert( dissector_tables, (gpointer)name, (gpointer) sub_dissectors );
1490 return sub_dissectors;
1494 get_dissector_table_ui_name(const char *name)
1496 dissector_table_t sub_dissectors = find_dissector_table( name);
1498 return sub_dissectors->ui_name;
1502 get_dissector_table_selector_type(const char *name)
1504 dissector_table_t sub_dissectors = find_dissector_table( name);
1506 return sub_dissectors->type;
1510 get_dissector_table_base(const char *name)
1512 dissector_table_t sub_dissectors = find_dissector_table( name);
1514 return sub_dissectors->base;
1517 static GHashTable *heur_dissector_lists = NULL;
1520 heur_dissector_t dissector;
1521 protocol_t *protocol;
1522 } heur_dtbl_entry_t;
1524 /* Finds a heuristic dissector table by field name. */
1525 static heur_dissector_list_t *
1526 find_heur_dissector_list(const char *name)
1528 g_assert(heur_dissector_lists != NULL);
1529 return g_hash_table_lookup(heur_dissector_lists, name);
1533 heur_dissector_add(const char *name, heur_dissector_t dissector, const int proto)
1535 heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1536 heur_dtbl_entry_t *dtbl_entry;
1539 g_assert(sub_dissectors != NULL);
1541 dtbl_entry = g_malloc(sizeof (heur_dtbl_entry_t));
1542 dtbl_entry->dissector = dissector;
1543 dtbl_entry->protocol = find_protocol_by_id(proto);
1545 /* do the table insertion */
1546 *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)dtbl_entry);
1551 static int find_matching_heur_dissector( gconstpointer a, gconstpointer b) {
1552 const heur_dtbl_entry_t *dtbl_entry_a = (const heur_dtbl_entry_t *) a;
1553 const heur_dtbl_entry_t *dtbl_entry_b = (const heur_dtbl_entry_t *) b;
1554 return (dtbl_entry_a->dissector == dtbl_entry_b->dissector) &&
1555 (dtbl_entry_a->protocol == dtbl_entry_b->protocol) ? 0 : 1;
1558 void heur_dissector_delete(const char *name, heur_dissector_t dissector, const int proto) {
1559 heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1560 heur_dtbl_entry_t dtbl_entry;
1561 GSList* found_entry;
1564 g_assert(sub_dissectors != NULL);
1566 dtbl_entry.dissector = dissector;
1568 dtbl_entry.protocol = find_protocol_by_id(proto);
1570 found_entry = g_slist_find_custom(*sub_dissectors, (gpointer) &dtbl_entry, find_matching_heur_dissector);
1573 *sub_dissectors = g_slist_remove_link(*sub_dissectors, found_entry);
1574 g_free(g_slist_nth_data(found_entry, 1));
1575 g_slist_free_1(found_entry);
1581 dissector_try_heuristic(heur_dissector_list_t sub_dissectors,
1582 tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1585 const char *saved_proto;
1587 heur_dtbl_entry_t *dtbl_entry;
1588 guint16 saved_can_desegment;
1589 gint saved_layer_names_len = 0;
1591 /* can_desegment is set to 2 by anyone which offers this api/service.
1592 then everytime a subdissector is called it is decremented by one.
1593 thus only the subdissector immediately ontop of whoever offers this
1595 We save the current value of "can_desegment" for the
1596 benefit of TCP proxying dissectors such as SOCKS, so they
1597 can restore it and allow the dissectors they call to use
1598 the desegmentation service.
1600 saved_can_desegment=pinfo->can_desegment;
1601 pinfo->saved_can_desegment = saved_can_desegment;
1602 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1605 saved_proto = pinfo->current_proto;
1607 if (pinfo->layer_names != NULL)
1608 saved_layer_names_len = (gint) pinfo->layer_names->len;
1610 for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
1611 /* XXX - why set this now and above? */
1612 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1613 dtbl_entry = (heur_dtbl_entry_t *)entry->data;
1615 if (dtbl_entry->protocol != NULL &&
1616 !proto_is_protocol_enabled(dtbl_entry->protocol)) {
1618 * No - don't try this dissector.
1623 if (dtbl_entry->protocol != NULL) {
1624 pinfo->current_proto =
1625 proto_get_protocol_short_name(dtbl_entry->protocol);
1628 * Add the protocol name to the layers; we'll remove it
1629 * if the dissector fails.
1631 if (pinfo->layer_names) {
1632 if (pinfo->layer_names->len > 0)
1633 g_string_append(pinfo->layer_names, ":");
1634 g_string_append(pinfo->layer_names,
1635 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol)));
1638 EP_CHECK_CANARY(("before calling heuristic dissector for protocol: %s",
1639 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1640 if ((*dtbl_entry->dissector)(tvb, pinfo, tree)) {
1641 EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has accepted and dissected packet",
1642 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1646 EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has returned true",
1647 proto_get_protocol_filter_name(proto_get_id(dtbl_entry->protocol))));
1650 * That dissector didn't accept the packet, so
1651 * remove its protocol's name from the list
1654 if (pinfo->layer_names != NULL) {
1655 g_string_truncate(pinfo->layer_names, saved_layer_names_len);
1659 pinfo->current_proto = saved_proto;
1660 pinfo->can_desegment=saved_can_desegment;
1665 register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
1667 /* Create our hash-of-lists if it doesn't already exist */
1668 if (heur_dissector_lists == NULL) {
1669 heur_dissector_lists = g_hash_table_new(g_str_hash, g_str_equal);
1670 g_assert(heur_dissector_lists != NULL);
1673 /* Make sure the registration is unique */
1674 g_assert(g_hash_table_lookup(heur_dissector_lists, name) == NULL);
1676 *sub_dissectors = NULL; /* initially empty */
1677 g_hash_table_insert(heur_dissector_lists, (gpointer)name,
1678 (gpointer) sub_dissectors);
1682 * Register dissectors by name; used if one dissector always calls a
1683 * particular dissector, or if it bases the decision of which dissector
1684 * to call on something other than a numerical value or on "try a bunch
1685 * of dissectors until one likes the packet".
1689 * List of registered dissectors.
1691 static GHashTable *registered_dissectors = NULL;
1693 /* Get the short name of the protocol for a dissector handle, if it has
1696 dissector_handle_get_short_name(const dissector_handle_t handle)
1698 if (handle->protocol == NULL) {
1700 * No protocol (see, for example, the handle for
1701 * dissecting the set of protocols where the first
1702 * octet of the payload is an OSI network layer protocol
1707 return proto_get_protocol_short_name(handle->protocol);
1710 /* Get the index of the protocol for a dissector handle, if it has
1713 dissector_handle_get_protocol_index(const dissector_handle_t handle)
1715 if (handle->protocol == NULL) {
1717 * No protocol (see, for example, the handle for
1718 * dissecting the set of protocols where the first
1719 * octet of the payload is an OSI network layer protocol
1724 return proto_get_id(handle->protocol);
1727 /* Find a registered dissector by name. */
1729 find_dissector(const char *name)
1731 g_assert(registered_dissectors != NULL);
1732 return g_hash_table_lookup(registered_dissectors, name);
1735 /* Create an anonymous handle for a dissector. */
1737 create_dissector_handle(dissector_t dissector, const int proto)
1739 struct dissector_handle *handle;
1741 handle = g_malloc(sizeof (struct dissector_handle));
1742 handle->name = NULL;
1743 handle->is_new = FALSE;
1744 handle->dissector.old = dissector;
1745 handle->protocol = find_protocol_by_id(proto);
1751 new_create_dissector_handle(new_dissector_t dissector, const int proto)
1753 struct dissector_handle *handle;
1755 handle = g_malloc(sizeof (struct dissector_handle));
1756 handle->name = NULL;
1757 handle->is_new = TRUE;
1758 handle->dissector.new = dissector;
1759 handle->protocol = find_protocol_by_id(proto);
1764 /* Register a dissector by name. */
1766 register_dissector(const char *name, dissector_t dissector, const int proto)
1768 struct dissector_handle *handle;
1770 /* Create our hash table if it doesn't already exist */
1771 if (registered_dissectors == NULL) {
1772 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1773 g_assert(registered_dissectors != NULL);
1776 /* Make sure the registration is unique */
1777 g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1779 handle = g_malloc(sizeof (struct dissector_handle));
1780 handle->name = name;
1781 handle->is_new = FALSE;
1782 handle->dissector.old = dissector;
1783 handle->protocol = find_protocol_by_id(proto);
1785 g_hash_table_insert(registered_dissectors, (gpointer)name,
1790 new_register_dissector(const char *name, new_dissector_t dissector, const int proto)
1792 struct dissector_handle *handle;
1794 /* Create our hash table if it doesn't already exist */
1795 if (registered_dissectors == NULL) {
1796 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1797 g_assert(registered_dissectors != NULL);
1800 /* Make sure the registration is unique */
1801 g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1803 handle = g_malloc(sizeof (struct dissector_handle));
1804 handle->name = name;
1805 handle->is_new = TRUE;
1806 handle->dissector.new = dissector;
1807 handle->protocol = find_protocol_by_id(proto);
1809 g_hash_table_insert(registered_dissectors, (gpointer)name,
1813 /* Call a dissector through a handle but if the dissector rejected it
1817 call_dissector_only(dissector_handle_t handle, tvbuff_t *tvb,
1818 packet_info *pinfo, proto_tree *tree)
1822 g_assert(handle != NULL);
1823 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE);
1827 /* Call a dissector through a handle and if this fails call the "data"
1831 call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
1832 packet_info *pinfo, proto_tree *tree)
1836 ret = call_dissector_only(handle, tvb, pinfo, tree);
1839 * The protocol was disabled, or the dissector rejected
1840 * it. Just dissect this packet as data.
1842 g_assert(data_handle != NULL);
1843 g_assert(data_handle->protocol != NULL);
1844 call_dissector_work(data_handle, tvb, pinfo, tree, TRUE);
1845 return tvb_length(tvb);
1851 * Dumps the "layer type"/"decode as" associations to stdout, similar
1852 * to the proto_registrar_dump_*() routines.
1854 * There is one record per line. The fields are tab-delimited.
1856 * Field 1 = layer type, e.g. "tcp.port"
1857 * Field 2 = selector in decimal
1858 * Field 3 = "decode as" name, e.g. "http"
1863 dissector_dump_decodes_display(const gchar *table_name,
1864 ftenum_t selector_type _U_, const gpointer key, const gpointer value,
1865 gpointer user_data _U_)
1867 guint32 selector = (guint32)(unsigned long) key;
1868 dissector_table_t sub_dissectors = find_dissector_table(table_name);
1869 dtbl_entry_t *dtbl_entry;
1870 dissector_handle_t handle;
1872 const gchar *decode_as;
1874 g_assert(sub_dissectors);
1875 switch (sub_dissectors->type) {
1882 g_assert(dtbl_entry);
1884 handle = dtbl_entry->current;
1887 proto_id = dissector_handle_get_protocol_index(handle);
1889 if (proto_id != -1) {
1890 decode_as = proto_get_protocol_filter_name(proto_id);
1891 g_assert(decode_as != NULL);
1892 printf("%s\t%u\t%s\n", table_name, selector, decode_as);
1902 dissector_dump_decodes()
1904 dissector_all_tables_foreach(dissector_dump_decodes_display, NULL);
1907 static GPtrArray* post_dissectors = NULL;
1908 static guint num_of_postdissectors = 0;
1911 register_postdissector(dissector_handle_t handle)
1913 if (!post_dissectors)
1914 post_dissectors = g_ptr_array_new();
1916 g_ptr_array_add(post_dissectors, handle);
1917 num_of_postdissectors++;
1921 have_postdissector()
1924 dissector_handle_t handle;
1926 for(i = 0; i < num_of_postdissectors; i++) {
1927 handle = (dissector_handle_t) g_ptr_array_index(post_dissectors,i);
1929 if (handle->protocol != NULL
1930 && proto_is_protocol_enabled(handle->protocol)) {
1931 /* We have at least one enabled postdissector */
1939 call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1943 for(i = 0; i < num_of_postdissectors; i++) {
1944 call_dissector_only((dissector_handle_t) g_ptr_array_index(post_dissectors,i),