As the gtk2 directory is no longer needed (GTK1 and 2 are using the same sources...
[obnox/wireshark/wip.git] / epan / dissectors / packet-cgmp.c
1 /* packet-cgmp.c
2  * Routines for the disassembly of the Cisco Group Management Protocol
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #include "config.h"
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include <glib.h>
31 #include <epan/packet.h>
32
33 /*
34  * See
35  *
36  * http://www.barnett.sk/software/bbooks/cisco_multicasting_routing/chap04.html
37  *
38  * for some information on CGMP.
39  */
40
41 static int proto_cgmp = -1;
42 static int hf_cgmp_version = -1;
43 static int hf_cgmp_type = -1;
44 static int hf_cgmp_count = -1;
45 static int hf_cgmp_gda = -1;
46 static int hf_cgmp_usa = -1;
47
48 static gint ett_cgmp = -1;
49
50 static const value_string type_vals[] = {
51         { 0, "Join" },
52         { 1, "Leave" },
53         { 0, NULL },
54 };
55
56 static void
57 dissect_cgmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
58 {
59         proto_item *ti;
60         proto_tree *cgmp_tree = NULL;
61         int offset = 0;
62         guint8 count;
63
64         if (check_col(pinfo->cinfo, COL_PROTOCOL))
65                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CGMP");
66         if (check_col(pinfo->cinfo, COL_INFO))
67                 col_set_str(pinfo->cinfo, COL_INFO, "Cisco Group Management Protocol");
68
69         if (tree) {
70                 ti = proto_tree_add_item(tree, proto_cgmp, tvb, offset, -1,
71                     FALSE);
72                 cgmp_tree = proto_item_add_subtree(ti, ett_cgmp);
73
74                 proto_tree_add_item(cgmp_tree, hf_cgmp_version, tvb, offset, 1,
75                     FALSE);
76                 proto_tree_add_item(cgmp_tree, hf_cgmp_type, tvb, offset, 1,
77                     FALSE);
78                 offset += 1;
79
80                 offset += 2;    /* skip reserved field */
81
82                 count = tvb_get_guint8(tvb, offset);
83                 proto_tree_add_uint(cgmp_tree, hf_cgmp_count, tvb, offset, 1,
84                     count);
85                 offset += 1;
86
87                 while (count != 0) {
88                         proto_tree_add_item(cgmp_tree, hf_cgmp_gda, tvb, offset, 6,
89                             FALSE);
90                         offset += 6;
91
92                         proto_tree_add_item(cgmp_tree, hf_cgmp_usa, tvb, offset, 6,
93                             FALSE);
94                         offset += 6;
95
96                         count--;
97                 }
98         }
99 }
100
101 void
102 proto_register_cgmp(void)
103 {
104         static hf_register_info hf[] = {
105                 { &hf_cgmp_version,
106                 { "Version",    "cgmp.version", FT_UINT8, BASE_DEC, NULL, 0xF0,
107                         "", HFILL }},
108
109                 { &hf_cgmp_type,
110                 { "Type",       "cgmp.type",    FT_UINT8, BASE_DEC, VALS(type_vals), 0x0F,
111                         "", HFILL }},
112
113                 { &hf_cgmp_count,
114                 { "Count",      "cgmp.count", FT_UINT8, BASE_DEC, NULL, 0x0,
115                         "", HFILL }},
116
117                 { &hf_cgmp_gda,
118                 { "Group Destination Address",  "cgmp.gda", FT_ETHER, BASE_NONE, NULL, 0x0,
119                         "Group Destination Address", HFILL }},
120
121                 { &hf_cgmp_usa,
122                 { "Unicast Source Address",     "cgmp.usa", FT_ETHER, BASE_NONE, NULL, 0x0,
123                         "Unicast Source Address", HFILL }},
124         };
125         static gint *ett[] = {
126                 &ett_cgmp,
127         };
128
129         proto_cgmp = proto_register_protocol("Cisco Group Management Protocol",
130             "CGMP", "cgmp");
131         proto_register_field_array(proto_cgmp, hf, array_length(hf));
132         proto_register_subtree_array(ett, array_length(ett));
133 }
134
135 void
136 proto_reg_handoff_cgmp(void)
137 {
138         dissector_handle_t cgmp_handle;
139
140         cgmp_handle = create_dissector_handle(dissect_cgmp, proto_cgmp);
141         dissector_add("llc.cisco_pid", 0x2001, cgmp_handle);
142         dissector_add("ethertype", 0x2001, cgmp_handle);
143 }