Coverage Report

Created: 2026-08-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-media.c
Line
Count
Source
1
/* packet-media.c
2
 * Routines for displaying an undissected media type (default case),
3
 * based on the generic "data" dissector.
4
 *
5
 * (C) Olivier Biot, 2004
6
 *
7
 * Refer to the AUTHORS file or the AUTHORS section in the man page
8
 * for contacting the author(s) of this file.
9
 *
10
 * Wireshark - Network traffic analyzer
11
 * By Gerald Combs <gerald@wireshark.org>
12
 * Copyright 1998 Gerald Combs
13
 *
14
 * SPDX-License-Identifier: GPL-2.0-or-later
15
 */
16
17
#include "config.h"
18
19
#include <epan/packet.h>
20
21
#include <wsutil/str_util.h>
22
23
#include "packet-media-type.h"
24
25
void proto_register_media(void);
26
27
static int proto_media;
28
static int hf_media_type;
29
static int ett_media;
30
static heur_dissector_list_t heur_subdissector_list;
31
static dissector_table_t media_type_suffix_table;
32
33
static int
34
dissect_media(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
35
515
{
36
515
    int bytes;
37
515
    proto_item *ti;
38
515
    proto_tree *media_tree = 0;
39
515
    media_content_info_t *content_info = (media_content_info_t *)data;
40
515
    heur_dtbl_entry_t *hdtbl_entry;
41
515
    char* suffix;
42
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.
47
     */
48
49
    /*
50
     * RFC 6838 4.2 Naming Requirements
51
     * "Characters after last plus always specify a structured syntax suffix"
52
     */
53
515
    if (pinfo->match_string &&
54
449
        (suffix = strrchr(pinfo->match_string, '+'))) {
55
56
60
        if ((bytes = dissector_try_string_with_data(media_type_suffix_table,
57
60
                suffix + 1, tvb, pinfo, tree, true, data)) > 0) {
58
33
            return bytes;
59
33
        }
60
60
    }
61
62
482
    if (dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, tree, &hdtbl_entry, data)) {
63
0
        return tvb_reported_length(tvb);
64
0
    }
65
66
    /* Add media type to the INFO column if it is visible */
67
482
    col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", (pinfo->match_string) ? pinfo->match_string : "");
68
69
482
    if (tree) {
70
464
        if ( (bytes = tvb_reported_length(tvb)) > 0 )
71
464
        {
72
464
            ti = proto_tree_add_item(tree, proto_media, tvb, 0, -1, ENC_NA);
73
464
            media_tree = proto_item_add_subtree(ti, ett_media);
74
75
464
            if (content_info != NULL && content_info->media_str != NULL) {
76
                /* The media type has parameters */
77
78
0
                proto_tree_add_bytes_format_value(media_tree, hf_media_type, tvb, 0, bytes,
79
0
                    NULL, "%s; %s (%d byte%s)",
80
0
                    pinfo->match_string, content_info->media_str,
81
0
                    bytes, plurality(bytes, "", "s"));
82
464
            } else {
83
                /* The media type has no parameters */
84
464
                proto_tree_add_bytes_format_value(media_tree, hf_media_type, tvb, 0, bytes,
85
464
                    NULL, "%s (%d byte%s)",
86
464
                    pinfo->match_string ? pinfo->match_string : "",
87
464
                    bytes, plurality(bytes, "", "s"));
88
464
            }
89
464
        }
90
464
    }
91
92
482
    return tvb_reported_length(tvb);
93
482
}
94
95
void
96
proto_register_media(void)
97
16
{
98
16
    static hf_register_info hf[] = {
99
16
      { &hf_media_type,
100
16
        { "Media type", "media.type",
101
16
          FT_BYTES, BASE_NONE, NULL, 0,
102
16
          NULL, HFILL }},
103
16
    };
104
16
    static int *ett[] = {
105
16
        &ett_media
106
16
    };
107
108
16
    proto_media = proto_register_protocol ("Media Type", "Media", "media");
109
16
    register_dissector("media", dissect_media, proto_media);
110
16
    heur_subdissector_list = register_heur_dissector_list_with_description("media", "Media type", proto_media);
111
16
    proto_register_field_array(proto_media, hf, array_length(hf));
112
16
    proto_register_subtree_array(ett, array_length(ett));
113
114
    /*
115
     * "Media" is used to dissect something whose normal dissector
116
     * is disabled, so it cannot itself be disabled.
117
     */
118
16
    proto_set_cant_toggle(proto_media);
119
120
    /*
121
     * https://www.iana.org/assignments/media-type-structured-suffix/media-type-structured-suffix.xhtml
122
     * Structured Suffixes ("zzz" in "xxx/yyy+zzz") can be used as fallback
123
     * when the exact media type is not registered.
124
     */
125
16
    media_type_suffix_table = register_dissector_table("media_type.suffix",
126
16
        "Internet media type structured suffix",
127
16
        proto_media, FT_STRING, STRING_CASE_INSENSITIVE);
128
16
}
129
130
/*
131
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
132
 *
133
 * Local variables:
134
 * c-basic-offset: 4
135
 * tab-width: 8
136
 * indent-tabs-mode: nil
137
 * End:
138
 *
139
 * vi: set shiftwidth=4 tabstop=8 expandtab:
140
 * :indentSize=4:tabSize=8:noTabs=true:
141
 */