HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-manolito.c
blobdea56388bad087a46be1c41e6b60c327bbd4cdea
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 * $Id$
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "config.h"
30 #include <glib.h>
32 #include <epan/packet.h>
33 #include <epan/wmem/wmem.h>
35 /* Initialize the protocol and registered fields */
36 static int proto_manolito = -1;
37 static int hf_manolito_checksum = -1;
38 static int hf_manolito_seqno = -1;
39 static int hf_manolito_src = -1;
40 static int hf_manolito_dest = -1;
41 static int hf_manolito_options_short = -1;
42 static int hf_manolito_options = -1;
44 /* Initialize the subtree pointers */
45 static gint ett_manolito = -1;
47 /* Code to actually dissect the packets */
48 static void
49 dissect_manolito(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
51 unsigned int offset;
53 /* Set up structures needed to add the protocol subtree and manage it */
54 proto_item *ti;
55 proto_tree *manolito_tree;
56 const char* packet_type = 0;
58 /* Make entries in Protocol column and Info column on summary display */
59 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MANOLITO");
61 ti = proto_tree_add_item(tree, proto_manolito, tvb, 0, -1, ENC_NA);
63 manolito_tree = proto_item_add_subtree(ti, ett_manolito);
65 /* MANOLITO packet header (network byte order) */
66 proto_tree_add_item(manolito_tree,
67 hf_manolito_checksum, tvb, 0, 4, ENC_BIG_ENDIAN);
68 proto_tree_add_item(manolito_tree,
69 hf_manolito_seqno, tvb, 4, 4, ENC_BIG_ENDIAN);
71 proto_tree_add_item(manolito_tree,
72 hf_manolito_src, tvb, 8, 4, ENC_BIG_ENDIAN);
74 proto_tree_add_item(manolito_tree,
75 hf_manolito_dest, tvb, 12, 4, ENC_BIG_ENDIAN);
77 if (tvb_reported_length(tvb) == 19) {
78 packet_type = "Ping (truncated)";
79 proto_tree_add_item(manolito_tree,
80 hf_manolito_options_short, tvb, 16, 3, ENC_BIG_ENDIAN);
81 } else {
82 proto_tree_add_item(manolito_tree,
83 hf_manolito_options, tvb, 16, 4, ENC_BIG_ENDIAN);
86 if (tvb_reported_length(tvb) <= 20) /* no payload, just headers */
88 col_set_str(pinfo->cinfo, COL_INFO, "Ping");
89 } else {
90 offset = 20; /* fields start here */
92 /* fields format: 2-byte name, optional NULL, 1-byte lenlen, */
93 /* that many bytes(len or data), for NI,CN,VL is len, more */
94 /* (that many bytes) data follows; else is raw data. */
97 guint16 field_name; /* 16-bit field name */
98 guint8 dtype; /* data-type */
99 guint8 length; /* length */
100 guint8* data; /* payload */
101 int start; /* field starting location */
102 char field_name_str[3]; /* printable name */
103 const char* longname; /* human-friendly field name */
105 start = offset;
107 /* 2-byte field name */
108 field_name = tvb_get_ntohs(tvb, offset);
109 offset += 2;
111 /* Identify the packet based on existing fields */
112 /* Maybe using the options fields is a better idea...*/
113 if (field_name == 0x434b) /* CK */
114 packet_type = "Search Hit";
115 if (field_name == 0x4e43) /* NC */
116 packet_type = "User Information";
117 if (field_name == 0x464e) /* FN - if only field */
118 packet_type = "Search Query";
119 if (field_name == 0x4944) /* ID ?? search by CK? */
120 packet_type = "Search Query (by hash)";
121 if (field_name == 0x5054) /* PT */
122 packet_type = "Download Request";
123 if (field_name == 0x4d45) /* ME */
124 packet_type = "Chat";
126 if (tvb_reported_length(tvb) == 20) /* no fields */
127 packet_type = "Ping";
129 /* Find the long name of the field */
130 switch(field_name)
132 case 0x5346: longname = "Shared Files"; break; /* SF */
133 case 0x534b: longname = "Shared Kilobytes";break; /* SK */
134 case 0x4e49: longname = "Network ID"; break; /* NI */
135 case 0x4e43: longname = "Num. Connections";break; /* NC */
136 case 0x4356: longname = "Client Version"; break; /* CV */
137 case 0x564c: longname = "Velocity"; break; /* VL */
138 case 0x464e: longname = "Filename"; break; /* FN */
139 case 0x464c: longname = "File Length"; break; /* FL */
140 case 0x4252: longname = "Bit Rate"; break; /* BR */
141 case 0x4643: longname = "Frequency"; break; /* FC */
142 case 0x5354: longname = "???"; break; /* ST */
143 case 0x534c: longname = "Song Length (s)"; break; /* SL */
144 case 0x434b: longname = "Checksum"; break; /* CK */
145 case 0x4e4e: longname = "Nickname"; break; /* NN */
146 case 0x434e: longname = "Client Name"; break; /* CN */
147 case 0x5054: longname = "Port"; break; /* PT */
148 case 0x484e: longname = "???"; break; /* HN */
149 case 0x4d45: longname = "Message"; break; /* ME */
150 case 0x4944: longname = "Identification"; break; /* ID */
151 case 0x4144: longname = "???"; break; /* AD */
152 default: longname = "unknown"; break;
155 /* 1-byte data type */
156 #define MANOLITO_STRING 1
157 #define MANOLITO_INTEGER 0
158 dtype = tvb_get_guint8(tvb, offset);
159 length = tvb_get_guint8(tvb, ++offset);
162 * Get the payload.
164 * XXX - is the cast necessary? I think the
165 * "usual arithmetic conversions" should
166 * widen it past 8 bits, so there shouldn't
167 * be an overflow.
169 data = (guint8 *)wmem_alloc(wmem_packet_scope(), (guint)length + 1);
170 tvb_memcpy(tvb, data, ++offset, length);
171 offset += length;
173 /* convert the 16-bit integer field name to a string */
174 /* XXX: changed this to use g_htons */
175 field_name_str[0] = g_htons(field_name) & 0x00ff;
176 field_name_str[1] = (g_htons(field_name) & 0xff00) >> 8;
177 field_name_str[2] = 0;
179 if (dtype == MANOLITO_STRING)
181 data[length] = 0;
182 proto_tree_add_text(manolito_tree, tvb, start,
183 offset - start, "%s (%s): %s",
184 (char*)field_name_str, longname, data);
185 } else if (dtype == MANOLITO_INTEGER) {
186 int n = 0;
188 /* integers can be up to 5 bytes */
189 switch(length)
191 case 5: n += data[4] << ((length - 5) * 8);
192 case 4: n += data[3] << ((length - 4) * 8);
193 case 3: n += data[2] << ((length - 3) * 8);
194 case 2: n += data[1] << ((length - 2) * 8);
195 case 1: n += data[0] << ((length - 1) * 8);
197 proto_tree_add_text(manolito_tree, tvb, start,
198 offset - start, "%s (%s): %d",
199 (char*)field_name_str, longname, n);
200 } else {
201 proto_tree_add_text(manolito_tree, tvb, start,
202 offset - start, "unknown type %d", dtype);
205 } while(offset < tvb_reported_length(tvb));
209 if (packet_type)
211 col_set_str(pinfo->cinfo, COL_INFO, packet_type);
216 /* Register the protocol with Wireshark */
218 void
219 proto_register_manolito(void)
222 /* Setup list of header fields See Section 1.6.1 for details*/
223 static hf_register_info hf[] = {
224 { &hf_manolito_checksum,
225 { "Checksum", "manolito.checksum",
226 FT_UINT32, BASE_HEX, NULL, 0,
227 "Checksum used for verifying integrity", HFILL }
229 { &hf_manolito_seqno,
230 { "Sequence Number", "manolito.seqno",
231 FT_UINT32, BASE_HEX, NULL, 0,
232 "Incremental sequence number", HFILL }
234 { &hf_manolito_src,
235 { "Forwarded IP Address", "manolito.src",
236 FT_IPv4, BASE_NONE, NULL, 0,
237 "Host packet was forwarded from (or 0)", HFILL }
239 { &hf_manolito_dest,
240 { "Destination IP Address","manolito.dest",
241 FT_IPv4, BASE_NONE, NULL, 0,
242 "Destination IPv4 address", HFILL }
244 { &hf_manolito_options_short,
245 { "Options", "manolito.options",
246 FT_UINT24, BASE_HEX, NULL, 0,
247 "Packet-dependent data", HFILL }
249 { &hf_manolito_options,
250 { "Options", "manolito.options",
251 FT_UINT32, BASE_HEX, NULL, 0,
252 "Packet-dependent data", HFILL }
256 static gint *ett[] = {
257 &ett_manolito,
260 proto_manolito = proto_register_protocol("Blubster/Piolet MANOLITO Protocol",
261 "Manolito", "manolito");
263 proto_register_field_array(proto_manolito, hf, array_length(hf));
264 proto_register_subtree_array(ett, array_length(ett));
268 /* If this dissector uses sub-dissector registration add a registration routine.
269 This format is required because a script is used to find these routines and
270 create the code that calls these routines.
272 void
273 proto_reg_handoff_manolito(void)
275 dissector_handle_t manolito_handle;
277 manolito_handle = create_dissector_handle(dissect_manolito,
278 proto_manolito);
279 dissector_add_uint("udp.port", 41170, manolito_handle);