2 * Routines for VLAN 802.1Q ethernet header disassembly
4 * $Id: packet-vlan.c,v 1.4 1999/11/16 11:43:02 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
34 #ifdef HAVE_NETINET_IN_H
35 # include <netinet/in.h>
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;
47 static gint ett_vlan = -1;
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;
54 if (!BYTES_ARE_IN_FRAME(offset, 2*sizeof(guint16))) {
58 if (check_col(fd, COL_PROTOCOL))
59 col_add_str(fd, COL_PROTOCOL, "VLAN");
61 tci = pntohs( &pd[offset] );
62 encap_proto = pntohs( &pd[offset+2] );
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));
70 ti = proto_tree_add_item(tree, proto_vlan, offset, 4);
71 vlan_tree = proto_item_add_subtree(ti, ett_vlan);
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);
78 ethertype(encap_proto, offset+4, pd, fd, tree, vlan_tree, hf_vlan_etype);
82 proto_register_vlan(void)
84 static hf_register_info hf[] = {
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" }},
92 "CFI", "vlan.cfi", FT_UINT16, BASE_BIN,
95 "ID", "vlan.id", FT_UINT16, BASE_BIN,
98 static gint *ett[] = {
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));