Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/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  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <glib.h>
26
27 #include <epan/packet.h>
28
29 /*
30  * See
31  *
32  * http://www.barnett.sk/software/bbooks/cisco_multicasting_routing/chap04.html
33  *
34  * for some information on CGMP.
35  */
36 void proto_register_cgmp(void);
37 void proto_reg_handoff_cgmp(void);
38
39 static int proto_cgmp = -1;
40 static int hf_cgmp_version = -1;
41 static int hf_cgmp_type = -1;
42 static int hf_cgmp_count = -1;
43 static int hf_cgmp_gda = -1;
44 static int hf_cgmp_usa = -1;
45
46 static gint ett_cgmp = -1;
47
48 static const value_string type_vals[] = {
49         { 0, "Join" },
50         { 1, "Leave" },
51         { 0, NULL },
52 };
53
54 static void
55 dissect_cgmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
56 {
57         proto_item *ti;
58         proto_tree *cgmp_tree = NULL;
59         int offset = 0;
60         guint8 count;
61
62         col_set_str(pinfo->cinfo, COL_PROTOCOL, "CGMP");
63         col_set_str(pinfo->cinfo, COL_INFO, "Cisco Group Management Protocol");
64
65         if (tree) {
66                 ti = proto_tree_add_item(tree, proto_cgmp, tvb, offset, -1,
67                     ENC_NA);
68                 cgmp_tree = proto_item_add_subtree(ti, ett_cgmp);
69
70                 proto_tree_add_item(cgmp_tree, hf_cgmp_version, tvb, offset, 1,
71                     ENC_BIG_ENDIAN);
72                 proto_tree_add_item(cgmp_tree, hf_cgmp_type, tvb, offset, 1,
73                     ENC_BIG_ENDIAN);
74                 offset += 1;
75
76                 offset += 2;    /* skip reserved field */
77
78                 count = tvb_get_guint8(tvb, offset);
79                 proto_tree_add_uint(cgmp_tree, hf_cgmp_count, tvb, offset, 1,
80                     count);
81                 offset += 1;
82
83                 while (count != 0) {
84                         proto_tree_add_item(cgmp_tree, hf_cgmp_gda, tvb, offset, 6,
85                             ENC_NA);
86                         offset += 6;
87
88                         proto_tree_add_item(cgmp_tree, hf_cgmp_usa, tvb, offset, 6,
89                             ENC_NA);
90                         offset += 6;
91
92                         count--;
93                 }
94         }
95 }
96
97 void
98 proto_register_cgmp(void)
99 {
100         static hf_register_info hf[] = {
101                 { &hf_cgmp_version,
102                 { "Version",    "cgmp.version", FT_UINT8, BASE_DEC, NULL, 0xF0,
103                         NULL, HFILL }},
104
105                 { &hf_cgmp_type,
106                 { "Type",       "cgmp.type",    FT_UINT8, BASE_DEC, VALS(type_vals), 0x0F,
107                         NULL, HFILL }},
108
109                 { &hf_cgmp_count,
110                 { "Count",      "cgmp.count", FT_UINT8, BASE_DEC, NULL, 0x0,
111                         NULL, HFILL }},
112
113                 { &hf_cgmp_gda,
114                 { "Group Destination Address",  "cgmp.gda", FT_ETHER, BASE_NONE, NULL, 0x0,
115                         NULL, HFILL }},
116
117                 { &hf_cgmp_usa,
118                 { "Unicast Source Address",     "cgmp.usa", FT_ETHER, BASE_NONE, NULL, 0x0,
119                         NULL, HFILL }},
120         };
121         static gint *ett[] = {
122                 &ett_cgmp,
123         };
124
125         proto_cgmp = proto_register_protocol("Cisco Group Management Protocol",
126             "CGMP", "cgmp");
127         proto_register_field_array(proto_cgmp, hf, array_length(hf));
128         proto_register_subtree_array(ett, array_length(ett));
129 }
130
131 void
132 proto_reg_handoff_cgmp(void)
133 {
134         dissector_handle_t cgmp_handle;
135
136         cgmp_handle = create_dissector_handle(dissect_cgmp, proto_cgmp);
137         dissector_add_uint("llc.cisco_pid", 0x2001, cgmp_handle);
138         dissector_add_uint("ethertype", 0x2001, cgmp_handle);
139 }