build: Add Makefile target for Coverity scanner
[netsniff-ng.git] / proto_vlan.c
blobbaa36b892d5a81623baad835703d1645a83f3c35
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 "protos.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 } __attribute__((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), ", (tci & 0xE000) >> 13);
34 tprintf("CFI (%d), ", (tci & 0x1000) >> 12);
35 tprintf("ID (%d), ", (tci & 0x0FFF));
36 tprintf("Proto (0x%.4x)", ntohs(vlan->h_vlan_encapsulated_proto));
37 tprintf(" ]\n");
39 pkt_set_proto(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_proto(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,