Use MAC address documentation range in filter examples
[metze/wireshark/wip.git] / epan / dissectors / packet-rgmp.c
1 /* packet-rgmp.c
2  * Routines for IGMP/RGMP packet disassembly
3  * Copyright 2006 Jaap Keuter
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 /*
25  Based on RFC3488
26
27  This is a setup for RGMP dissection, a simple protocol bolted on IGMP.
28  */
29
30 #include "config.h"
31
32 #include <epan/packet.h>
33 #include "packet-igmp.h"
34
35 void proto_register_rgmp(void);
36 void proto_reg_handoff_rgmp(void);
37
38 static int proto_rgmp      = -1;
39 static int hf_type         = -1;
40 static int hf_reserved     = -1;
41 static int hf_checksum     = -1;
42 static int hf_checksum_bad = -1;
43 static int hf_maddr        = -1;
44
45 static int ett_rgmp = -1;
46
47 #define MC_RGMP 0xe0000019
48
49 static const value_string rgmp_types[] = {
50     {IGMP_RGMP_LEAVE, "Leave"},
51     {IGMP_RGMP_JOIN,  "Join"},
52     {IGMP_RGMP_BYE,   "Bye"},
53     {IGMP_RGMP_HELLO, "Hello"},
54     {0, NULL}
55 };
56
57 /* This function is only called from the IGMP dissector */
58 static int
59 dissect_rgmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
60 {
61     proto_tree *tree;
62     proto_item *item;
63     guint8 type;
64     int offset = 0;
65     guint32 dst = g_htonl(MC_RGMP);
66
67     /* Shouldn't be destined for us */
68     if (memcmp(pinfo->dst.data, &dst, 4))
69         return 0;
70
71     col_set_str(pinfo->cinfo, COL_PROTOCOL, "RGMP");
72     col_clear(pinfo->cinfo, COL_INFO);
73
74     item = proto_tree_add_item(parent_tree, proto_rgmp, tvb, offset, -1, ENC_NA);
75     tree = proto_item_add_subtree(item, ett_rgmp);
76
77     type = tvb_get_guint8(tvb, offset);
78     col_add_str(pinfo->cinfo, COL_INFO,
79                 val_to_str(type, rgmp_types, "Unknown Type: 0x%02x"));
80     proto_tree_add_uint(tree, hf_type, tvb, offset, 1, type);
81     offset += 1;
82
83     /* reserved */
84     proto_tree_add_item(tree, hf_reserved, tvb, offset, 1, ENC_NA);
85     offset += 1;
86
87     igmp_checksum(tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
88     offset += 2;
89
90     proto_tree_add_item(tree, hf_maddr, tvb, offset, 4, ENC_BIG_ENDIAN);
91     offset += 4;
92
93     return offset;
94 }
95
96
97 void
98 proto_register_rgmp(void)
99 {
100     static hf_register_info hf[] = {
101         { &hf_type,
102           { "Type", "rgmp.type", FT_UINT8, BASE_HEX,
103             VALS(rgmp_types), 0, "RGMP Packet Type", HFILL }
104         },
105
106         { &hf_reserved,
107           { "Reserved", "rgmp.reserved", FT_UINT8, BASE_HEX,
108             NULL, 0, "RGMP Reserved", HFILL }
109         },
110
111         { &hf_checksum,
112           { "Checksum", "rgmp.checksum", FT_UINT16, BASE_HEX,
113             NULL, 0, NULL, HFILL }
114         },
115
116         { &hf_checksum_bad,
117           { "Bad Checksum", "rgmp.checksum_bad", FT_BOOLEAN, BASE_NONE,
118             NULL, 0x0, NULL, HFILL }
119         },
120
121         { &hf_maddr,
122           { "Multicast group address", "rgmp.maddr", FT_IPv4, BASE_NONE,
123             NULL, 0, NULL, HFILL }
124         }
125     };
126
127     static gint *ett[] = {
128         &ett_rgmp
129     };
130
131     proto_rgmp = proto_register_protocol("Router-port Group Management Protocol", "RGMP", "rgmp");
132     proto_register_field_array(proto_rgmp, hf, array_length(hf));
133     proto_register_subtree_array(ett, array_length(ett));
134
135     new_register_dissector("rgmp", dissect_rgmp, proto_rgmp);
136 }
137
138 void
139 proto_reg_handoff_rgmp(void)
140 {
141     dissector_handle_t rgmp_handle;
142
143     rgmp_handle = new_create_dissector_handle(dissect_rgmp, proto_rgmp);
144     dissector_add_uint("igmp.type", IGMP_RGMP_HELLO, rgmp_handle);
145     dissector_add_uint("igmp.type", IGMP_RGMP_BYE, rgmp_handle);
146     dissector_add_uint("igmp.type", IGMP_RGMP_JOIN, rgmp_handle);
147     dissector_add_uint("igmp.type", IGMP_RGMP_LEAVE, rgmp_handle);
148 }
149
150 /*
151  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
152  *
153  * Local variables:
154  * c-basic-offset: 4
155  * tab-width: 8
156  * indent-tabs-mode: nil
157  * End:
158  *
159  * vi: set shiftwidth=4 tabstop=8 expandtab:
160  * :indentSize=4:tabSize=8:noTabs=true:
161  */