netsniff-ng: fix --bind-cpu option in example command line
[netsniff-ng-new.git] / proto_vlan.c
blobebdf28198fff22b93c97c87efc9a4e864e4d1067
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 "vlan.h"
14 #include "dissector_eth.h"
15 #include "pkt_buff.h"
17 struct vlanhdr {
18 uint16_t h_vlan_TCI;
19 uint16_t h_vlan_encapsulated_proto;
20 } __packed;
22 static void vlan(struct pkt_buff *pkt)
24 uint16_t tci;
25 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
27 if (vlan == NULL)
28 return;
30 tci = ntohs(vlan->h_vlan_TCI);
32 tprintf(" [ VLAN ");
33 tprintf("Prio (%d), ", vlan_tci2prio(tci));
34 tprintf("CFI (%d), ", vlan_tci2cfi(tci));
35 tprintf("ID (%d), ", vlan_tci2vid(tci));
36 tprintf("Proto (0x%.4x)", ntohs(vlan->h_vlan_encapsulated_proto));
37 tprintf(" ]\n");
39 pkt_set_dissector(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
42 static void vlan_less(struct pkt_buff *pkt)
44 uint16_t tci;
45 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
47 if (vlan == NULL)
48 return;
50 tci = ntohs(vlan->h_vlan_TCI);
52 tprintf(" VLAN%d", (tci & 0x0FFF));
54 pkt_set_dissector(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
57 struct protocol vlan_ops = {
58 .key = 0x8100,
59 .print_full = vlan,
60 .print_less = vlan_less,