MSWSP: add ids for another unknown Property Set
[wireshark-wip.git] / epan / dissectors / packet-data.c
blobe6a2830c9288dfe8f5a7b3dcc6e1e7e5045b0cd0
1 /* packet-data.c
2 * Routines for raw data (default case)
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #define NEW_PROTO_TREE_API
28 #include "config.h"
30 #include <glib.h>
32 #include <wsutil/md5.h>
34 #include <epan/packet.h>
35 #include <epan/prefs.h>
36 #include "packet-data.h"
38 /* proto_data cannot be static because it's referenced in the
39 * print routines
41 void proto_register_data(void);
43 int proto_data = -1;
45 #define DATA_HFI_INIT HFI_INIT(proto_data)
47 static header_field_info hfi_data_data DATA_HFI_INIT =
48 { "Data", "data.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL };
50 static header_field_info hfi_data_text DATA_HFI_INIT =
51 { "Text", "data.text", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL };
53 static header_field_info hfi_data_len DATA_HFI_INIT =
54 { "Length", "data.len", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL };
56 static header_field_info hfi_data_md5_hash DATA_HFI_INIT =
57 { "Payload MD5 hash", "data.md5_hash", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL };
59 static gboolean new_pane = FALSE;
60 static gboolean show_as_text = FALSE;
61 static gboolean generate_md5_hash = FALSE;
63 static gint ett_data = -1;
65 static void
66 dissect_data(tvbuff_t *tvb, packet_info *pinfo _U_ , proto_tree *tree)
68 gint bytes;
70 if (tree) {
71 bytes = tvb_length_remaining(tvb, 0);
72 if (bytes > 0) {
73 tvbuff_t *data_tvb;
74 proto_item *ti;
75 proto_tree *data_tree;
76 if (new_pane) {
77 guint8 *real_data = (guint8 *)tvb_memdup(NULL, tvb, 0, bytes);
78 data_tvb = tvb_new_child_real_data(tvb,real_data,bytes,bytes);
79 tvb_set_free_cb(data_tvb, g_free);
80 add_new_data_source(pinfo, data_tvb, "Not dissected data bytes");
81 } else {
82 data_tvb = tvb;
84 ti = proto_tree_add_protocol_format(tree, proto_data, tvb,
86 bytes, "Data (%d byte%s)", bytes,
87 plurality(bytes, "", "s"));
88 data_tree = proto_item_add_subtree(ti, ett_data);
90 proto_tree_add_item(data_tree, &hfi_data_data, data_tvb, 0, bytes, ENC_NA);
92 if (show_as_text) {
93 proto_tree_add_item(data_tree, &hfi_data_text, data_tvb, 0, bytes, ENC_ASCII|ENC_NA);
96 if(generate_md5_hash) {
97 const guint8 *cp;
98 md5_state_t md_ctx;
99 md5_byte_t digest[16];
100 const gchar *digest_string;
102 cp = tvb_get_ptr(tvb, 0, bytes);
104 md5_init(&md_ctx);
105 md5_append(&md_ctx, cp, bytes);
106 md5_finish(&md_ctx, digest);
108 digest_string = bytestring_to_str(digest, 16, '\0');
109 ti = proto_tree_add_string(data_tree, &hfi_data_md5_hash, tvb, 0, 0, digest_string);
110 PROTO_ITEM_SET_GENERATED(ti);
113 ti = proto_tree_add_int(data_tree, &hfi_data_len, data_tvb, 0, 0, bytes);
114 PROTO_ITEM_SET_GENERATED (ti);
119 void
120 proto_register_data(void)
122 #ifndef HAVE_HFI_SECTION_INIT
123 static header_field_info *hfi[] = {
124 &hfi_data_data,
125 &hfi_data_text,
126 &hfi_data_md5_hash,
127 &hfi_data_len,
129 #endif
131 static gint *ett[] = {
132 &ett_data
135 module_t *module_data;
137 proto_data = proto_register_protocol (
138 "Data", /* name */
139 "Data", /* short name */
140 "data" /* abbrev */
143 register_dissector("data", dissect_data, proto_data);
145 proto_register_fields(proto_data, hfi, array_length(hfi));
146 proto_register_subtree_array(ett, array_length(ett));
148 module_data = prefs_register_protocol( proto_data, NULL);
149 prefs_register_bool_preference(module_data,
150 "datapref.newpane",
151 "Show not dissected data on new Packet Bytes pane",
152 "Show not dissected data on new Packet Bytes pane",
153 &new_pane);
154 prefs_register_bool_preference(module_data,
155 "show_as_text",
156 "Show data as text",
157 "Show data as text in the Packet Details pane",
158 &show_as_text);
159 prefs_register_bool_preference(module_data,
160 "md5_hash",
161 "Generate MD5 hash",
162 "Whether or not MD5 hashes should be generated and shown for each payload.",
163 &generate_md5_hash);
166 * "Data" is used to dissect something whose normal dissector
167 * is disabled, so it cannot itself be disabled.
169 proto_set_cant_toggle(proto_data);