2 * Routines for displaying an undissected media type (default case),
3 * based on the generic "data" dissector.
5 * (C) Olivier Biot, 2004
7 * Refer to the AUTHORS file or the AUTHORS section in the man page
8 * for contacting the author(s) of this file.
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
19 #include <epan/packet.h>
21 #include <wsutil/str_util.h>
23 #include "packet-media-type.h"
25 void proto_register_media(void);
27 static int proto_media
;
28 static int hf_media_type
;
30 static heur_dissector_list_t heur_subdissector_list
;
31 static dissector_table_t media_type_suffix_table
;
34 dissect_media(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
38 proto_tree
*media_tree
= 0;
39 media_content_info_t
*content_info
= (media_content_info_t
*)data
;
40 heur_dtbl_entry_t
*hdtbl_entry
;
43 /* XXX - Should we move the other media_type table here, and have
44 * dissectors always call this dissector instead of invoking the table,
45 * similar to the Ethertype dissector?
46 * It would make Decode As with Media Types easier.
50 * RFC 6838 4.2 Naming Requirements
51 * "Characters after last plus always specify a structured syntax suffix"
53 if (pinfo
->match_string
&&
54 (suffix
= strrchr(pinfo
->match_string
, '+'))) {
56 if ((bytes
= dissector_try_string_new(media_type_suffix_table
,
57 suffix
+ 1, tvb
, pinfo
, tree
, true, data
)) > 0) {
62 if (dissector_try_heuristic(heur_subdissector_list
, tvb
, pinfo
, tree
, &hdtbl_entry
, data
)) {
63 return tvb_reported_length(tvb
);
66 /* Add media type to the INFO column if it is visible */
67 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " (%s)", (pinfo
->match_string
) ? pinfo
->match_string
: "");
70 if ( (bytes
= tvb_reported_length(tvb
)) > 0 )
72 ti
= proto_tree_add_item(tree
, proto_media
, tvb
, 0, -1, ENC_NA
);
73 media_tree
= proto_item_add_subtree(ti
, ett_media
);
75 if (content_info
!= NULL
&& content_info
->media_str
!= NULL
) {
76 /* The media type has parameters */
78 proto_tree_add_bytes_format_value(media_tree
, hf_media_type
, tvb
, 0, bytes
,
79 NULL
, "%s; %s (%d byte%s)",
80 pinfo
->match_string
, content_info
->media_str
,
81 bytes
, plurality(bytes
, "", "s"));
83 /* The media type has no parameters */
84 proto_tree_add_bytes_format_value(media_tree
, hf_media_type
, tvb
, 0, bytes
,
85 NULL
, "%s (%d byte%s)",
86 pinfo
->match_string
? pinfo
->match_string
: "",
87 bytes
, plurality(bytes
, "", "s"));
92 return tvb_reported_length(tvb
);
96 proto_register_media(void)
98 static hf_register_info hf
[] = {
100 { "Media type", "media.type",
101 FT_BYTES
, BASE_NONE
, NULL
, 0,
104 static int *ett
[] = {
108 proto_media
= proto_register_protocol (
109 "Media Type", /* name */
110 "Media", /* short name */
113 register_dissector("media", dissect_media
, proto_media
);
114 heur_subdissector_list
= register_heur_dissector_list_with_description("media", "Media type", proto_media
);
115 proto_register_field_array(proto_media
, hf
, array_length(hf
));
116 proto_register_subtree_array(ett
, array_length(ett
));
119 * "Media" is used to dissect something whose normal dissector
120 * is disabled, so it cannot itself be disabled.
122 proto_set_cant_toggle(proto_media
);
125 * https://www.iana.org/assignments/media-type-structured-suffix/media-type-structured-suffix.xhtml
126 * Structured Suffixes ("zzz" in "xxx/yyy+zzz") can be used as fallback
127 * when the exact media type is not registered.
129 media_type_suffix_table
= register_dissector_table("media_type.suffix",
130 "Internet media type structured suffix",
131 proto_media
, FT_STRING
, STRING_CASE_INSENSITIVE
);
135 * Editor modelines - https://www.wireshark.org/tools/modelines.html
140 * indent-tabs-mode: nil
143 * vi: set shiftwidth=4 tabstop=8 expandtab:
144 * :indentSize=4:tabSize=8:noTabs=true: