Replace the ETT_ "enum" members, declared in "packet.h", with
[obnox/wireshark/wip.git] / packet-vlan.c
1 /* packet-vlan.c
2  * Routines for VLAN 802.1Q ethernet header disassembly
3  *
4  * $Id: packet-vlan.c,v 1.4 1999/11/16 11:43:02 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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33
34 #ifdef HAVE_NETINET_IN_H
35 # include <netinet/in.h>
36 #endif
37
38 #include <glib.h>
39 #include "packet.h"
40
41 static int proto_vlan = -1;
42 static int hf_vlan_etype = -1;
43 static int hf_vlan_priority = -1;
44 static int hf_vlan_id = -1;
45 static int hf_vlan_cfi = -1;
46
47 static gint ett_vlan = -1;
48
49 void
50 dissect_vlan(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
51   proto_tree *ti, *vlan_tree = NULL;
52   guint16 tci,encap_proto;
53
54   if (!BYTES_ARE_IN_FRAME(offset, 2*sizeof(guint16))) {
55     return;
56   }
57
58   if (check_col(fd, COL_PROTOCOL))
59     col_add_str(fd, COL_PROTOCOL, "VLAN");
60
61   tci = pntohs( &pd[offset] );
62   encap_proto = pntohs( &pd[offset+2] );
63
64   if (check_col(fd, COL_INFO)) {
65     col_add_fstr(fd, COL_INFO, "PRI: %d  CFI: %d  ID: %d",
66       (tci >> 13), ((tci >> 12) & 1), (tci & 0xFFF));
67   }
68
69   if (tree) {
70     ti = proto_tree_add_item(tree, proto_vlan, offset, 4);
71     vlan_tree = proto_item_add_subtree(ti, ett_vlan);
72
73     proto_tree_add_item(vlan_tree, hf_vlan_priority, offset, 2, tci);
74     proto_tree_add_item(vlan_tree, hf_vlan_cfi, offset, 2, tci);
75     proto_tree_add_item(vlan_tree, hf_vlan_id, offset, 2, tci);
76   }
77
78   ethertype(encap_proto, offset+4, pd, fd, tree, vlan_tree, hf_vlan_etype);
79 }
80
81 void
82 proto_register_vlan(void)
83 {
84   static hf_register_info hf[] = {
85         { &hf_vlan_etype, { 
86                 "Type", "vlan.etype", FT_UINT16, BASE_HEX, 
87                 VALS(etype_vals), 0x0, "Type" }},
88         { &hf_vlan_priority, { 
89                 "Priority", "vlan.priority", FT_UINT16, BASE_BIN, 
90                 0, 0xE000, "Priority" }},
91         { &hf_vlan_cfi, { 
92                 "CFI", "vlan.cfi", FT_UINT16, BASE_BIN, 
93                 0, 0x1000, "CFI" }},
94         { &hf_vlan_id, { 
95                 "ID", "vlan.id", FT_UINT16, BASE_BIN, 
96                 0, 0x0FFF, "ID" }},
97   };
98   static gint *ett[] = {
99         &ett_vlan,
100   };
101
102   proto_vlan = proto_register_protocol("802.1q Virtual LAN", "vlan");
103   proto_register_field_array(proto_vlan, hf, array_length(hf));
104   proto_register_subtree_array(ett, array_length(ett));
105 }