docs: added project to PROJECTS file
[netsniff-ng.git] / src / proto_vlan.h
blob45195c56fbbda6aba38c4cc498ed75e337e1031c
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"
19 struct vlanhdr {
20 uint16_t h_vlan_TCI;
21 uint16_t h_vlan_encapsulated_proto;
22 } __attribute__((packed));
24 static inline void vlan(uint8_t *packet, size_t len)
26 uint16_t tci;
27 struct vlanhdr *vlan = (struct vlanhdr *) packet;
29 if (len < sizeof(struct vlanhdr))
30 return;
32 tci = ntohs(vlan->h_vlan_TCI);
34 tprintf(" [ VLAN ");
35 tprintf("Prio (%d), ", (tci & 0xE000) >> 13);
36 tprintf("CFI (%d), ", (tci & 0x1000) >> 12);
37 tprintf("ID (%d), ", (tci & 0x0FFF));
38 tprintf("Proto (0x%.4x)", ntohs(vlan->h_vlan_encapsulated_proto));
39 tprintf(" ]\n");
42 static inline void vlan_less(uint8_t *packet, size_t len)
44 uint16_t tci;
45 struct vlanhdr *vlan = (struct vlanhdr *) packet;
47 if (len < sizeof(struct vlanhdr))
48 return;
50 tci = ntohs(vlan->h_vlan_TCI);
52 tprintf(" VLAN%d", (tci & 0x0FFF));
55 static inline void vlan_next(uint8_t *packet, size_t len,
56 struct hash_table **table,
57 unsigned int *key, size_t *off)
59 struct vlanhdr *vlan = (struct vlanhdr *) packet;
61 if (len < sizeof(struct vlanhdr))
62 goto invalid;
64 (*off) = sizeof(struct vlanhdr);
65 (*key) = ntohs(vlan->h_vlan_encapsulated_proto);
66 (*table) = &eth_lay2;
68 return;
69 invalid:
70 (*off) = 0;
71 (*key) = 0;
72 (*table) = NULL;
75 struct protocol vlan_ops = {
76 .key = 0x8100,
77 .offset = sizeof(struct vlanhdr),
78 .print_full = vlan,
79 .print_less = vlan_less,
80 .print_pay_ascii = empty,
81 .print_pay_hex = empty,
82 .print_pay_none = vlan,
83 .print_all_cstyle = __hex2,
84 .print_all_hex = __hex,
85 .proto_next = vlan_next,
88 #endif /* VLAN_H */