Include <time.h> to get "struct tm" declared.
[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.1 1999/10/20 22:41:11 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 void
48 dissect_vlan(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
49   proto_tree *ti, *vlan_tree = NULL;
50   guint16 tci,proto;
51
52   if (!BYTES_ARE_IN_FRAME(offset, 2*sizeof(guint16))) {
53     return;
54   }
55
56   if (check_col(fd, COL_PROTOCOL))
57     col_add_str(fd, COL_PROTOCOL, "VLAN");
58
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));
64   }
65
66   if (tree) {
67     ti = proto_tree_add_item(tree, proto_vlan, offset, 4);
68     vlan_tree = proto_item_add_subtree(ti, ETT_VLAN);
69
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);
73   }
74
75   ethertype(proto, offset+4, pd, fd, tree, vlan_tree, hf_vlan_etype);
76 }
77
78 void
79 proto_register_vlan(void)
80 {
81   static hf_register_info hf[] = {
82         { &hf_vlan_etype, { 
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" }},
88         { &hf_vlan_cfi, { 
89                 "CFI", "vlan.etype", FT_UINT16, BASE_BIN, 
90                 0, 0x1000, "CFI" }},
91         { &hf_vlan_id, { 
92                 "ID", "vlan.etype", FT_UINT16, BASE_BIN, 
93                 0, 0x0FFF, "ID" }},
94   };
95
96   proto_vlan = proto_register_protocol("802.1q Virtual LAN", "vlan");
97   proto_register_field_array(proto_vlan, hf, array_length(hf));
98 }