From 22b84e5df00b2d930e79680729fef871baf24128 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Tue, 23 Aug 2011 23:57:35 -0300 Subject: [PATCH] Created IEEE802_11 constructor from buffer. Tagged option parsing and subclass parsing is missing. --- include/ieee802-11.h | 5 +++-- src/ieee802-11.cpp | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/ieee802-11.h b/include/ieee802-11.h index 09e0ba5..fb44950 100644 --- a/include/ieee802-11.h +++ b/include/ieee802-11.h @@ -509,7 +509,7 @@ namespace Tins { PDUType pdu_type() const { return PDU::IEEE802_11; } protected: virtual uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { return 0; } - private: + protected: /** * Struct that represents the 802.11 header */ @@ -556,7 +556,8 @@ namespace Tins { } __attribute__((__packed__)) seq_control; } __attribute__((__packed__)); - + private: + IEEE802_11(const ieee80211_header *header_ptr); void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent); diff --git a/src/ieee802-11.cpp b/src/ieee802-11.cpp index c274f31..adb409b 100644 --- a/src/ieee802-11.cpp +++ b/src/ieee802-11.cpp @@ -63,11 +63,18 @@ Tins::IEEE802_11::IEEE802_11(uint32_t iface_index, const uint8_t* dst_hw_addr, c } Tins::IEEE802_11::IEEE802_11(const ieee80211_header *header_ptr) : PDU(ETHERTYPE_IP) { - + } Tins::IEEE802_11::IEEE802_11(const uint8_t *buffer, uint32_t total_sz) : PDU(ETHERTYPE_IP), _options_size(0) { - + if(total_sz < sizeof(_header)) + throw std::runtime_error("Not enough size for an RadioTap header in the buffer."); + std::memcpy(&_header, buffer, sizeof(_header)); + buffer += sizeof(_header); + total_sz -= sizeof(_header); + + // Tagged arguments missing. + // subclass specific parsing missing too. } Tins::IEEE802_11::~IEEE802_11() {