From f4b90d0194cdb5275823116b2229c04249225d7e Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Mon, 17 Aug 2015 00:21:30 +0300 Subject: [PATCH] netsniff-ng: vlan: Use helpers when parse vlan header Add proto_vlan.h with helpers to parse VLAN fields. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- proto_vlan.c | 7 ++++--- proto_vlan.h | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 proto_vlan.h diff --git a/proto_vlan.c b/proto_vlan.c index a175dde4..c1b3e65a 100644 --- a/proto_vlan.c +++ b/proto_vlan.c @@ -10,6 +10,7 @@ #include /* for ntohs() */ #include "proto.h" +#include "proto_vlan.h" #include "dissector_eth.h" #include "pkt_buff.h" @@ -29,9 +30,9 @@ static void vlan(struct pkt_buff *pkt) tci = ntohs(vlan->h_vlan_TCI); tprintf(" [ VLAN "); - tprintf("Prio (%d), ", (tci & 0xE000) >> 13); - tprintf("CFI (%d), ", (tci & 0x1000) >> 12); - tprintf("ID (%d), ", (tci & 0x0FFF)); + tprintf("Prio (%d), ", vlan_tci2prio(tci)); + tprintf("CFI (%d), ", vlan_tci2cfi(tci)); + tprintf("ID (%d), ", vlan_tci2vid(tci)); tprintf("Proto (0x%.4x)", ntohs(vlan->h_vlan_encapsulated_proto)); tprintf(" ]\n"); diff --git a/proto_vlan.h b/proto_vlan.h new file mode 100644 index 00000000..dc31cfac --- /dev/null +++ b/proto_vlan.h @@ -0,0 +1,27 @@ +/* + * proto_vlan.h - VLAN proto helpers & declarations + * Subject to the GPL, version 2. + */ + +#ifndef PROTO_VLAN_H +#define PROTO_VLAN_H + +#include +#include + +static inline uint16_t vlan_tci2prio(uint16_t tci) +{ + return (tci & 0xe000) >> 13; +} + +static inline uint16_t vlan_tci2cfi(uint16_t tci) +{ + return (tci & 0x1000) >> 12; +} + +static inline uint16_t vlan_tci2vid(uint16_t tci) +{ + return tci & 0x0fff; +} + +#endif -- 2.11.4.GIT