netsniff-ng 0.5.9-rc2
[netsniff-ng.git] / proto_vlan.c
blobf9b2cf2ccdda76bf2c33f6a70d87a87d6fe3ae65
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Copyright 2010 Emmanuel Roullit.
5 * Subject to the GPL, version 2.
6 */
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <netinet/in.h> /* for ntohs() */
12 #include "proto.h"
13 #include "dissector_eth.h"
14 #include "pkt_buff.h"
16 struct vlanhdr {
17 uint16_t h_vlan_TCI;
18 uint16_t h_vlan_encapsulated_proto;
19 } __attribute__((packed));
21 static void vlan(struct pkt_buff *pkt)
23 uint16_t tci;
24 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
26 if (vlan == NULL)
27 return;
29 tci = ntohs(vlan->h_vlan_TCI);
31 tprintf(" [ VLAN ");
32 tprintf("Prio (%d), ", (tci & 0xE000) >> 13);
33 tprintf("CFI (%d), ", (tci & 0x1000) >> 12);
34 tprintf("ID (%d), ", (tci & 0x0FFF));
35 tprintf("Proto (0x%.4x)", ntohs(vlan->h_vlan_encapsulated_proto));
36 tprintf(" ]\n");
38 pkt_set_proto(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
41 static void vlan_less(struct pkt_buff *pkt)
43 uint16_t tci;
44 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
46 if (vlan == NULL)
47 return;
49 tci = ntohs(vlan->h_vlan_TCI);
51 tprintf(" VLAN%d", (tci & 0x0FFF));
53 pkt_set_proto(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
56 struct protocol vlan_ops = {
57 .key = 0x8100,
58 .print_full = vlan,
59 .print_less = vlan_less,