trafgen: remove unused cmdline param
[netsniff-ng.git] / src / proto_vlan.c
blob0523ab3dcf33e9a959f8a2d13e39d7d6484ac2a1
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 #include <stdio.h>
10 #include <stdint.h>
11 #include <netinet/in.h> /* for ntohs() */
13 #include "proto.h"
14 #include "protos.h"
15 #include "dissector_eth.h"
16 #include "pkt_buff.h"
18 struct vlanhdr {
19 uint16_t h_vlan_TCI;
20 uint16_t h_vlan_encapsulated_proto;
21 } __attribute__((packed));
23 static void vlan(struct pkt_buff *pkt)
25 uint16_t tci;
26 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
28 if (vlan == NULL)
29 return;
31 tci = ntohs(vlan->h_vlan_TCI);
33 tprintf(" [ VLAN ");
34 tprintf("Prio (%d), ", (tci & 0xE000) >> 13);
35 tprintf("CFI (%d), ", (tci & 0x1000) >> 12);
36 tprintf("ID (%d), ", (tci & 0x0FFF));
37 tprintf("Proto (0x%.4x)", ntohs(vlan->h_vlan_encapsulated_proto));
38 tprintf(" ]\n");
40 pkt_set_proto(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
43 static void vlan_less(struct pkt_buff *pkt)
45 uint16_t tci;
46 struct vlanhdr *vlan = (struct vlanhdr *) pkt_pull(pkt, sizeof(*vlan));
48 if (vlan == NULL)
49 return;
51 tci = ntohs(vlan->h_vlan_TCI);
53 tprintf(" VLAN%d", (tci & 0x0FFF));
55 pkt_set_proto(pkt, &eth_lay2, ntohs(vlan->h_vlan_encapsulated_proto));
58 struct protocol vlan_ops = {
59 .key = 0x8100,
60 .print_full = vlan,
61 .print_less = vlan_less,
64 EXPORT_SYMBOL(vlan_ops);