Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-manolito.c
blobedcc3c5e4fa31370dbff67ca40f2e700ee5df26c
1 /* packet-manolito.c
2 * Routines for Blubster/Piolet Manolito Protocol dissection
3 * Copyright 2003-2004, Jeff Connelly <shellreef+mp2p@gmail.com>
5 * Official home page: http://openlito.sourceforge.net/
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/expert.h>
19 void proto_register_manolito(void);
20 void proto_reg_handoff_manolito(void);
22 static dissector_handle_t manolito_handle;
24 #define MANOLITO_PORT 41170 /* Not IANA registered */
26 static int proto_manolito;
28 static int hf_manolito_checksum;
29 static int hf_manolito_seqno;
30 static int hf_manolito_src;
31 static int hf_manolito_dest;
32 static int hf_manolito_options_short;
33 static int hf_manolito_options;
34 static int hf_manolito_string;
35 static int hf_manolito_integer;
37 static int ett_manolito;
39 static expert_field ei_manolito_type;
41 #define MANOLITO_STRING 1
42 #define MANOLITO_INTEGER 0
44 static const value_string field_longname[] = {
45 { 0x4144, "???" },
46 { 0x4252, "Bit Rate" },
47 { 0x434b, "Checksum" },
48 { 0x434e, "Client Name" },
49 { 0x4356, "Client Version" },
50 { 0x4643, "Frequency" },
51 { 0x464c, "File Length" },
52 { 0x464e, "Filename" },
53 { 0x484e, "???" },
54 { 0x4944, "Identification" },
55 { 0x4d45, "Message" },
56 { 0x4e43, "Num. Connections" },
57 { 0x4e49, "Network ID" },
58 { 0x4e4e, "Nickname" },
59 { 0x5054, "Port" },
60 { 0x5346, "Shared Files" },
61 { 0x534b, "Shared Kilobytes" },
62 { 0x534c, "Song Length (s)" },
63 { 0x5354, "???" },
64 { 0x564c, "Velocity" },
65 { 0, NULL }
67 static value_string_ext field_longname_ext = VALUE_STRING_EXT_INIT(field_longname);
70 static int
71 dissect_manolito(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dissector_data _U_)
73 int offset = 0;
74 proto_item *ti;
75 proto_tree *manolito_tree;
76 char *packet_type = NULL;
78 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MANOLITO");
80 ti = proto_tree_add_item(tree, proto_manolito, tvb, offset, -1, ENC_NA);
82 manolito_tree = proto_item_add_subtree(ti, ett_manolito);
84 /* MANOLITO packet header (network byte order) */
85 proto_tree_add_checksum(manolito_tree, tvb, offset, hf_manolito_checksum,
86 -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
87 offset += 4;
88 proto_tree_add_item(manolito_tree,
89 hf_manolito_seqno, tvb, offset, 4, ENC_BIG_ENDIAN);
90 offset += 4;
91 proto_tree_add_item(manolito_tree,
92 hf_manolito_src, tvb, offset, 4, ENC_BIG_ENDIAN);
93 offset += 4;
94 proto_tree_add_item(manolito_tree,
95 hf_manolito_dest, tvb, offset, 4, ENC_BIG_ENDIAN);
96 offset += 4;
98 if (tvb_reported_length_remaining(tvb, offset) == 3) {
99 proto_tree_add_item(manolito_tree,
100 hf_manolito_options_short, tvb, offset, 3, ENC_BIG_ENDIAN);
101 offset += 3;
102 col_set_str(pinfo->cinfo, COL_INFO, "Ping (truncated)");
103 return offset;
106 proto_tree_add_item(manolito_tree,
107 hf_manolito_options, tvb, 16, 4, ENC_BIG_ENDIAN);
108 offset += 4;
110 if (tvb_reported_length_remaining(tvb, offset) == 0) {
111 col_set_str(pinfo->cinfo, COL_INFO, "Ping");
112 return offset;
115 /* fields format: 2-byte name, optional NULL, 1-byte lenlen, */
116 /* that many bytes(len or data), for NI,CN,VL is len, more */
117 /* (that many bytes) data follows; else is raw data. */
120 uint16_t field_name; /* 16-bit field name */
121 uint8_t dtype; /* data-type */
122 uint8_t length; /* length */
123 int start; /* field starting location */
124 uint8_t *field_name_str;
126 start = offset;
128 /* 2-byte field name */
129 field_name = tvb_get_ntohs(tvb, offset);
130 field_name_str = tvb_get_string_enc(pinfo->pool, tvb, offset, 2, ENC_ASCII);
131 if (!packet_type) {
132 /* Identify the packet based on existing fields */
133 /* Maybe using the options fields is a better idea...*/
134 if (field_name == 0x434b) /* CK */
135 packet_type = "Search Hit";
136 if (field_name == 0x4e43) /* NC */
137 packet_type = "User Information";
138 if (field_name == 0x464e) /* FN - if only field */
139 packet_type = "Search Query";
140 if (field_name == 0x4944) /* ID ?? search by CK? */
141 packet_type = "Search Query (by hash)";
142 if (field_name == 0x5054) /* PT */
143 packet_type = "Download Request";
144 if (field_name == 0x4d45) /* ME */
145 packet_type = "Chat";
147 offset += 2;
149 /* 1-byte data type */
150 dtype = tvb_get_uint8(tvb, offset);
151 offset++;
152 length = tvb_get_uint8(tvb, offset);
153 offset++;
155 if (dtype == MANOLITO_STRING) {
156 uint8_t *str;
158 str = tvb_get_string_enc(pinfo->pool, tvb, offset, length, ENC_ASCII);
159 proto_tree_add_string_format(manolito_tree, hf_manolito_string, tvb, start,
160 4+length, str, "%s (%s): %s",
161 field_name_str,
162 val_to_str_ext_const(field_name, &field_longname_ext, "unknown"),
163 str);
164 offset += length;
166 else if (dtype == MANOLITO_INTEGER) {
167 bool len_ok = true;
168 uint64_t n = 0;
170 /* integers can be up to 5 bytes */
171 switch(length)
173 case 5:
174 n = tvb_get_ntoh40(tvb, offset);
175 break;
176 case 4:
177 n = tvb_get_ntohl(tvb, offset);
178 break;
179 case 3:
180 n = tvb_get_ntoh24(tvb, offset);
181 break;
182 case 2:
183 n = tvb_get_ntohs(tvb, offset);
184 break;
185 case 1:
186 n = tvb_get_uint8(tvb, offset);
187 break;
189 default:
190 len_ok = false;
193 if (len_ok) {
194 proto_tree_add_uint64_format(manolito_tree, hf_manolito_integer, tvb, start,
195 4+length, n, "%s (%s): %" PRIu64,
196 field_name_str,
197 val_to_str_ext_const(field_name, &field_longname_ext, "unknown"),
200 else {
201 /* XXX - expert info */
203 offset += length;
205 else {
206 proto_tree_add_expert_format(manolito_tree, pinfo, &ei_manolito_type,
207 tvb, start, offset - start, "Unknown type %d", dtype);
210 } while(tvb_reported_length_remaining(tvb, offset));
212 if (packet_type)
213 col_set_str(pinfo->cinfo, COL_INFO, packet_type);
215 return offset;
219 void
220 proto_register_manolito(void)
222 static hf_register_info hf[] = {
223 { &hf_manolito_checksum,
224 { "Checksum", "manolito.checksum",
225 FT_UINT32, BASE_HEX, NULL, 0,
226 "Checksum used for verifying integrity", HFILL }
228 { &hf_manolito_seqno,
229 { "Sequence Number", "manolito.seqno",
230 FT_UINT32, BASE_HEX, NULL, 0,
231 "Incremental sequence number", HFILL }
233 { &hf_manolito_src,
234 { "Forwarded IP Address", "manolito.src",
235 FT_IPv4, BASE_NONE, NULL, 0,
236 "Host packet was forwarded from (or 0)", HFILL }
238 { &hf_manolito_dest,
239 { "Destination IP Address", "manolito.dest",
240 FT_IPv4, BASE_NONE, NULL, 0,
241 "Destination IPv4 address", HFILL }
243 { &hf_manolito_options_short,
244 { "Options", "manolito.options",
245 FT_UINT24, BASE_HEX, NULL, 0,
246 "Packet-dependent data", HFILL }
248 { &hf_manolito_options,
249 { "Options", "manolito.options",
250 FT_UINT32, BASE_HEX, NULL, 0,
251 "Packet-dependent data", HFILL }
253 { &hf_manolito_string,
254 { "String field", "manolito.string",
255 FT_STRING, BASE_NONE, NULL, 0,
256 NULL, HFILL }
258 { &hf_manolito_integer,
259 { "Integer field", "manolito.integer",
260 FT_UINT40, BASE_DEC, NULL, 0,
261 NULL, HFILL }
265 static int *ett[] = {
266 &ett_manolito,
269 static ei_register_info ei[] = {
270 { &ei_manolito_type, { "manolito.type.unknown", PI_PROTOCOL, PI_WARN, "Unknown type", EXPFILL }},
273 expert_module_t* expert_manolito;
275 proto_manolito = proto_register_protocol("Blubster/Piolet MANOLITO Protocol", "Manolito", "manolito");
277 proto_register_field_array(proto_manolito, hf, array_length(hf));
278 proto_register_subtree_array(ett, array_length(ett));
279 expert_manolito = expert_register_protocol(proto_manolito);
280 expert_register_field_array(expert_manolito, ei, array_length(ei));
282 manolito_handle = register_dissector("manolito", dissect_manolito, proto_manolito);
286 void
287 proto_reg_handoff_manolito(void)
289 dissector_add_uint_with_preference("udp.port", MANOLITO_PORT, manolito_handle);
293 * Editor modelines - https://www.wireshark.org/tools/modelines.html
295 * Local variables:
296 * c-basic-offset: 8
297 * tab-width: 8
298 * indent-tabs-mode: t
299 * End:
301 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
302 * :indentSize=8:tabSize=8:noTabs=false: