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