Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-discard.c
blob1231dfcdad8075d69f62996c3d6e0bff94d83723
1 /* packet-discard.c
2 * Routines for Discard Protocol dissection
4 * Discard specs taken from RFC 863
5 * https://tools.ietf.org/html/rfc863
7 * Inspiration from packet-chargen.c and packet-data.
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include "config.h"
18 #include <epan/packet.h>
19 #include <epan/prefs.h>
20 #include <wsutil/wsgcrypt.h>
21 #include <wsutil/to_str.h>
23 #define DISCARD_PORT_UDP 9
24 #define DISCARD_PORT_TCP 9
26 void proto_register_discard(void);
27 void proto_reg_handoff_discard(void);
29 static int proto_discard;
31 static int hf_discard_data;
32 static int hf_discard_text;
33 static int hf_discard_md5_hash;
34 static int hf_discard_len;
36 static bool show_as_text;
37 static bool generate_md5_hash;
39 static int ett_discard;
41 /* dissect_discard - dissects discard packet data
42 * tvb - tvbuff for packet data (IN)
43 * pinfo - packet info
44 * proto_tree - resolved protocol tree
46 static int
47 dissect_discard(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dissector_data _U_)
49 proto_tree* discard_tree;
50 proto_item* ti;
51 uint32_t len;
52 uint32_t cap_len;
54 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DISCARD");
56 if (show_as_text) {
57 col_set_str(pinfo->cinfo, COL_INFO, "Discard: ");
58 } else {
59 col_set_str(pinfo->cinfo, COL_INFO, "Discard");
62 ti = proto_tree_add_item(tree, proto_discard, tvb, 0, -1, ENC_NA);
63 discard_tree = proto_item_add_subtree(ti, ett_discard);
65 len = tvb_reported_length(tvb);
66 cap_len = tvb_captured_length(tvb);
68 proto_tree_add_item(discard_tree, hf_discard_data, tvb, 0, -1, ENC_NA);
70 if (show_as_text) {
71 char *display_str;
73 proto_tree_add_item_ret_display_string(discard_tree, hf_discard_text, tvb, 0, -1, ENC_ASCII, pinfo->pool, &display_str);
74 col_append_str(pinfo->cinfo, COL_INFO, display_str);
77 if (generate_md5_hash) {
78 const uint8_t *cp;
79 uint8_t digest[HASH_MD5_LENGTH];
80 const char *digest_string;
82 cp = tvb_get_ptr(tvb, 0, cap_len);
84 gcry_md_hash_buffer(GCRY_MD_MD5, digest, cp, cap_len);
85 digest_string = bytes_to_str_punct(pinfo->pool, digest, HASH_MD5_LENGTH, '\0');
87 ti = proto_tree_add_string(discard_tree, hf_discard_md5_hash, tvb, 0, 0, digest_string);
88 proto_item_set_generated(ti);
91 ti = proto_tree_add_uint(discard_tree, hf_discard_len, tvb, 0, 0, len);
92 proto_item_set_generated(ti);
94 if(len > cap_len) {
96 * Trigger _ws.short, e.g. [Packet size limited during capture: DISCARD truncated]
98 tvb_get_ptr(tvb, 0, len);
101 return cap_len;
104 void
105 proto_register_discard(void)
107 static hf_register_info hf[] = {
108 { &hf_discard_data, {
109 "Data", "discard.data",
110 FT_BYTES, BASE_NONE, NULL, 0,
111 NULL, HFILL }
113 { &hf_discard_text, {
114 "Text", "discard.text",
115 FT_STRING, BASE_NONE, NULL, 0,
116 NULL, HFILL }
118 { &hf_discard_md5_hash, {
119 "Payload MD5 hash", "discard.md5_hash",
120 FT_STRING, BASE_NONE, NULL, 0,
121 NULL, HFILL }
123 { &hf_discard_len, {
124 "Reported Length", "discard.len",
125 FT_UINT32, BASE_DEC, NULL, 0,
126 NULL, HFILL }
130 static int *ett[] = {
131 &ett_discard,
134 module_t *module_data;
136 proto_discard = proto_register_protocol("Discard Protocol", "DISCARD", "discard");
138 proto_register_field_array(proto_discard, hf, array_length(hf));
139 proto_register_subtree_array(ett, array_length(ett));
141 module_data = prefs_register_protocol(proto_discard, NULL);
143 prefs_register_bool_preference(module_data,
144 "show_as_text",
145 "Show data as text",
146 "Show data as text in the Packet Details pane",
147 &show_as_text);
149 prefs_register_bool_preference(module_data,
150 "md5_hash",
151 "Generate MD5 hash",
152 "Whether or not MD5 hashes should be generated and shown for each payload.",
153 &generate_md5_hash);
156 void
157 proto_reg_handoff_discard(void)
159 dissector_handle_t discard_handle;
161 discard_handle = create_dissector_handle(dissect_discard, proto_discard);
162 dissector_add_uint_with_preference("udp.port", DISCARD_PORT_UDP, discard_handle);
163 dissector_add_uint_with_preference("tcp.port", DISCARD_PORT_TCP, discard_handle);
167 * Editor modelines - https://www.wireshark.org/tools/modelines.html
169 * Local variables:
170 * c-basic-offset: 8
171 * tab-width: 8
172 * indent-tabs-mode: t
173 * End:
175 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
176 * :indentSize=8:tabSize=8:noTabs=false: