Put back an unused variable, as a reminder that the routine it's in
[obnox/wireshark/wip.git] / packet-cgmp.c
1 /* packet-cgmp.c
2  * Routines for the disassembly of the Cisco Group Management Protocol
3  *
4  * $Id: packet-cgmp.c,v 1.15 2002/03/23 22:02:20 guy Exp $
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 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
29 #endif
30
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <glib.h>
35 #include <epan/packet.h>
36
37 /*
38  * See
39  *
40  * http://www.barnett.sk/software/bbooks/cisco_multicasting_routing/chap04.html
41  *
42  * for some information on CGMP.
43  */
44
45 static int proto_cgmp = -1;
46 static int hf_cgmp_version = -1;
47 static int hf_cgmp_type = -1;
48 static int hf_cgmp_count = -1;
49 static int hf_cgmp_gda = -1;
50 static int hf_cgmp_usa = -1;
51
52 static gint ett_cgmp = -1;
53
54 static const value_string type_vals[] = {
55         { 0, "Join" },
56         { 1, "Leave" },
57         { 0, NULL },
58 };
59         
60 static void 
61 dissect_cgmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
62 {
63         proto_item *ti; 
64         proto_tree *cgmp_tree = NULL;
65         int offset = 0;
66         guint8 count;
67
68         if (check_col(pinfo->cinfo, COL_PROTOCOL))
69                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CGMP");
70         if (check_col(pinfo->cinfo, COL_INFO))
71                 col_set_str(pinfo->cinfo, COL_INFO, "Cisco Group Management Protocol"); 
72
73         if (tree) {
74                 ti = proto_tree_add_item(tree, proto_cgmp, tvb, offset, -1,
75                     FALSE);
76                 cgmp_tree = proto_item_add_subtree(ti, ett_cgmp);
77         
78                 proto_tree_add_item(cgmp_tree, hf_cgmp_version, tvb, offset, 1,
79                     FALSE);
80                 proto_tree_add_item(cgmp_tree, hf_cgmp_type, tvb, offset, 1,
81                     FALSE);
82                 offset += 1;
83
84                 offset += 2;    /* skip reserved field */
85
86                 count = tvb_get_guint8(tvb, offset);
87                 proto_tree_add_uint(cgmp_tree, hf_cgmp_count, tvb, offset, 1,
88                     count);
89                 offset += 1;
90
91                 while (count != 0) {
92                         proto_tree_add_item(cgmp_tree, hf_cgmp_gda, tvb, offset, 6,
93                             FALSE);
94                         offset += 6;
95
96                         proto_tree_add_item(cgmp_tree, hf_cgmp_usa, tvb, offset, 6,
97                             FALSE);
98                         offset += 6;
99
100                         count--;
101                 }
102         }
103 }
104
105 void
106 proto_register_cgmp(void)
107 {
108         static hf_register_info hf[] = {
109                 { &hf_cgmp_version,
110                 { "Version",    "cgmp.version", FT_UINT8, BASE_DEC, NULL, 0xF0,
111                         "", HFILL }},
112
113                 { &hf_cgmp_type,
114                 { "Type",       "cgmp.type",    FT_UINT8, BASE_DEC, VALS(type_vals), 0x0F,
115                         "", HFILL }},
116
117                 { &hf_cgmp_count,
118                 { "Count",      "cgmp.count", FT_UINT8, BASE_DEC, NULL, 0x0,
119                         "", HFILL }},
120
121                 { &hf_cgmp_gda,
122                 { "Group Destination Address",  "cgmp.gda", FT_ETHER, BASE_NONE, NULL, 0x0,
123                         "Group Destination Address", HFILL }},
124
125                 { &hf_cgmp_usa,
126                 { "Unicast Source Address",     "cgmp.usa", FT_ETHER, BASE_NONE, NULL, 0x0,
127                         "Unicast Source Address", HFILL }},
128         };
129         static gint *ett[] = {
130                 &ett_cgmp,
131         };
132
133         proto_cgmp = proto_register_protocol("Cisco Group Management Protocol",
134             "CGMP", "cgmp");
135         proto_register_field_array(proto_cgmp, hf, array_length(hf));
136         proto_register_subtree_array(ett, array_length(ett));
137 }
138
139 void
140 proto_reg_handoff_cgmp(void)
141 {
142         dissector_handle_t cgmp_handle;
143
144         cgmp_handle = create_dissector_handle(dissect_cgmp, proto_cgmp);
145         dissector_add("llc.cisco_pid", 0x2001, cgmp_handle);
146         dissector_add("ethertype", 0x2001, cgmp_handle);
147 }