HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-msnip.c
blobca5d70e802c3a450cd540fac91c35a99b8be8023
1 /* packet-msnip.c 2001 Ronnie Sahlberg <See AUTHORS for email>
2 * Routines for IGMP/MSNIP packet disassembly
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 MSNIP
28 code
30 0x23 x
31 0x24 x
32 0x25 x
34 MSNIP " Multicast Source Notification of Interest Protocol
35 Defined in draft-ietf-idmr-igmp-msnip-00.txt
38 #include "config.h"
40 #include <glib.h>
42 #include <epan/packet.h>
43 #include <epan/to_str.h>
44 #include "packet-igmp.h"
45 #include "packet-msnip.h"
48 static int proto_msnip = -1;
49 static int hf_checksum = -1;
50 static int hf_checksum_bad = -1;
51 static int hf_type = -1;
52 static int hf_count = -1;
53 static int hf_holdtime = -1;
54 static int hf_groups = -1;
55 static int hf_maddr = -1;
56 static int hf_mask = -1;
57 static int hf_holdtime16 = -1;
58 static int hf_genid = -1;
59 static int hf_rec_type = -1;
61 static int ett_msnip = -1;
62 static int ett_groups = -1;
65 #define MSNIP_GM 0x23
66 #define MSNIP_IS 0x24
67 #define MSNIP_RMR 0x25
68 static const value_string msnip_types[] = {
69 {MSNIP_GM, "Multicast Group Map"},
70 {MSNIP_IS, "Multicast Interest Solicitation"},
71 {MSNIP_RMR, "Multicast Receiver Membership Report"},
72 {0, NULL}
75 #define MSNIP_RECTYPE_TRANSMIT 1
76 #define MSNIP_RECTYPE_HOLD 2
77 static const value_string msnip_rec_types[] = {
78 {MSNIP_RECTYPE_TRANSMIT, "Request to start transmitting group"},
79 {MSNIP_RECTYPE_HOLD, "Request to hold transmitting group"},
80 {0, NULL}
83 static int
84 dissect_msnip_rmr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
86 guint8 count;
88 /* group count */
89 count = tvb_get_guint8(tvb, offset);
90 proto_tree_add_uint(parent_tree, hf_count, tvb, offset, 1, count);
91 offset += 1;
93 /* checksum */
94 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
95 offset += 2;
97 while (count--) {
98 proto_tree *tree;
99 proto_item *item;
100 guint8 rec_type;
101 guint32 maddr;
102 int old_offset = offset;
104 item = proto_tree_add_item(parent_tree, hf_groups,
105 tvb, offset, -1, ENC_NA);
106 tree = proto_item_add_subtree(item, ett_groups);
108 /* record type */
109 rec_type = tvb_get_guint8(tvb, offset);
110 proto_tree_add_uint(tree, hf_rec_type, tvb, offset, 1, rec_type);
111 offset += 1;
113 /* skip 3 unused bytes */
114 offset += 3;
116 /* multicast group */
117 maddr = tvb_get_ipv4(tvb, offset);
118 proto_tree_add_ipv4(tree, hf_maddr, tvb, offset, 4,
119 maddr);
120 offset += 4;
122 if (item) {
123 proto_item_set_text(item,"Group: %s %s",
124 ip_to_str((guint8 *)&maddr),
125 val_to_str(rec_type, msnip_rec_types,
126 "Unknown Type:0x%02x"));
128 proto_item_set_len(item, offset-old_offset);
132 return offset;
135 static int
136 dissect_msnip_is(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
139 /* skip reserved byte */
140 offset += 1;
142 /* checksum */
143 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
144 offset += 2;
146 /* 16 bit holdtime */
147 proto_tree_add_uint(parent_tree, hf_holdtime16, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
148 offset += 2;
150 /* Generation ID */
151 proto_tree_add_uint(parent_tree, hf_genid, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
152 offset += 2;
154 return offset;
158 static int
159 dissect_msnip_gm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
161 guint8 count;
163 /* group count */
164 count = tvb_get_guint8(tvb, offset);
165 proto_tree_add_uint(parent_tree, hf_count, tvb, offset, 1, count);
166 offset += 1;
168 /* checksum */
169 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
170 offset += 2;
172 /* holdtime */
173 proto_tree_add_uint(parent_tree, hf_holdtime, tvb, offset, 4, count);
174 offset += 4;
176 while (count--) {
177 proto_tree *tree;
178 proto_item *item;
179 guint32 maddr;
180 guint8 masklen;
181 int old_offset = offset;
183 item = proto_tree_add_item(parent_tree, hf_groups,
184 tvb, offset, -1, ENC_NA);
185 tree = proto_item_add_subtree(item, ett_groups);
187 /* multicast group */
188 maddr = tvb_get_ipv4(tvb, offset);
189 proto_tree_add_ipv4(tree, hf_maddr, tvb, offset, 4,
190 maddr);
191 offset += 4;
193 /* mask length */
194 masklen = tvb_get_guint8(tvb, offset);
195 proto_tree_add_uint(tree, hf_mask, tvb,
196 offset, 1, masklen);
197 offset += 1;
199 /* skip 3 unused bytes */
200 offset += 3;
202 if (item) {
203 proto_item_set_text(item,"Group: %s/%d",
204 ip_to_str((guint8 *)&maddr), masklen);
206 proto_item_set_len(item, offset-old_offset);
210 return offset;
214 /* This function is only called from the IGMP dissector */
216 dissect_msnip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
218 proto_tree *tree;
219 proto_item *item;
220 guint8 type;
222 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_msnip))) {
223 /* we are not enabled, skip entire packet to be nice
224 to the igmp layer. (so clicking on IGMP will display the data)
226 return offset+tvb_length_remaining(tvb, offset);
229 item = proto_tree_add_item(parent_tree, proto_msnip, tvb, offset, -1, ENC_NA);
230 tree = proto_item_add_subtree(item, ett_msnip);
233 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSNIP");
234 col_clear(pinfo->cinfo, COL_INFO);
237 type = tvb_get_guint8(tvb, offset);
238 col_add_str(pinfo->cinfo, COL_INFO,
239 val_to_str(type, msnip_types,
240 "Unknown Type:0x%02x"));
242 /* type of command */
243 proto_tree_add_uint(tree, hf_type, tvb, offset, 1, type);
244 offset += 1;
246 switch (type) {
247 case MSNIP_GM:
248 offset = dissect_msnip_gm(tvb, pinfo, tree, offset);
249 break;
250 case MSNIP_IS:
251 offset = dissect_msnip_is(tvb, pinfo, tree, offset);
252 break;
253 case MSNIP_RMR:
254 offset = dissect_msnip_rmr(tvb, pinfo, tree, offset);
255 break;
258 if (item) {
259 proto_item_set_len(item, offset);
262 return offset;
266 void
267 proto_register_msnip(void)
269 static hf_register_info hf[] = {
270 { &hf_type,
271 { "Type", "msnip.type", FT_UINT8, BASE_HEX,
272 VALS(msnip_types), 0, "MSNIP Packet Type", HFILL }},
274 { &hf_checksum,
275 { "Checksum", "msnip.checksum", FT_UINT16, BASE_HEX,
276 NULL, 0, "MSNIP Checksum", HFILL }},
278 { &hf_checksum_bad,
279 { "Bad Checksum", "msnip.checksum_bad", FT_BOOLEAN, BASE_NONE,
280 NULL, 0x0, "Bad MSNIP Checksum", HFILL }},
282 { &hf_count,
283 { "Count", "msnip.count", FT_UINT8, BASE_DEC,
284 NULL, 0, "MSNIP Number of groups", HFILL }},
286 { &hf_holdtime,
287 { "Holdtime", "msnip.holdtime", FT_UINT32, BASE_DEC,
288 NULL, 0, "MSNIP Holdtime in seconds", HFILL }},
290 { &hf_groups,
291 { "Groups", "msnip.groups", FT_NONE, BASE_NONE,
292 NULL, 0, "MSNIP Groups", HFILL }},
294 { &hf_maddr,
295 { "Multicast group", "msnip.maddr", FT_IPv4, BASE_NONE,
296 NULL, 0, "MSNIP Multicast Group", HFILL }},
298 { &hf_mask,
299 { "Netmask", "msnip.netmask", FT_UINT8, BASE_DEC,
300 NULL, 0, "MSNIP Netmask", HFILL }},
302 { &hf_holdtime16,
303 { "Holdtime", "msnip.holdtime16", FT_UINT16, BASE_DEC,
304 NULL, 0, "MSNIP Holdtime in seconds", HFILL }},
306 { &hf_genid,
307 { "Generation ID", "msnip.genid", FT_UINT16, BASE_DEC,
308 NULL, 0, "MSNIP Generation ID", HFILL }},
310 { &hf_rec_type,
311 { "Record Type", "msnip.rec_type", FT_UINT8, BASE_DEC,
312 VALS(msnip_rec_types), 0, "MSNIP Record Type", HFILL }},
315 static gint *ett[] = {
316 &ett_msnip,
317 &ett_groups,
320 proto_msnip = proto_register_protocol("MSNIP: Multicast Source Notification of Interest Protocol",
321 "MSNIP", "msnip");
322 proto_register_field_array(proto_msnip, hf, array_length(hf));
323 proto_register_subtree_array(ett, array_length(ett));