1 /* packet-msnip.c 2001 Ronnie Sahlberg <rsahlber@bigpond.net.au>
2 * Routines for IGMP/MSNIP packet disassembly
4 * $Id: packet-msnip.c,v 1.1 2001/06/29 18:55:49 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 MSNIP " Multicast Source Notification of Interest Protocol
35 Defined in draft-ietf-idmr-igmp-msnip-00.txt
42 #ifdef HAVE_SYS_TYPES_H
43 # include <sys/types.h>
52 #include "packet-msnip.h"
55 static int proto_msnip = -1;
56 static int hf_checksum = -1;
57 static int hf_checksum_bad = -1;
58 static int hf_type = -1;
59 static int hf_count = -1;
60 static int hf_holdtime = -1;
61 static int hf_groups = -1;
62 static int hf_maddr = -1;
63 static int hf_mask = -1;
64 static int hf_holdtime16 = -1;
65 static int hf_genid = -1;
66 static int hf_rec_type = -1;
68 static int ett_msnip = -1;
69 static int ett_groups = -1;
74 #define MSNIP_RMR 0x25
75 static const value_string msnip_types[] = {
76 {MSNIP_GM, "Multicast Group Map"},
77 {MSNIP_IS, "Multicast Interest Solicitation"},
78 {MSNIP_RMR, "Multicast Receiver Membership Report"},
82 #define MSNIP_RECTYPE_TRANSMIT 1
83 #define MSNIP_RECTYPE_HOLD 2
84 static const value_string msnip_rec_types[] = {
85 {MSNIP_RECTYPE_TRANSMIT, "Request to start transmitting group"},
86 {MSNIP_RECTYPE_HOLD, "Request to hold transmitting group"},
91 msnip_checksum(proto_tree *tree,tvbuff_t *tvb, int len)
93 guint16 cksum,hdrcksum;
96 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, len);
97 cksum_vec[0].len = len;
99 hdrcksum = tvb_get_ntohs(tvb, 2);
100 cksum = in_cksum(&cksum_vec[0],1);
103 proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (correct)", hdrcksum);
105 proto_tree_add_item_hidden(tree, hf_checksum_bad, tvb, 2, 2, TRUE);
106 proto_tree_add_uint_format(tree, hf_checksum, tvb, 2, 2, hdrcksum, "Header checksum: 0x%04x (incorrect, should be 0x%04x)", hdrcksum,in_cksum_shouldbe(hdrcksum,cksum));
114 dissect_msnip_rmr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
119 count = tvb_get_guint8(tvb, offset);
120 proto_tree_add_uint(parent_tree, hf_count, tvb, offset, 1, count);
124 msnip_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
132 int old_offset = offset;
134 item = proto_tree_add_item(parent_tree, hf_groups,
135 tvb, offset, 0, FALSE);
136 tree = proto_item_add_subtree(item, ett_groups);
139 rec_type = tvb_get_guint8(tvb, offset);
140 proto_tree_add_uint(tree, hf_rec_type, tvb, offset, 1, rec_type);
143 /* skip 3 unused bytes */
146 /* multicast group */
147 tvb_memcpy(tvb, (guint8 *)&maddr, offset, 4);
148 proto_tree_add_ipv4(tree, hf_maddr, tvb, offset, 4,
153 proto_item_set_text(item,"Group: %s %s",
154 ip_to_str((guint8 *)&maddr),
155 val_to_str(rec_type, msnip_rec_types,
156 "Unknown Type:0x%02x"));
158 proto_item_set_len(item, offset-old_offset);
166 dissect_msnip_is(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
169 /* skip reserved byte */
173 msnip_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
176 /* 16 bit holdtime */
177 proto_tree_add_uint(parent_tree, hf_holdtime16, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
181 proto_tree_add_uint(parent_tree, hf_genid, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
189 dissect_msnip_gm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
194 count = tvb_get_guint8(tvb, offset);
195 proto_tree_add_uint(parent_tree, hf_count, tvb, offset, 1, count);
199 msnip_checksum(parent_tree, tvb, tvb_length_remaining(tvb, 0));
203 proto_tree_add_uint(parent_tree, hf_holdtime, tvb, offset, 4, count);
211 int old_offset = offset;
213 item = proto_tree_add_item(parent_tree, hf_groups,
214 tvb, offset, 0, FALSE);
215 tree = proto_item_add_subtree(item, ett_groups);
217 /* multicast group */
218 tvb_memcpy(tvb, (guint8 *)&maddr, offset, 4);
219 proto_tree_add_ipv4(tree, hf_maddr, tvb, offset, 4,
224 masklen = tvb_get_guint8(tvb, offset);
225 proto_tree_add_uint(tree, hf_mask, tvb,
229 /* skip 3 unused bytes */
233 proto_item_set_text(item,"Group: %s/%d",
234 ip_to_str((guint8 *)&maddr), masklen);
236 proto_item_set_len(item, offset-old_offset);
244 /* This function is only called from the IGMP dissector */
246 dissect_msnip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
252 if (!proto_is_protocol_enabled(proto_msnip)) {
253 /* we are not enabled, skip entire packet to be nice
254 to the igmp layer. (so clicking on IGMP will display the data)
256 return offset+tvb_length_remaining(tvb, offset);
259 item = proto_tree_add_item(parent_tree, proto_msnip, tvb, offset, 0, FALSE);
260 tree = proto_item_add_subtree(item, ett_msnip);
263 if (check_col(pinfo->fd, COL_PROTOCOL)) {
264 col_set_str(pinfo->fd, COL_PROTOCOL, "MSNIP");
266 if (check_col(pinfo->fd, COL_INFO)) {
267 col_clear(pinfo->fd, COL_INFO);
271 type = tvb_get_guint8(tvb, offset);
272 if (check_col(pinfo->fd, COL_INFO)) {
273 col_add_fstr(pinfo->fd, COL_INFO,
274 "%s",val_to_str(type, msnip_types,
275 "Unknown Type:0x%02x"));
278 /* type of command */
279 proto_tree_add_uint(tree, hf_type, tvb, offset, 1, type);
284 offset = dissect_msnip_gm(tvb, pinfo, tree, offset);
287 offset = dissect_msnip_is(tvb, pinfo, tree, offset);
290 offset = dissect_msnip_rmr(tvb, pinfo, tree, offset);
295 proto_item_set_len(item, offset);
303 proto_register_msnip(void)
305 static hf_register_info hf[] = {
307 { "Type", "msnip.type", FT_UINT8, BASE_HEX,
308 VALS(msnip_types), 0, "MSNIP Packet Type", HFILL }},
311 { "Checksum", "msnip.checksum", FT_UINT16, BASE_HEX,
312 NULL, 0, "MSNIP Checksum", HFILL }},
315 { "Bad Checksum", "msnip.checksum_bad", FT_BOOLEAN, BASE_NONE,
316 NULL, 0, "Bad MSNIP Checksum", HFILL }},
319 { "Count", "msnip.count", FT_UINT8, BASE_DEC,
320 NULL, 0, "MSNIP Number of groups", HFILL }},
323 { "Holdtime", "msnip.holdtime", FT_UINT32, BASE_DEC,
324 NULL, 0, "MSNIP Holdtime in seconds", HFILL }},
327 { "Groups", "msnip.groups", FT_NONE, BASE_NONE,
328 NULL, 0, "MSNIP Groups", HFILL }},
331 { "Multicast group", "msnip.maddr", FT_IPv4, BASE_NONE,
332 NULL, 0, "MSNIP Multicast Group", HFILL }},
335 { "Netmask", "msnip.netmask", FT_UINT8, BASE_DEC,
336 NULL, 0, "MSNIP Netmask", HFILL }},
339 { "Holdtime", "msnip.holdtime16", FT_UINT16, BASE_DEC,
340 NULL, 0, "MSNIP Holdtime in seconds", HFILL }},
343 { "Generation ID", "msnip.genid", FT_UINT16, BASE_DEC,
344 NULL, 0, "MSNIP Generation ID", HFILL }},
347 { "Record Type", "msnip.rec_type", FT_UINT8, BASE_DEC,
348 VALS(msnip_rec_types), 0, "MSNIP Record Type", HFILL }},
351 static gint *ett[] = {
356 proto_msnip = proto_register_protocol("MSNIP : Multicast Source Notification of Interest Protocol",
358 proto_register_field_array(proto_msnip, hf, array_length(hf));
359 proto_register_subtree_array(ett, array_length(ett));