diff --git a/clopts_common.c b/clopts_common.c index 12227c4485..31aa75a8b8 100644 --- a/clopts_common.c +++ b/clopts_common.c @@ -30,6 +30,7 @@ #include #include +#include #include "clopts_common.h" @@ -52,6 +53,8 @@ handle_dashG_option(int argc, char **argv, char *progname) proto_registrar_dump_protocols(); else if (strcmp(argv[2], "values") == 0) proto_registrar_dump_values(); + else if (strcmp(argv[2], "decodes") == 0) + dissector_dump_decodes(); else { fprintf(stderr, "%s: Invalid \"%s\" option for -G flag\n", progname, argv[2]); diff --git a/epan/packet.c b/epan/packet.c index a9e2a0814b..2b3bc50c78 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -1696,3 +1696,58 @@ call_dissector(dissector_handle_t handle, tvbuff_t *tvb, } return ret; } + +/* + * Dumps the "layer type"/"decode as" associations to stdout, similar + * to the proto_registrar_dump_*() routines. + * + * There is one record per line. The fields are tab-delimited. + * + * Field 1 = layer type, e.g. "tcp.port" + * Field 2 = selector in decimal + * Field 3 = "decode as" name, e.g. "http" + */ + + +static void +dissector_dump_decodes_display(gchar *table_name, ftenum_t selector_type _U_, + gpointer key, gpointer value, gpointer user_data _U_) +{ + guint32 selector = (guint32) key; + dissector_table_t sub_dissectors = find_dissector_table(table_name); + dtbl_entry_t *dtbl_entry; + dissector_handle_t handle; + gint proto_id; + gchar *decode_as; + + g_assert(sub_dissectors); + switch (sub_dissectors->type) { + + case FT_UINT8: + case FT_UINT16: + case FT_UINT24: + case FT_UINT32: + dtbl_entry = value; + g_assert(dtbl_entry); + + handle = dtbl_entry->current; + g_assert(handle); + + proto_id = dissector_handle_get_protocol_index(handle); + + if (proto_id != -1) { + decode_as = proto_get_protocol_filter_name(proto_id); + g_assert(decode_as != NULL); + printf("%s\t%d\t%s\n", table_name, selector, decode_as); + } + break; + + default: + break; + } +} + +void +dissector_dump_decodes() { + dissector_all_tables_foreach(dissector_dump_decodes_display, NULL); +} diff --git a/epan/packet.h b/epan/packet.h index 7fcc67c929..5d16892b7d 100644 --- a/epan/packet.h +++ b/epan/packet.h @@ -367,4 +367,10 @@ extern void ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_ethertype, packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, int etype_id, int trailer_id, int fcs_len); +/* + * Dump layer/selector/dissector records in a fashion similar to the + * proto_registrar_dump_* routines. + */ +extern void dissector_dump_decodes(); + #endif /* packet.h */