Patches to prevent problems under Windows when time formats are negative.
[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.5 2000/11/19 08:53:56 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 void 
62 dissect_cgmp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
63 {
64         proto_item *ti; 
65         proto_tree *cgmp_tree = NULL;
66         guint8 count;
67
68         OLD_CHECK_DISPLAY_AS_DATA(proto_cgmp, pd, offset, fd, tree);
69
70         if (check_col(fd, COL_PROTOCOL))
71                 col_set_str(fd, COL_PROTOCOL, "CGMP");
72         if (check_col(fd, COL_INFO))
73                 col_set_str(fd, COL_INFO, "Cisco Group Management Protocol"); 
74
75         if (tree) {
76                 ti = proto_tree_add_item(tree, proto_cgmp, NullTVB, offset, END_OF_FRAME, FALSE);
77                 cgmp_tree = proto_item_add_subtree(ti, ett_cgmp);
78         
79                 proto_tree_add_uint(cgmp_tree, hf_cgmp_version, NullTVB, offset, 1,
80                     pd[offset]);
81                 proto_tree_add_uint(cgmp_tree, hf_cgmp_type, NullTVB, offset, 1,
82                     pd[offset]);
83                 offset += 1;
84
85                 offset += 2;    /* skip reserved field */
86
87                 count = pd[offset];
88                 proto_tree_add_uint(cgmp_tree, hf_cgmp_count, NullTVB, offset, 1,
89                     count);
90                 offset += 1;
91
92                 while (count != 0) {
93                         if (!BYTES_ARE_IN_FRAME(offset, 6))
94                                 break;
95                         proto_tree_add_ether(cgmp_tree, hf_cgmp_gda, NullTVB, offset, 6,
96                             &pd[offset]);
97                         offset += 6;
98
99                         if (!BYTES_ARE_IN_FRAME(offset, 6))
100                                 break;
101                         proto_tree_add_ether(cgmp_tree, hf_cgmp_usa, NullTVB, offset, 6,
102                             &pd[offset]);
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", "cgmp");
139         proto_register_field_array(proto_cgmp, hf, array_length(hf));
140         proto_register_subtree_array(ett, array_length(ett));
141 }