2 * Routines for VLAN 802.1Q ethernet header disassembly
4 * $Id: packet-vlan.c,v 1.1 1999/10/20 22:41:11 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;
48 dissect_vlan(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
49 proto_tree *ti, *vlan_tree = NULL;
52 if (!BYTES_ARE_IN_FRAME(offset, 2*sizeof(guint16))) {
56 if (check_col(fd, COL_PROTOCOL))
57 col_add_str(fd, COL_PROTOCOL, "VLAN");
59 tci = ntohs( *((int *)pd) );
60 proto = ntohs( *((int *)pd) );
61 if (check_col(fd, COL_INFO)) {
62 col_add_fstr(fd, COL_INFO, "PRI: %d CFI: %d ID: %d",
63 (tci >> 5), (tci & (1 << 4)), (tci & 0xFFF));
67 ti = proto_tree_add_item(tree, proto_vlan, offset, 4);
68 vlan_tree = proto_item_add_subtree(ti, ETT_VLAN);
70 proto_tree_add_item(vlan_tree, hf_vlan_priority, offset, 2, tci);
71 proto_tree_add_item(vlan_tree, hf_vlan_cfi, offset, 2, tci);
72 proto_tree_add_item(vlan_tree, hf_vlan_id, offset, 2, tci);
75 ethertype(proto, offset+4, pd, fd, tree, vlan_tree, hf_vlan_etype);
79 proto_register_vlan(void)
81 static hf_register_info hf[] = {
83 "Type", "vlan.etype", FT_UINT16, BASE_HEX,
84 VALS(etype_vals), 0x0, "Type" }},
85 { &hf_vlan_priority, {
86 "Priority", "vlan.etype", FT_UINT16, BASE_BIN,
87 0, 0xE000, "Priority" }},
89 "CFI", "vlan.etype", FT_UINT16, BASE_BIN,
92 "ID", "vlan.etype", FT_UINT16, BASE_BIN,
96 proto_vlan = proto_register_protocol("802.1q Virtual LAN", "vlan");
97 proto_register_field_array(proto_vlan, hf, array_length(hf));