proto_ipv6_mobility_hdr.h: Headerfixing
[netsniff-ng.git] / src / proto_vlan.h
blob3949f4c63172c79b9fe0421db9b7ef5bae062ccd
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Copyright 2010 Emmanuel Roullit.
6 * Subject to the GPL, version 2.
7 */
9 #ifndef VLAN_H
10 #define VLAN_H
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <netinet/in.h> /* for ntohs() */
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
18 #include "pkt_buff.h"
20 struct vlanhdr {
21 uint16_t h_vlan_TCI;
22 uint16_t h_vlan_encapsulated_proto;
23 } __attribute__((packed));
25 static inline void vlan(struct pkt_buff *pkt)
27 uint16_t tci;
28 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
30 if (vlan == NULL)
31 return;
33 tci = ntohs(vlan->h_vlan_TCI);
35 tprintf(" [ VLAN ");
36 tprintf("Prio (%d), ", (tci & 0xE000) >> 13);
37 tprintf("CFI (%d), ", (tci & 0x1000) >> 12);
38 tprintf("ID (%d), ", (tci & 0x0FFF));
39 tprintf("Proto (0x%.4x)", ntohs(vlan->h_vlan_encapsulated_proto));
40 tprintf(" ]\n");
42 pkt_set_proto(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
45 static inline void vlan_less(struct pkt_buff *pkt)
47 uint16_t tci;
48 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
50 if (vlan == NULL)
51 return;
53 tci = ntohs(vlan->h_vlan_TCI);
55 tprintf(" VLAN%d", (tci & 0x0FFF));
57 pkt_set_proto(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
60 struct protocol vlan_ops = {
61 .key = 0x8100,
62 .print_full = vlan,
63 .print_less = vlan_less,
66 #endif /* VLAN_H */