netsniff-ng: nlmsg: Make netlink family strings more descriptive
[netsniff-ng.git] / proto_vlan_q_in_q.c
blob20b4bc18b6e17064aacb1c5e872dca95d1621511
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>, Deutsche Flugsicherung GmbH
4 * Subject to the GPL, version 2.
6 * http://www.ieee802.org/1/pages/802.1ad.html
7 */
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <netinet/in.h> /* for ntohs() */
13 #include "proto.h"
14 #include "dissector_eth.h"
15 #include "built_in.h"
16 #include "pkt_buff.h"
18 struct QinQhdr {
19 uint16_t TCI;
20 uint16_t TPID;
21 } __packed;
23 static void QinQ_full(struct pkt_buff *pkt)
25 uint16_t tci;
26 struct QinQhdr *QinQ = (struct QinQhdr *) pkt_pull(pkt, sizeof(*QinQ));
28 if (QinQ == NULL)
29 return;
31 tci = ntohs(QinQ->TCI);
33 tprintf(" [ VLAN QinQ ");
34 tprintf("Prio (%d), ", (tci & 0xE000) >> 13);
35 tprintf("DEI (%d), ", (tci & 0x1000) >> 12);
36 tprintf("ID (%d), ", (tci & 0x0FFF));
37 tprintf("Proto (0x%.4x)", ntohs(QinQ->TPID));
38 tprintf(" ]\n");
40 pkt_set_proto(pkt, &eth_lay2, ntohs(QinQ->TPID));
43 static void QinQ_less(struct pkt_buff *pkt)
45 uint16_t tci;
46 struct QinQhdr *QinQ = (struct QinQhdr *) pkt_pull(pkt, sizeof(*QinQ));
48 if (QinQ == NULL)
49 return;
51 tci = ntohs(QinQ->TCI);
53 tprintf(" VLAN%d", (tci & 0x0FFF));
55 pkt_set_proto(pkt, &eth_lay2, ntohs(QinQ->TPID));
58 struct protocol QinQ_ops = {
59 .key = 0x88a8,
60 .print_full = QinQ_full,
61 .print_less = QinQ_less,