diff --git a/include/bootp.h b/include/bootp.h index 7e1bb93..48f0eec 100644 --- a/include/bootp.h +++ b/include/bootp.h @@ -23,10 +23,11 @@ #define TINS_BOOTP_H #include -#include +#include #include "pdu.h" #include "utils.h" #include "ipaddress.h" +#include "hwaddress.h" namespace Tins { @@ -35,8 +36,8 @@ namespace Tins { * \brief Class representing a BootP packet. */ class BootP : public PDU { - public: + typedef HWAddress<16> chaddr_type; /** * \brief This PDU's flag. */ @@ -156,7 +157,8 @@ namespace Tins { * \brief Getter for the chaddr field. * \return The chddr field for this BootP PDU. */ - const uint8_t *chaddr() const { return _bootp.chaddr; } + //const uint8_t *chaddr() const { return _bootp.chaddr; } + chaddr_type chaddr() const { return _bootp.chaddr; } /** * \brief Getter for the sname field. @@ -260,7 +262,17 @@ namespace Tins { * The new_chaddr pointer must be at least BOOTP::hlen() bytes long. * \param new_chaddr The chaddr to be set. */ - void chaddr(const uint8_t *new_chaddr); + template + void chaddr(const HWAddress &new_chaddr) { + // Copy the new addr + uint8_t *end = std::copy( + new_chaddr.begin(), + new_chaddr.begin() + std::min(n, sizeof(_bootp.chaddr)), + _bootp.chaddr + ); + // Fill what's left with zeros + std::fill(end, _bootp.chaddr + chaddr_type::address_size, 0); + } /** * \brief Setter for the sname field. @@ -288,11 +300,11 @@ namespace Tins { PDUType pdu_type() const { return PDU::BOOTP; } /** - * \brief Clones this PDU. - * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + PDU *clone_pdu() const { + return do_clone_pdu(); + } protected: void copy_bootp_fields(const BootP *other); void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent); diff --git a/include/dhcp.h b/include/dhcp.h index 2828395..224ceb0 100644 --- a/include/dhcp.h +++ b/include/dhcp.h @@ -182,23 +182,6 @@ namespace Tins { */ DHCP(const uint8_t *buffer, uint32_t total_sz); - /** - * \brief Copy constructor. - */ - DHCP(const DHCP &other); - - /** - * \brief Copy assignment operator. - */ - DHCP &operator= (const DHCP &other); - - /** - * \brief DHCP destructor - * - * Releases the memory allocated for options. - */ - ~DHCP(); - /** * \brief Adds a new option to this DHCP PDU. * @@ -391,11 +374,11 @@ namespace Tins { uint32_t header_size() const; /** - * \brief Clones this PDU. - * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + PDU *clone_pdu() const { + return do_clone_pdu(); + } private: static const uint32_t MAX_DHCP_SIZE; diff --git a/include/dot11.h b/include/dot11.h index 41a86ce..dd98471 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -49,12 +49,7 @@ namespace Tins { /** * \brief Broadcast hardware address. */ - static const uint8_t *BROADCAST; - - /** - * \brief Dot11 address size. - */ - static const uint32_t ADDR_SIZE = 6; + static const address_type BROADCAST; /** * \brief Enum for the different types of 802.11 frames. @@ -970,7 +965,7 @@ namespace Tins { * * \return The fourth address as a constant uint8_t pointer. */ - const uint8_t* addr4() const { return this->_addr4; } + const address_type &addr4() const { return this->_addr4; } /** * \brief Setter for the second address. @@ -1005,7 +1000,7 @@ namespace Tins { * * \param new_addr4 const uint8_t array of 6 bytes containing the new fourth address. */ - void addr4(const uint8_t* new_addr4); + void addr4(const address_type &new_addr4); /** * \brief Returns the 802.11 frame's header length. @@ -1271,11 +1266,12 @@ namespace Tins { void copy_ext_header(const Dot11ManagementFrame *other); - uint32_t management_frame_size() { return sizeof(_ext_header) + (from_ds() && to_ds()) ? sizeof(_addr4) : 0; } + uint32_t management_frame_size() { + return sizeof(_ext_header) + (from_ds() && to_ds()) ? address_type::address_size : 0; + } private: ExtendedHeader _ext_header; - uint8_t _addr4[6]; - + address_type _addr4; }; /** diff --git a/include/hwaddress.h b/include/hwaddress.h index 0dbb882..dc3d981 100644 --- a/include/hwaddress.h +++ b/include/hwaddress.h @@ -55,6 +55,15 @@ public: convert(address, buffer); } + template + HWAddress(const HWAddress &rhs) { + std::copy( + rhs.begin(), + rhs.begin() + std::min(i, n), + begin() + ); + } + HWAddress& operator=(const std::string &address) { convert(address, buffer); } diff --git a/include/pdu.h b/include/pdu.h index a3e1750..4cb0e3d 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -126,13 +126,13 @@ namespace Tins { * \brief Getter for this PDU's type flag identifier. * \return The type flag identifier. */ - inline uint32_t flag() const { return _flag; } + uint32_t flag() const { return _flag; } /** * \brief Getter for the inner PDU. * \return The current inner PDU. Might be 0. */ - inline PDU *inner_pdu() const { return _inner_pdu; } + PDU *inner_pdu() const { return _inner_pdu; } /** \brief Sets the flag identifier. */ diff --git a/src/bootp.cpp b/src/bootp.cpp index 8005334..81458be 100644 --- a/src/bootp.cpp +++ b/src/bootp.cpp @@ -1,16 +1,39 @@ +/* + * libtins is a net packet wrapper library for crafting and + * interpreting sniffed packets. + * + * Copyright (C) 2011 Nasel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include #include #include #include "bootp.h" - -Tins::BootP::BootP() : PDU(255), _vend_size(64) { +namespace Tins{ +BootP::BootP() : PDU(255), _vend_size(64) { _vend = new uint8_t[64]; std::memset(&_bootp, 0, sizeof(bootphdr)); std::memset(_vend, 0, 64); } -Tins::BootP::BootP(const uint8_t *buffer, uint32_t total_sz, uint32_t vend_field_size) : PDU(255), _vend(0), _vend_size(vend_field_size) { +BootP::BootP(const uint8_t *buffer, uint32_t total_sz, uint32_t vend_field_size) +: PDU(255), _vend(0), _vend_size(vend_field_size) +{ if(total_sz < sizeof(bootphdr) + vend_field_size) throw std::runtime_error("Not enough size for a BootP header in the buffer."); std::memcpy(&_bootp, buffer, sizeof(bootphdr)); @@ -18,99 +41,95 @@ Tins::BootP::BootP(const uint8_t *buffer, uint32_t total_sz, uint32_t vend_field total_sz -= sizeof(bootphdr); if(_vend_size) { _vend = new uint8_t[_vend_size]; - std::memcpy(_vend, buffer, _vend_size); + std::copy(buffer, buffer + _vend_size, _vend); } // Maybe RawPDU on what is left on the buffer?... } -Tins::BootP::BootP(const BootP &other) : PDU(other) { +BootP::BootP(const BootP &other) : PDU(other) { copy_bootp_fields(&other); } -Tins::BootP &Tins::BootP::operator= (const BootP &other) { +BootP &BootP::operator= (const BootP &other) { copy_bootp_fields(&other); - copy_inner_pdu(other); return *this; } -Tins::BootP::~BootP() { +BootP::~BootP() { delete[] _vend; } -uint32_t Tins::BootP::header_size() const { +uint32_t BootP::header_size() const { return sizeof(bootphdr) + _vend_size; } -void Tins::BootP::opcode(uint8_t new_opcode) { +void BootP::opcode(uint8_t new_opcode) { _bootp.opcode = new_opcode; } -void Tins::BootP::htype(uint8_t new_htype) { +void BootP::htype(uint8_t new_htype) { _bootp.htype = new_htype; } -void Tins::BootP::hlen(uint8_t new_hlen) { +void BootP::hlen(uint8_t new_hlen) { _bootp.hlen = new_hlen; } -void Tins::BootP::hops(uint8_t new_hops) { +void BootP::hops(uint8_t new_hops) { _bootp.hops = new_hops; } -void Tins::BootP::xid(uint32_t new_xid) { +void BootP::xid(uint32_t new_xid) { _bootp.xid = Utils::net_to_host_l(new_xid); } -void Tins::BootP::secs(uint16_t new_secs) { +void BootP::secs(uint16_t new_secs) { _bootp.secs = Utils::net_to_host_s(new_secs); } -void Tins::BootP::padding(uint16_t new_padding) { +void BootP::padding(uint16_t new_padding) { _bootp.padding = Utils::net_to_host_s(new_padding); } -void Tins::BootP::ciaddr(IPv4Address new_ciaddr) { +void BootP::ciaddr(IPv4Address new_ciaddr) { _bootp.ciaddr = new_ciaddr; } -void Tins::BootP::yiaddr(IPv4Address new_yiaddr) { +void BootP::yiaddr(IPv4Address new_yiaddr) { _bootp.yiaddr = new_yiaddr; } -void Tins::BootP::siaddr(IPv4Address new_siaddr) { +void BootP::siaddr(IPv4Address new_siaddr) { _bootp.siaddr = new_siaddr; } -void Tins::BootP::giaddr(IPv4Address new_giaddr) { +void BootP::giaddr(IPv4Address new_giaddr) { _bootp.giaddr = new_giaddr; } -void Tins::BootP::chaddr(const uint8_t *new_chaddr) { - std::memcpy(_bootp.chaddr, new_chaddr, _bootp.hlen); -} - -void Tins::BootP::sname(const uint8_t *new_sname) { +void BootP::sname(const uint8_t *new_sname) { std::memcpy(_bootp.sname, new_sname, sizeof(_bootp.sname)); } -void Tins::BootP::file(const uint8_t *new_file) { +void BootP::file(const uint8_t *new_file) { std::memcpy(_bootp.file, new_file, sizeof(_bootp.file)); } -void Tins::BootP::vend(uint8_t *new_vend, uint32_t size) { +void BootP::vend(uint8_t *new_vend, uint32_t size) { delete[] _vend; _vend_size = size; _vend = new uint8_t[size]; - std::memcpy(_vend, new_vend, size); + std::copy(new_vend, new_vend + size, _vend); } -void Tins::BootP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { +void BootP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { assert(total_sz >= sizeof(bootphdr) + _vend_size); std::memcpy(buffer, &_bootp, sizeof(bootphdr)); - std::memcpy(buffer + sizeof(bootphdr), _vend, _vend_size); + //std::memcpy(buffer + sizeof(bootphdr), _vend, _vend_size); + std::copy(_vend, _vend + _vend_size, buffer + sizeof(bootphdr)); } -void Tins::BootP::copy_bootp_fields(const BootP *other) { +void BootP::copy_bootp_fields(const BootP *other) { std::memcpy(&_bootp, &other->_bootp, sizeof(_bootp)); _vend_size = other->_vend_size; if(_vend_size) { @@ -120,9 +139,4 @@ void Tins::BootP::copy_bootp_fields(const BootP *other) { else _vend = 0; } - -Tins::PDU *Tins::BootP::clone_pdu() const { - BootP *new_pdu = new BootP(); - new_pdu->copy_bootp_fields(this); - return new_pdu; } diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 93ff3e9..1e42859 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -61,7 +61,7 @@ DHCP::DHCP(const uint8_t *buffer, uint32_t total_sz) throw std::runtime_error("Not enough size for a DHCP header in the buffer."); } // If the END-OF-OPTIONS was not found... - if(args[0] != END && args[0] != PAD) { + if(args[0] != END && args[0] != PAD) { // Not enough size for this option if(total_sz < args[1]) throw std::runtime_error("Not enough size for a DHCP header in the buffer."); @@ -75,31 +75,9 @@ DHCP::DHCP(const uint8_t *buffer, uint32_t total_sz) } } -DHCP::DHCP(const DHCP &other) : BootP(other) { - copy_fields(&other); -} - -DHCP &DHCP::operator= (const DHCP &other) { - copy_fields(&other); - copy_inner_pdu(other); - return *this; -} - -DHCP::~DHCP() { - /*while(_options.size()) { - delete[] _options.front().value; - _options.pop_front(); - }*/ -} - DHCP::DHCPOption::DHCPOption(uint8_t opt, uint8_t len, const uint8_t *val) : option(opt), value(val, val ? (val + len) : val) { - /*if(len) { - value = new uint8_t[len]; - std::memcpy(value, val, len); - } - else - value = 0;*/ + } bool DHCP::add_option(Options opt, uint8_t len, const uint8_t *val) { @@ -262,13 +240,6 @@ void DHCP::copy_fields(const DHCP *other) { _size = other->_size; for(options_type::const_iterator it = other->_options.begin(); it != other->_options.end(); ++it) _options.push_back(*it); - //_options.push_back(DHCPOption(it->option, it->length, it->value)); -} - -PDU *DHCP::clone_pdu() const { - DHCP *new_pdu = new DHCP(); - new_pdu->copy_fields(this); - return new_pdu; } bool DHCP::generic_search(Options opt, std::list *container) { diff --git a/src/dot11.cpp b/src/dot11.cpp index c465fec..ac03cb6 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -39,17 +39,17 @@ using namespace std; -const uint8_t *Tins::Dot11::BROADCAST = (const uint8_t*)"\xff\xff\xff\xff\xff\xff"; -const uint32_t Tins::Dot11::ADDR_SIZE; +namespace Tins { +const Dot11::address_type Dot11::BROADCAST = "ff:ff:ff:ff:ff:ff"; -Tins::Dot11::Dot11(const address_type &dst_hw_addr, PDU* child) +Dot11::Dot11(const address_type &dst_hw_addr, PDU* child) : PDU(ETHERTYPE_IP, child), _options_size(0) { memset(&this->_header, 0, sizeof(ieee80211_header)); addr1(dst_hw_addr); } -Tins::Dot11::Dot11(const NetworkInterface &iface, +Dot11::Dot11(const NetworkInterface &iface, const address_type &dst_hw_addr, PDU* child) : PDU(ETHERTYPE_IP, child), _options_size(0) { @@ -58,13 +58,13 @@ Tins::Dot11::Dot11(const NetworkInterface &iface, this->iface(iface); } -Tins::Dot11::Dot11(const ieee80211_header *header_ptr) +Dot11::Dot11(const ieee80211_header *header_ptr) : PDU(ETHERTYPE_IP) { } -Tins::Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz) +Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz) : PDU(ETHERTYPE_IP), _options_size(0) { if(total_sz < sizeof(_header.control)) @@ -75,24 +75,24 @@ Tins::Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz) total_sz -= sz; } -Tins::Dot11::Dot11(const Dot11 &other) : PDU(other) { +Dot11::Dot11(const Dot11 &other) : PDU(other) { copy_80211_fields(&other); } -Tins::Dot11::~Dot11() { +Dot11::~Dot11() { while(_options.size()) { delete[] _options.front().value; _options.pop_front(); } } -Tins::Dot11 &Tins::Dot11::operator= (const Dot11 &other) { +Dot11 &Dot11::operator= (const Dot11 &other) { copy_80211_fields(&other); copy_inner_pdu(other); return *this; } -void Tins::Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) { +void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) { uint8_t opcode, length; while(total_sz >= 2) { opcode = buffer[0]; @@ -107,82 +107,82 @@ void Tins::Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_ } } -Tins::Dot11::Dot11Option::Dot11Option(uint8_t opt, uint8_t len, const uint8_t *val) : option(opt), length(len) { +Dot11::Dot11Option::Dot11Option(uint8_t opt, uint8_t len, const uint8_t *val) : option(opt), length(len) { value = new uint8_t[len]; std::memcpy(value, val, len); } -void Tins::Dot11::add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val) { +void Dot11::add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val) { uint32_t opt_size = len + (sizeof(uint8_t) << 1); _options.push_back(Dot11Option((uint8_t)opt, len, val)); _options_size += opt_size; } -const Tins::Dot11::Dot11Option *Tins::Dot11::search_option(TaggedOption opt) const { +const Dot11::Dot11Option *Dot11::search_option(TaggedOption opt) const { for(std::list::const_iterator it = _options.begin(); it != _options.end(); ++it) if(it->option == (uint8_t)opt) return &(*it); return 0; } -void Tins::Dot11::protocol(uint8_t new_proto) { +void Dot11::protocol(uint8_t new_proto) { this->_header.control.protocol = new_proto; } -void Tins::Dot11::type(uint8_t new_type) { +void Dot11::type(uint8_t new_type) { this->_header.control.type = new_type; } -void Tins::Dot11::subtype(uint8_t new_subtype) { +void Dot11::subtype(uint8_t new_subtype) { this->_header.control.subtype = new_subtype; } -void Tins::Dot11::to_ds(bool new_value) { +void Dot11::to_ds(bool new_value) { this->_header.control.to_ds = (new_value)? 1 : 0; } -void Tins::Dot11::from_ds(bool new_value) { +void Dot11::from_ds(bool new_value) { this->_header.control.from_ds = (new_value)? 1 : 0; } -void Tins::Dot11::more_frag(bool new_value) { +void Dot11::more_frag(bool new_value) { this->_header.control.more_frag = (new_value)? 1 : 0; } -void Tins::Dot11::retry(bool new_value) { +void Dot11::retry(bool new_value) { this->_header.control.retry = (new_value)? 1 : 0; } -void Tins::Dot11::power_mgmt(bool new_value) { +void Dot11::power_mgmt(bool new_value) { this->_header.control.power_mgmt = (new_value)? 1 : 0; } -void Tins::Dot11::wep(bool new_value) { +void Dot11::wep(bool new_value) { this->_header.control.wep = (new_value)? 1 : 0; } -void Tins::Dot11::order(bool new_value) { +void Dot11::order(bool new_value) { this->_header.control.order = (new_value)? 1 : 0; } -void Tins::Dot11::duration_id(uint16_t new_duration_id) { +void Dot11::duration_id(uint16_t new_duration_id) { this->_header.duration_id = new_duration_id; } -void Tins::Dot11::addr1(const address_type &new_addr1) { +void Dot11::addr1(const address_type &new_addr1) { std::copy(new_addr1.begin(), new_addr1.end(), _header.addr1); } -void Tins::Dot11::iface(const NetworkInterface &new_iface) { +void Dot11::iface(const NetworkInterface &new_iface) { this->_iface = new_iface; } -uint32_t Tins::Dot11::header_size() const { +uint32_t Dot11::header_size() const { uint32_t sz = sizeof(ieee80211_header) + _options_size; return sz; } -bool Tins::Dot11::send(PacketSender* sender) { +bool Dot11::send(PacketSender* sender) { struct sockaddr_ll addr; memset(&addr, 0, sizeof(struct sockaddr_ll)); @@ -196,7 +196,7 @@ bool Tins::Dot11::send(PacketSender* sender) { return sender->send_l2(this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr)); } -void Tins::Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { +void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { uint32_t my_sz = header_size(); assert(total_sz >= my_sz); memcpy(buffer, &_header, sizeof(_header)); @@ -218,7 +218,7 @@ void Tins::Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const } } -Tins::PDU *Tins::Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { +PDU *Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { // We only need the control field, the length of the PDU will depend on the flags set. if(total_sz < sizeof(ieee80211_header::control)) throw std::runtime_error("Not enough size for a IEEE 802.11 header in the buffer."); @@ -256,7 +256,7 @@ Tins::PDU *Tins::Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { return ret; } -void Tins::Dot11::copy_80211_fields(const Dot11 *other) { +void Dot11::copy_80211_fields(const Dot11 *other) { std::memcpy(&_header, &other->_header, sizeof(_header)); _iface = other->_iface; _options_size = other->_options_size; @@ -266,17 +266,18 @@ void Tins::Dot11::copy_80211_fields(const Dot11 *other) { /* Dot11ManagementFrame */ -Tins::Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) { +Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) { buffer += sizeof(ieee80211_header); total_sz -= sizeof(ieee80211_header); if(total_sz < sizeof(_ext_header)) throw std::runtime_error("Not enough size for an IEEE 802.11 header in the buffer."); std::memcpy(&_ext_header, buffer, sizeof(_ext_header)); if(from_ds() && to_ds()) - std::memcpy(_addr4, buffer + sizeof(_ext_header), sizeof(_addr4)); + _addr4 = buffer + sizeof(_ext_header); + //std::memcpy(_addr4, buffer + sizeof(_ext_header), sizeof(_addr4)); } -Tins::Dot11ManagementFrame::Dot11ManagementFrame( +Dot11ManagementFrame::Dot11ManagementFrame( const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11(dst_hw_addr) { @@ -284,7 +285,7 @@ Tins::Dot11ManagementFrame::Dot11ManagementFrame( addr2(src_hw_addr); } -Tins::Dot11ManagementFrame::Dot11ManagementFrame(const NetworkInterface &iface, +Dot11ManagementFrame::Dot11ManagementFrame(const NetworkInterface &iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11(iface, dst_hw_addr) { @@ -292,66 +293,67 @@ Tins::Dot11ManagementFrame::Dot11ManagementFrame(const NetworkInterface &iface, addr2(src_hw_addr); } -Tins::Dot11ManagementFrame::Dot11ManagementFrame(const Dot11ManagementFrame &other) : Dot11(other) { +Dot11ManagementFrame::Dot11ManagementFrame(const Dot11ManagementFrame &other) : Dot11(other) { copy_ext_header(&other); } -void Tins::Dot11ManagementFrame::copy_ext_header(const Dot11ManagementFrame* other) { +void Dot11ManagementFrame::copy_ext_header(const Dot11ManagementFrame* other) { Dot11::copy_80211_fields(other); std::memcpy(&_ext_header, &other->_ext_header, sizeof(_ext_header)); - std::memcpy(_addr4, other->_addr4, 6); + //std::memcpy(_addr4, other->_addr4, 6); + _addr4 = other->_addr4; } -uint32_t Tins::Dot11ManagementFrame::header_size() const { +uint32_t Dot11ManagementFrame::header_size() const { uint32_t sz = Dot11::header_size() + sizeof(_ext_header); if (this->from_ds() && this->to_ds()) sz += 6; return sz; } -void Tins::Dot11ManagementFrame::addr2(const address_type &new_addr2) { +void Dot11ManagementFrame::addr2(const address_type &new_addr2) { std::copy(new_addr2.begin(), new_addr2.end(), _ext_header.addr2); } -void Tins::Dot11ManagementFrame::addr3(const address_type &new_addr3) { +void Dot11ManagementFrame::addr3(const address_type &new_addr3) { std::copy(new_addr3.begin(), new_addr3.end(), _ext_header.addr3); } -void Tins::Dot11ManagementFrame::frag_num(uint8_t new_frag_num) { +void Dot11ManagementFrame::frag_num(uint8_t new_frag_num) { this->_ext_header.seq_control.frag_number = new_frag_num; } -void Tins::Dot11ManagementFrame::seq_num(uint16_t new_seq_num) { +void Dot11ManagementFrame::seq_num(uint16_t new_seq_num) { this->_ext_header.seq_control.seq_number = new_seq_num; } -void Tins::Dot11ManagementFrame::addr4(const uint8_t* new_addr4) { - memcpy(this->_addr4, new_addr4, 6); +void Dot11ManagementFrame::addr4(const address_type &new_addr4) { + _addr4 = new_addr4; } -uint32_t Tins::Dot11ManagementFrame::write_ext_header(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11ManagementFrame::write_ext_header(uint8_t *buffer, uint32_t total_sz) { uint32_t written = sizeof(_ext_header); memcpy(buffer, &_ext_header, sizeof(this->_ext_header)); buffer += sizeof(_ext_header); if (from_ds() && to_ds()) { written += 6; - memcpy(buffer, _addr4, 6); + std::copy(_addr4.begin(), _addr4.end(), buffer); } return written; } -void Tins::Dot11ManagementFrame::ssid(const std::string &new_ssid) { +void Dot11ManagementFrame::ssid(const std::string &new_ssid) { add_tagged_option(Dot11::SSID, new_ssid.size(), (const uint8_t*)new_ssid.c_str()); } -void Tins::Dot11ManagementFrame::rsn_information(const RSNInformation& info) { +void Dot11ManagementFrame::rsn_information(const RSNInformation& info) { uint32_t size; uint8_t *buffer = info.serialize(size); add_tagged_option(RSN, size, buffer); delete[] buffer; } -void Tins::Dot11ManagementFrame::supported_rates(const std::list &new_rates) { +void Dot11ManagementFrame::supported_rates(const std::list &new_rates) { uint8_t *buffer = new uint8_t[new_rates.size()], *ptr = buffer; for(std::list::const_iterator it = new_rates.begin(); it != new_rates.end(); ++it) { uint8_t result = 0x80, left = *it / 0.5; @@ -363,7 +365,7 @@ void Tins::Dot11ManagementFrame::supported_rates(const std::list &new_rat delete[] buffer; } -void Tins::Dot11ManagementFrame::extended_supported_rates(const std::list &new_rates) { +void Dot11ManagementFrame::extended_supported_rates(const std::list &new_rates) { uint8_t *buffer = new uint8_t[new_rates.size()], *ptr = buffer; for(std::list::const_iterator it = new_rates.begin(); it != new_rates.end(); ++it) { uint8_t result = 0x80, left = *it / 0.5; @@ -375,18 +377,18 @@ void Tins::Dot11ManagementFrame::extended_supported_rates(const std::list delete[] buffer; } -void Tins::Dot11ManagementFrame::qos_capabilities(uint8_t new_qos_capabilities) { +void Dot11ManagementFrame::qos_capabilities(uint8_t new_qos_capabilities) { add_tagged_option(QOS_CAPABILITY, 1, &new_qos_capabilities); } -void Tins::Dot11ManagementFrame::power_capabilities(uint8_t min_power, uint8_t max_power) { +void Dot11ManagementFrame::power_capabilities(uint8_t min_power, uint8_t max_power) { uint8_t buffer[2]; buffer[0] = min_power; buffer[1] = max_power; add_tagged_option(POWER_CAPABILITY, 2, buffer); } -void Tins::Dot11ManagementFrame::supported_channels(const std::list > &new_channels) { +void Dot11ManagementFrame::supported_channels(const std::list > &new_channels) { uint8_t* buffer = new uint8_t[new_channels.size() * 2]; uint8_t* ptr = buffer; for(std::list >::const_iterator it = new_channels.begin(); it != new_channels.end(); ++it) { @@ -397,7 +399,7 @@ void Tins::Dot11ManagementFrame::supported_channels(const std::list elements) { +void Dot11ManagementFrame::request_information(const std::list elements) { uint16_t sz = elements.size(); list::const_iterator it = elements.begin(); uint8_t* buffer = new uint8_t[sz]; @@ -420,7 +422,7 @@ void Tins::Dot11ManagementFrame::request_information(const std::list el delete[] buffer; } -void Tins::Dot11ManagementFrame::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index) { +void Dot11ManagementFrame::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index) { uint8_t buffer[5]; uint16_t* ptr_buffer = (uint16_t*)buffer; ptr_buffer[0] = dwell_time; @@ -431,11 +433,11 @@ void Tins::Dot11ManagementFrame::fh_parameter_set(uint16_t dwell_time, uint8_t h } -void Tins::Dot11ManagementFrame::ds_parameter_set(uint8_t current_channel) { +void Dot11ManagementFrame::ds_parameter_set(uint8_t current_channel) { add_tagged_option(DS_SET, 1, ¤t_channel); } -void Tins::Dot11ManagementFrame::cf_parameter_set(uint8_t cfp_count, +void Dot11ManagementFrame::cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining) { @@ -449,11 +451,11 @@ void Tins::Dot11ManagementFrame::cf_parameter_set(uint8_t cfp_count, } -void Tins::Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) { +void Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) { add_tagged_option(IBSS_SET, 2, (uint8_t*)&atim_window); } -void Tins::Dot11ManagementFrame::country(const std::vector& countries, +void Dot11ManagementFrame::country(const std::vector& countries, const std::vector& first_channels, const std::vector& number_channels, const std::vector& max_power) { @@ -484,14 +486,14 @@ void Tins::Dot11ManagementFrame::country(const std::vector& countries, } -void Tins::Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { +void Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { uint8_t buffer[2]; buffer[0] = prime_radix; buffer[1] = number_channels; add_tagged_option(HOPPING_PATTERN_PARAMS, 2, buffer); } -void Tins::Dot11ManagementFrame::fh_pattern_table(uint8_t flag, +void Dot11ManagementFrame::fh_pattern_table(uint8_t flag, uint8_t number_of_sets, uint8_t modulus, uint8_t offset, @@ -510,11 +512,11 @@ void Tins::Dot11ManagementFrame::fh_pattern_table(uint8_t flag, delete[] buffer; } -void Tins::Dot11ManagementFrame::power_constraint(uint8_t local_power_constraint) { +void Dot11ManagementFrame::power_constraint(uint8_t local_power_constraint) { add_tagged_option(POWER_CONSTRAINT, 1, &local_power_constraint); } -void Tins::Dot11ManagementFrame::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { +void Dot11ManagementFrame::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { uint8_t buffer[3]; buffer[0] = switch_mode; @@ -524,7 +526,7 @@ void Tins::Dot11ManagementFrame::channel_switch(uint8_t switch_mode, uint8_t new } -void Tins::Dot11ManagementFrame::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { +void Dot11ManagementFrame::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { uint8_t buffer[6]; uint16_t* ptr_buffer = (uint16_t*)buffer; @@ -537,7 +539,7 @@ void Tins::Dot11ManagementFrame::quiet(uint8_t quiet_count, uint8_t quiet_period } -void Tins::Dot11ManagementFrame::ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const vector >& channel_map) { +void Dot11ManagementFrame::ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const vector >& channel_map) { uint8_t sz = 7 + 2 * channel_map.size(); uint8_t* buffer = new uint8_t[sz]; @@ -557,7 +559,7 @@ void Tins::Dot11ManagementFrame::ibss_dfs(const uint8_t* dfs_owner, uint8_t reco } -void Tins::Dot11ManagementFrame::tpc_report(uint8_t transmit_power, uint8_t link_margin) { +void Dot11ManagementFrame::tpc_report(uint8_t transmit_power, uint8_t link_margin) { uint8_t buffer[2]; buffer[0] = transmit_power; @@ -566,11 +568,11 @@ void Tins::Dot11ManagementFrame::tpc_report(uint8_t transmit_power, uint8_t link } -void Tins::Dot11ManagementFrame::erp_information(uint8_t value) { +void Dot11ManagementFrame::erp_information(uint8_t value) { add_tagged_option(ERP_INFORMATION, 1, &value); } -void Tins::Dot11ManagementFrame::bss_load(uint16_t station_count, uint8_t channel_utilization, uint16_t available_capacity) { +void Dot11ManagementFrame::bss_load(uint16_t station_count, uint8_t channel_utilization, uint16_t available_capacity) { uint8_t buffer[5]; buffer[0] = station_count & 0xFF; @@ -581,7 +583,7 @@ void Tins::Dot11ManagementFrame::bss_load(uint16_t station_count, uint8_t channe add_tagged_option(BSS_LOAD, 5, buffer); } -void Tins::Dot11ManagementFrame::tim(uint8_t dtim_count, +void Dot11ManagementFrame::tim(uint8_t dtim_count, uint8_t dtim_period, uint8_t bitmap_control, uint8_t* partial_virtual_bitmap, @@ -596,20 +598,20 @@ void Tins::Dot11ManagementFrame::tim(uint8_t dtim_count, add_tagged_option(TIM, sz, buffer); } -void Tins::Dot11ManagementFrame::challenge_text(uint8_t* ch_text, uint8_t ch_text_sz) { +void Dot11ManagementFrame::challenge_text(uint8_t* ch_text, uint8_t ch_text_sz) { add_tagged_option(CHALLENGE_TEXT, ch_text_sz, ch_text); } /* Dot11Beacon */ -Tins::Dot11Beacon::Dot11Beacon(const address_type &dst_hw_addr, +Dot11Beacon::Dot11Beacon(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { subtype(Dot11::BEACON); memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Beacon::Dot11Beacon(const NetworkInterface& iface, +Dot11Beacon::Dot11Beacon(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -617,7 +619,7 @@ Tins::Dot11Beacon::Dot11Beacon(const NetworkInterface& iface, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz) +Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); @@ -631,45 +633,45 @@ Tins::Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz) parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11Beacon::timestamp(uint64_t new_timestamp) { +void Dot11Beacon::timestamp(uint64_t new_timestamp) { this->_body.timestamp = new_timestamp; } -void Tins::Dot11Beacon::interval(uint16_t new_interval) { +void Dot11Beacon::interval(uint16_t new_interval) { this->_body.interval = new_interval; } -void Tins::Dot11Beacon::essid(const std::string &new_essid) { +void Dot11Beacon::essid(const std::string &new_essid) { Dot11ManagementFrame::ssid(new_essid); } -void Tins::Dot11Beacon::supported_rates(const std::list &new_rates) { +void Dot11Beacon::supported_rates(const std::list &new_rates) { Dot11ManagementFrame::supported_rates(new_rates); } -void Tins::Dot11Beacon::ds_parameter_set(uint8_t current_channel) { +void Dot11Beacon::ds_parameter_set(uint8_t current_channel) { Dot11ManagementFrame::ds_parameter_set(current_channel); } -void Tins::Dot11Beacon::fh_parameter_set(uint16_t dwell_time, +void Dot11Beacon::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index) { Dot11ManagementFrame::fh_parameter_set(dwell_time, hop_set, hop_pattern, hop_index); } -void Tins::Dot11Beacon::cf_parameter_set(uint8_t cfp_count, +void Dot11Beacon::cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining) { Dot11ManagementFrame::cf_parameter_set(cfp_count, cfp_period, cfp_max_duration, cfp_dur_remaining); } -void Tins::Dot11Beacon::ibss_parameter_set(uint16_t atim_window) { +void Dot11Beacon::ibss_parameter_set(uint16_t atim_window) { Dot11ManagementFrame::ibss_parameter_set(atim_window); } -void Tins::Dot11Beacon::tim(uint8_t dtim_count, +void Dot11Beacon::tim(uint8_t dtim_count, uint8_t dtim_period, uint8_t bitmap_control, uint8_t* partial_virtual_bitmap, @@ -677,18 +679,18 @@ void Tins::Dot11Beacon::tim(uint8_t dtim_count, Dot11ManagementFrame::tim(dtim_count, dtim_period, bitmap_control, partial_virtual_bitmap, partial_virtual_bitmap_sz); } -void Tins::Dot11Beacon::country(const std::vector& countries, +void Dot11Beacon::country(const std::vector& countries, const std::vector& first_channels, const std::vector& number_channels, const std::vector& max_power) { Dot11ManagementFrame::country(countries, first_channels, number_channels, max_power); } -void Tins::Dot11Beacon::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { +void Dot11Beacon::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { Dot11ManagementFrame::fh_parameters(prime_radix, number_channels); } -void Tins::Dot11Beacon::fh_pattern_table(uint8_t flag, +void Dot11Beacon::fh_pattern_table(uint8_t flag, uint8_t number_of_sets, uint8_t modulus, uint8_t offset, @@ -696,63 +698,63 @@ void Tins::Dot11Beacon::fh_pattern_table(uint8_t flag, Dot11ManagementFrame::fh_pattern_table(flag, number_of_sets, modulus, offset, random_table); } -void Tins::Dot11Beacon::power_constraint(uint8_t local_power_constraint) { +void Dot11Beacon::power_constraint(uint8_t local_power_constraint) { Dot11ManagementFrame::power_constraint(local_power_constraint); } -void Tins::Dot11Beacon::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { +void Dot11Beacon::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { Dot11ManagementFrame::channel_switch(switch_mode, new_channel, switch_count); } -void Tins::Dot11Beacon::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { +void Dot11Beacon::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { Dot11ManagementFrame::quiet(quiet_count, quiet_period, quiet_duration, quiet_offset); } -void Tins::Dot11Beacon::ibss_dfs(const uint8_t* dfs_owner, +void Dot11Beacon::ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const std::vector >& channel_map) { Dot11ManagementFrame::ibss_dfs(dfs_owner, recovery_interval, channel_map); } -void Tins::Dot11Beacon::tpc_report(uint8_t transmit_power, uint8_t link_margin) { +void Dot11Beacon::tpc_report(uint8_t transmit_power, uint8_t link_margin) { Dot11ManagementFrame::tpc_report(transmit_power, link_margin); } -void Tins::Dot11Beacon::erp_information(uint8_t value) { +void Dot11Beacon::erp_information(uint8_t value) { Dot11ManagementFrame::erp_information(value); } -void Tins::Dot11Beacon::extended_supported_rates(const std::list &new_rates) { +void Dot11Beacon::extended_supported_rates(const std::list &new_rates) { Dot11ManagementFrame::extended_supported_rates(new_rates); } -void Tins::Dot11Beacon::rsn_information(const RSNInformation& info) { +void Dot11Beacon::rsn_information(const RSNInformation& info) { Dot11ManagementFrame::rsn_information(info); } -void Tins::Dot11Beacon::bss_load(uint16_t station_count, +void Dot11Beacon::bss_load(uint16_t station_count, uint8_t channel_utilization, uint16_t available_capacity) { Dot11ManagementFrame::bss_load(station_count, channel_utilization, available_capacity); } -void Tins::Dot11Beacon::edca_parameter_set(uint32_t ac_be, +void Dot11Beacon::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); } -void Tins::Dot11Beacon::qos_capabilities(uint8_t qos_info) { +void Dot11Beacon::qos_capabilities(uint8_t qos_info) { Dot11ManagementFrame::qos_capabilities(qos_info); } -string Tins::Dot11Beacon::essid() const { +string Dot11Beacon::essid() const { const Dot11::Dot11Option *option = search_option(SSID); return (option) ? string((const char*)option->value, option->length) : 0; } -bool Tins::Dot11Beacon::rsn_information(RSNInformation *rsn) { +bool Dot11Beacon::rsn_information(RSNInformation *rsn) { const Dot11::Dot11Option *option = search_option(RSN); if(!option || option->length < (sizeof(uint16_t) << 1) + sizeof(uint32_t)) return false; @@ -793,18 +795,18 @@ bool Tins::Dot11Beacon::rsn_information(RSNInformation *rsn) { return true; } -uint32_t Tins::Dot11Beacon::header_size() const { +uint32_t Dot11Beacon::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(_body); } -uint32_t Tins::Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(_body); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; } -Tins::PDU *Tins::Dot11Beacon::clone_pdu() const { +PDU *Dot11Beacon::clone_pdu() const { Dot11Beacon *new_pdu = new Dot11Beacon(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -814,21 +816,21 @@ Tins::PDU *Tins::Dot11Beacon::clone_pdu() const { /* Diassoc */ -Tins::Dot11Disassoc::Dot11Disassoc(const address_type &dst_hw_addr, +Dot11Disassoc::Dot11Disassoc(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { subtype(Dot11::DISASSOC); memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Disassoc::Dot11Disassoc(const NetworkInterface& iface, +Dot11Disassoc::Dot11Disassoc(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr){ this->subtype(Dot11::DISASSOC); memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Disassoc::Dot11Disassoc(const uint8_t *buffer, uint32_t total_sz) { +Dot11Disassoc::Dot11Disassoc(const uint8_t *buffer, uint32_t total_sz) { uint32_t sz = management_frame_size(); buffer += sz; total_sz -= sz; @@ -840,22 +842,22 @@ Tins::Dot11Disassoc::Dot11Disassoc(const uint8_t *buffer, uint32_t total_sz) { parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11Disassoc::reason_code(uint16_t new_reason_code) { +void Dot11Disassoc::reason_code(uint16_t new_reason_code) { this->_body.reason_code = new_reason_code; } -uint32_t Tins::Dot11Disassoc::header_size() const { +uint32_t Dot11Disassoc::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(DisassocBody); } -uint32_t Tins::Dot11Disassoc::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11Disassoc::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(DisassocBody); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; } -Tins::PDU *Tins::Dot11Disassoc::clone_pdu() const { +PDU *Dot11Disassoc::clone_pdu() const { Dot11Disassoc *new_pdu = new Dot11Disassoc(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -865,7 +867,7 @@ Tins::PDU *Tins::Dot11Disassoc::clone_pdu() const { /* Assoc request. */ -Tins::Dot11AssocRequest::Dot11AssocRequest(const address_type &dst_hw_addr, +Dot11AssocRequest::Dot11AssocRequest(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { @@ -873,7 +875,7 @@ Tins::Dot11AssocRequest::Dot11AssocRequest(const address_type &dst_hw_addr, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11AssocRequest::Dot11AssocRequest(const NetworkInterface& iface, +Dot11AssocRequest::Dot11AssocRequest(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -881,7 +883,7 @@ Tins::Dot11AssocRequest::Dot11AssocRequest(const NetworkInterface& iface, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11AssocRequest::Dot11AssocRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { +Dot11AssocRequest::Dot11AssocRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); buffer += sz; total_sz -= sz; @@ -893,50 +895,50 @@ Tins::Dot11AssocRequest::Dot11AssocRequest(const uint8_t *buffer, uint32_t total parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11AssocRequest::listen_interval(uint16_t new_listen_interval) { +void Dot11AssocRequest::listen_interval(uint16_t new_listen_interval) { this->_body.listen_interval = new_listen_interval; } -void Tins::Dot11AssocRequest::ssid(const std::string &new_ssid) { +void Dot11AssocRequest::ssid(const std::string &new_ssid) { Dot11ManagementFrame::ssid(new_ssid); } -void Tins::Dot11AssocRequest::supported_rates(const std::list &new_rates) { +void Dot11AssocRequest::supported_rates(const std::list &new_rates) { Dot11ManagementFrame::supported_rates(new_rates); } -void Tins::Dot11AssocRequest::extended_supported_rates(const std::list &new_rates) { +void Dot11AssocRequest::extended_supported_rates(const std::list &new_rates) { Dot11ManagementFrame::extended_supported_rates(new_rates); } -void Tins::Dot11AssocRequest::power_capabilities(uint8_t min_power, uint8_t max_power) { +void Dot11AssocRequest::power_capabilities(uint8_t min_power, uint8_t max_power) { Dot11ManagementFrame::power_capabilities(min_power, max_power); } -void Tins::Dot11AssocRequest::supported_channels(const std::list > &new_channels) { +void Dot11AssocRequest::supported_channels(const std::list > &new_channels) { Dot11ManagementFrame::supported_channels(new_channels); } -void Tins::Dot11AssocRequest::rsn_information(const RSNInformation& info) { +void Dot11AssocRequest::rsn_information(const RSNInformation& info) { Dot11ManagementFrame::rsn_information(info); } -void Tins::Dot11AssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { +void Dot11AssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { Dot11ManagementFrame::qos_capabilities(new_qos_capabilities); } -uint32_t Tins::Dot11AssocRequest::header_size() const { +uint32_t Dot11AssocRequest::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(AssocReqBody); } -uint32_t Tins::Dot11AssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11AssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(AssocReqBody); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; } -Tins::PDU *Tins::Dot11AssocRequest::clone_pdu() const { +PDU *Dot11AssocRequest::clone_pdu() const { Dot11AssocRequest *new_pdu = new Dot11AssocRequest(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -946,7 +948,7 @@ Tins::PDU *Tins::Dot11AssocRequest::clone_pdu() const { /* Assoc response. */ -Tins::Dot11AssocResponse::Dot11AssocResponse(const address_type &dst_hw_addr, +Dot11AssocResponse::Dot11AssocResponse(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { @@ -954,7 +956,7 @@ Tins::Dot11AssocResponse::Dot11AssocResponse(const address_type &dst_hw_addr, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11AssocResponse::Dot11AssocResponse(const NetworkInterface& iface, +Dot11AssocResponse::Dot11AssocResponse(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -962,7 +964,7 @@ Tins::Dot11AssocResponse::Dot11AssocResponse(const NetworkInterface& iface, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11AssocResponse::Dot11AssocResponse(const uint8_t *buffer, uint32_t total_sz) +Dot11AssocResponse::Dot11AssocResponse(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); @@ -976,38 +978,38 @@ Tins::Dot11AssocResponse::Dot11AssocResponse(const uint8_t *buffer, uint32_t tot parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11AssocResponse::status_code(uint16_t new_status_code) { +void Dot11AssocResponse::status_code(uint16_t new_status_code) { this->_body.status_code = new_status_code; } -void Tins::Dot11AssocResponse::aid(uint16_t new_aid) { +void Dot11AssocResponse::aid(uint16_t new_aid) { this->_body.aid = new_aid; } -void Tins::Dot11AssocResponse::supported_rates(const std::list &new_rates) { +void Dot11AssocResponse::supported_rates(const std::list &new_rates) { Dot11ManagementFrame::supported_rates(new_rates); } -void Tins::Dot11AssocResponse::extended_supported_rates(const std::list &new_rates) { +void Dot11AssocResponse::extended_supported_rates(const std::list &new_rates) { Dot11ManagementFrame::extended_supported_rates(new_rates); } -void Tins::Dot11AssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { +void Dot11AssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); } -uint32_t Tins::Dot11AssocResponse::header_size() const { +uint32_t Dot11AssocResponse::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(AssocRespBody); } -uint32_t Tins::Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(AssocRespBody); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; } -Tins::PDU *Tins::Dot11AssocResponse::clone_pdu() const { +PDU *Dot11AssocResponse::clone_pdu() const { Dot11AssocResponse *new_pdu = new Dot11AssocResponse(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -1017,7 +1019,7 @@ Tins::PDU *Tins::Dot11AssocResponse::clone_pdu() const { /* ReAssoc request. */ -Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const address_type &dst_hw_addr, +Dot11ReAssocRequest::Dot11ReAssocRequest(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { @@ -1025,7 +1027,7 @@ Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const address_type &dst_hw_addr, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const NetworkInterface& iface, +Dot11ReAssocRequest::Dot11ReAssocRequest(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -1033,7 +1035,7 @@ Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const NetworkInterface& iface, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t *buffer, uint32_t total_sz) +Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); @@ -1047,54 +1049,54 @@ Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t *buffer, uint32_t t parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11ReAssocRequest::listen_interval(uint16_t new_listen_interval) { +void Dot11ReAssocRequest::listen_interval(uint16_t new_listen_interval) { this->_body.listen_interval = new_listen_interval; } -void Tins::Dot11ReAssocRequest::current_ap(uint8_t* new_current_ap) { +void Dot11ReAssocRequest::current_ap(uint8_t* new_current_ap) { memcpy(this->_body.current_ap, new_current_ap, 6); } -void Tins::Dot11ReAssocRequest::ssid(const std::string &new_ssid) { +void Dot11ReAssocRequest::ssid(const std::string &new_ssid) { Dot11ManagementFrame::ssid(new_ssid); } -void Tins::Dot11ReAssocRequest::supported_rates(const std::list &new_rates) { +void Dot11ReAssocRequest::supported_rates(const std::list &new_rates) { Dot11ManagementFrame::supported_rates(new_rates); } -void Tins::Dot11ReAssocRequest::extended_supported_rates(const std::list &new_rates) { +void Dot11ReAssocRequest::extended_supported_rates(const std::list &new_rates) { Dot11ManagementFrame::extended_supported_rates(new_rates); } -void Tins::Dot11ReAssocRequest::power_capabilities(uint8_t min_power, uint8_t max_power) { +void Dot11ReAssocRequest::power_capabilities(uint8_t min_power, uint8_t max_power) { Dot11ManagementFrame::power_capabilities(min_power, max_power); } -void Tins::Dot11ReAssocRequest::supported_channels(const std::list > &new_channels) { +void Dot11ReAssocRequest::supported_channels(const std::list > &new_channels) { Dot11ManagementFrame::supported_channels(new_channels); } -void Tins::Dot11ReAssocRequest::rsn_information(const RSNInformation& info) { +void Dot11ReAssocRequest::rsn_information(const RSNInformation& info) { Dot11ManagementFrame::rsn_information(info); } -void Tins::Dot11ReAssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { +void Dot11ReAssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { Dot11ManagementFrame::qos_capabilities(new_qos_capabilities); } -uint32_t Tins::Dot11ReAssocRequest::header_size() const { +uint32_t Dot11ReAssocRequest::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } -uint32_t Tins::Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(this->_body); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; } -Tins::PDU *Tins::Dot11ReAssocRequest::clone_pdu() const { +PDU *Dot11ReAssocRequest::clone_pdu() const { Dot11ReAssocRequest *new_pdu = new Dot11ReAssocRequest(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -1104,7 +1106,7 @@ Tins::PDU *Tins::Dot11ReAssocRequest::clone_pdu() const { /* ReAssoc response. */ -Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const address_type &dst_hw_addr, +Dot11ReAssocResponse::Dot11ReAssocResponse(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { @@ -1112,7 +1114,7 @@ Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const address_type &dst_hw_addr memset(&_body, 0, sizeof(_body)); } -Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const NetworkInterface& iface, +Dot11ReAssocResponse::Dot11ReAssocResponse(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -1120,7 +1122,7 @@ Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const NetworkInterface& iface, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t *buffer, uint32_t total_sz) +Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); buffer += sz; @@ -1133,38 +1135,38 @@ Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t *buffer, uint32_t parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11ReAssocResponse::status_code(uint16_t new_status_code) { +void Dot11ReAssocResponse::status_code(uint16_t new_status_code) { this->_body.status_code = new_status_code; } -void Tins::Dot11ReAssocResponse::aid(uint16_t new_aid) { +void Dot11ReAssocResponse::aid(uint16_t new_aid) { this->_body.aid = new_aid; } -void Tins::Dot11ReAssocResponse::supported_rates(const std::list &new_rates) { +void Dot11ReAssocResponse::supported_rates(const std::list &new_rates) { Dot11ManagementFrame::supported_rates(new_rates); } -void Tins::Dot11ReAssocResponse::extended_supported_rates(const std::list &new_rates) { +void Dot11ReAssocResponse::extended_supported_rates(const std::list &new_rates) { Dot11ManagementFrame::extended_supported_rates(new_rates); } -void Tins::Dot11ReAssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { +void Dot11ReAssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); } -uint32_t Tins::Dot11ReAssocResponse::header_size() const { +uint32_t Dot11ReAssocResponse::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } -uint32_t Tins::Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(this->_body); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; } -Tins::PDU *Tins::Dot11ReAssocResponse::clone_pdu() const { +PDU *Dot11ReAssocResponse::clone_pdu() const { Dot11ReAssocResponse *new_pdu = new Dot11ReAssocResponse(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -1174,43 +1176,43 @@ Tins::PDU *Tins::Dot11ReAssocResponse::clone_pdu() const { /* Probe Request */ -Tins::Dot11ProbeRequest::Dot11ProbeRequest(const address_type &dst_hw_addr, +Dot11ProbeRequest::Dot11ProbeRequest(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { this->subtype(Dot11::PROBE_REQ); } -Tins::Dot11ProbeRequest::Dot11ProbeRequest(const NetworkInterface& iface, +Dot11ProbeRequest::Dot11ProbeRequest(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { this->subtype(Dot11::PROBE_REQ); } -Tins::Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz) +Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11ProbeRequest::ssid(const std::string &new_ssid) { +void Dot11ProbeRequest::ssid(const std::string &new_ssid) { Dot11ManagementFrame::ssid(new_ssid); } -void Tins::Dot11ProbeRequest::supported_rates(const std::list &new_rates) { +void Dot11ProbeRequest::supported_rates(const std::list &new_rates) { Dot11ManagementFrame::supported_rates(new_rates); } -void Tins::Dot11ProbeRequest::request_information(const std::list elements) { +void Dot11ProbeRequest::request_information(const std::list elements) { Dot11ManagementFrame::request_information(elements); } -void Tins::Dot11ProbeRequest::extended_supported_rates(const std::list &new_rates) { +void Dot11ProbeRequest::extended_supported_rates(const std::list &new_rates) { Dot11ManagementFrame::extended_supported_rates(new_rates); } -Tins::PDU* Tins::Dot11ProbeRequest::clone_pdu() const { +PDU* Dot11ProbeRequest::clone_pdu() const { Dot11ProbeRequest* new_pdu = new Dot11ProbeRequest(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -1219,7 +1221,7 @@ Tins::PDU* Tins::Dot11ProbeRequest::clone_pdu() const { /* Probe Response */ -Tins::Dot11ProbeResponse::Dot11ProbeResponse(const address_type &dst_hw_addr, +Dot11ProbeResponse::Dot11ProbeResponse(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { @@ -1227,7 +1229,7 @@ Tins::Dot11ProbeResponse::Dot11ProbeResponse(const address_type &dst_hw_addr, memset(&this->_body, 0, sizeof(this->_body)); } -Tins::Dot11ProbeResponse::Dot11ProbeResponse(const NetworkInterface& iface, +Dot11ProbeResponse::Dot11ProbeResponse(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -1235,7 +1237,7 @@ Tins::Dot11ProbeResponse::Dot11ProbeResponse(const NetworkInterface& iface, memset(&this->_body, 0, sizeof(this->_body)); } -Tins::Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz) +Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); @@ -1249,50 +1251,50 @@ Tins::Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t tot parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11ProbeResponse::timestamp(uint64_t new_timestamp) { +void Dot11ProbeResponse::timestamp(uint64_t new_timestamp) { this->_body.timestamp = new_timestamp; } -void Tins::Dot11ProbeResponse::interval(uint16_t new_interval) { +void Dot11ProbeResponse::interval(uint16_t new_interval) { this->_body.interval = new_interval; } -void Tins::Dot11ProbeResponse::ssid(const std::string &new_ssid) { +void Dot11ProbeResponse::ssid(const std::string &new_ssid) { Dot11ManagementFrame::ssid(new_ssid); } -void Tins::Dot11ProbeResponse::supported_rates(const std::list &new_rates) { +void Dot11ProbeResponse::supported_rates(const std::list &new_rates) { Dot11ManagementFrame::supported_rates(new_rates); } -void Tins::Dot11ProbeResponse::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index) { +void Dot11ProbeResponse::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index) { Dot11ManagementFrame::fh_parameter_set(dwell_time, hop_set, hop_pattern, hop_index); } -void Tins::Dot11ProbeResponse::ds_parameter_set(uint8_t current_channel) { +void Dot11ProbeResponse::ds_parameter_set(uint8_t current_channel) { Dot11ManagementFrame::ds_parameter_set(current_channel); } -void Tins::Dot11ProbeResponse::cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining) { +void Dot11ProbeResponse::cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining) { Dot11ManagementFrame::cf_parameter_set(cfp_count, cfp_period, cfp_max_duration, cfp_dur_remaining); } -void Tins::Dot11ProbeResponse::ibss_parameter_set(uint16_t atim_window) { +void Dot11ProbeResponse::ibss_parameter_set(uint16_t atim_window) { Dot11ManagementFrame::ibss_parameter_set(atim_window); } -void Tins::Dot11ProbeResponse::country(const std::vector& countries, +void Dot11ProbeResponse::country(const std::vector& countries, const std::vector& first_channels, const std::vector& number_channels, const std::vector& max_power) { Dot11ManagementFrame::country(countries, first_channels, number_channels, max_power); } -void Tins::Dot11ProbeResponse::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { +void Dot11ProbeResponse::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { Dot11ManagementFrame::fh_parameters(prime_radix, number_channels); } -void Tins::Dot11ProbeResponse::fh_pattern_table(uint8_t flag, +void Dot11ProbeResponse::fh_pattern_table(uint8_t flag, uint8_t number_of_sets, uint8_t modulus, uint8_t offset, @@ -1300,58 +1302,58 @@ void Tins::Dot11ProbeResponse::fh_pattern_table(uint8_t flag, Dot11ManagementFrame::fh_pattern_table(flag, number_of_sets, modulus, offset, random_table); } -void Tins::Dot11ProbeResponse::power_constraint(uint8_t local_power_constraint) { +void Dot11ProbeResponse::power_constraint(uint8_t local_power_constraint) { Dot11ManagementFrame::power_constraint(local_power_constraint); } -void Tins::Dot11ProbeResponse::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { +void Dot11ProbeResponse::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { Dot11ManagementFrame::channel_switch(switch_mode, new_channel, switch_count); } -void Tins::Dot11ProbeResponse::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { +void Dot11ProbeResponse::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { Dot11ManagementFrame::quiet(quiet_count, quiet_period, quiet_duration, quiet_offset); } -void Tins::Dot11ProbeResponse::ibss_dfs(const uint8_t* dfs_owner, +void Dot11ProbeResponse::ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const std::vector >& channel_map) { Dot11ManagementFrame::ibss_dfs(dfs_owner, recovery_interval, channel_map); } -void Tins::Dot11ProbeResponse::tpc_report(uint8_t transmit_power, uint8_t link_margin) { +void Dot11ProbeResponse::tpc_report(uint8_t transmit_power, uint8_t link_margin) { Dot11ManagementFrame::tpc_report(transmit_power, link_margin); } -void Tins::Dot11ProbeResponse::erp_information(uint8_t value) { +void Dot11ProbeResponse::erp_information(uint8_t value) { Dot11ManagementFrame::erp_information(value); } -void Tins::Dot11ProbeResponse::extended_supported_rates(const std::list &new_rates) { +void Dot11ProbeResponse::extended_supported_rates(const std::list &new_rates) { Dot11ManagementFrame::extended_supported_rates(new_rates); } -void Tins::Dot11ProbeResponse::rsn_information(const RSNInformation& info) { +void Dot11ProbeResponse::rsn_information(const RSNInformation& info) { Dot11ManagementFrame::rsn_information(info); } -void Tins::Dot11ProbeResponse::bss_load(uint16_t station_count, +void Dot11ProbeResponse::bss_load(uint16_t station_count, uint8_t channel_utilization, uint16_t available_capacity) { Dot11ManagementFrame::bss_load(station_count, channel_utilization, available_capacity); } -void Tins::Dot11ProbeResponse::edca_parameter_set(uint32_t ac_be, +void Dot11ProbeResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); } -uint32_t Tins::Dot11ProbeResponse::header_size() const { +uint32_t Dot11ProbeResponse::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } -Tins::PDU* Tins::Dot11ProbeResponse::clone_pdu() const { +PDU* Dot11ProbeResponse::clone_pdu() const { Dot11ProbeResponse* new_pdu = new Dot11ProbeResponse(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -1359,7 +1361,7 @@ Tins::PDU* Tins::Dot11ProbeResponse::clone_pdu() const { return new_pdu; } -uint32_t Tins::Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(this->_body); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); @@ -1368,7 +1370,7 @@ uint32_t Tins::Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint3 /* Auth */ -Tins::Dot11Authentication::Dot11Authentication(const address_type &dst_hw_addr, +Dot11Authentication::Dot11Authentication(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { @@ -1376,7 +1378,7 @@ Tins::Dot11Authentication::Dot11Authentication(const address_type &dst_hw_addr, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Authentication::Dot11Authentication(const NetworkInterface& iface, +Dot11Authentication::Dot11Authentication(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -1384,7 +1386,7 @@ Tins::Dot11Authentication::Dot11Authentication(const NetworkInterface& iface, memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t total_sz) +Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); @@ -1398,27 +1400,27 @@ Tins::Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t t parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11Authentication::auth_algorithm(uint16_t new_auth_algorithm) { +void Dot11Authentication::auth_algorithm(uint16_t new_auth_algorithm) { this->_body.auth_algorithm = new_auth_algorithm; } -void Tins::Dot11Authentication::auth_seq_number(uint16_t new_auth_seq_number) { +void Dot11Authentication::auth_seq_number(uint16_t new_auth_seq_number) { this->_body.auth_seq_number = new_auth_seq_number; } -void Tins::Dot11Authentication::status_code(uint16_t new_status_code) { +void Dot11Authentication::status_code(uint16_t new_status_code) { this->_body.status_code = new_status_code; } -void Tins::Dot11Authentication::challenge_text(uint8_t* ch_text, uint8_t ch_text_sz) { +void Dot11Authentication::challenge_text(uint8_t* ch_text, uint8_t ch_text_sz) { Dot11ManagementFrame::challenge_text(ch_text, ch_text_sz); } -uint32_t Tins::Dot11Authentication::header_size() const { +uint32_t Dot11Authentication::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } -Tins::PDU* Tins::Dot11Authentication::clone_pdu() const { +PDU* Dot11Authentication::clone_pdu() const { Dot11Authentication *new_pdu = new Dot11Authentication(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -1426,7 +1428,7 @@ Tins::PDU* Tins::Dot11Authentication::clone_pdu() const { return new_pdu; } -uint32_t Tins::Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(this->_body); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); @@ -1435,7 +1437,7 @@ uint32_t Tins::Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint /* Deauth */ -Tins::Dot11Deauthentication::Dot11Deauthentication(const address_type &dst_hw_addr, +Dot11Deauthentication::Dot11Deauthentication(const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { @@ -1443,7 +1445,7 @@ Tins::Dot11Deauthentication::Dot11Deauthentication(const address_type &dst_hw_ad memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Deauthentication::Dot11Deauthentication(const NetworkInterface& iface, +Dot11Deauthentication::Dot11Deauthentication(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { @@ -1451,7 +1453,7 @@ Tins::Dot11Deauthentication::Dot11Deauthentication(const NetworkInterface& iface memset(&_body, 0, sizeof(_body)); } -Tins::Dot11Deauthentication::Dot11Deauthentication(const uint8_t *buffer, uint32_t total_sz) +Dot11Deauthentication::Dot11Deauthentication(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { uint32_t sz = management_frame_size(); buffer += sz; @@ -1464,22 +1466,22 @@ Tins::Dot11Deauthentication::Dot11Deauthentication(const uint8_t *buffer, uint32 parse_tagged_parameters(buffer, total_sz); } -void Tins::Dot11Deauthentication::reason_code(uint16_t new_reason_code) { +void Dot11Deauthentication::reason_code(uint16_t new_reason_code) { this->_body.reason_code = new_reason_code; } -uint32_t Tins::Dot11Deauthentication::header_size() const { +uint32_t Dot11Deauthentication::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } -uint32_t Tins::Dot11Deauthentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11Deauthentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(this->_body); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; } -Tins::PDU *Tins::Dot11Deauthentication::clone_pdu() const { +PDU *Dot11Deauthentication::clone_pdu() const { Dot11Deauthentication *new_pdu = new Dot11Deauthentication(); new_pdu->copy_80211_fields(this); new_pdu->copy_ext_header(this); @@ -1489,7 +1491,7 @@ Tins::PDU *Tins::Dot11Deauthentication::clone_pdu() const { /* Dot11Data */ -Tins::Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz) +Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) { uint32_t sz = Dot11::header_size(); buffer += sz; @@ -1510,7 +1512,7 @@ Tins::Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz) inner_pdu(new Tins::SNAP(buffer, total_sz)); } -Tins::Dot11Data::Dot11Data(const address_type &dst_hw_addr, +Dot11Data::Dot11Data(const address_type &dst_hw_addr, const address_type &src_hw_addr, PDU* child) : Dot11(dst_hw_addr, child) { @@ -1519,7 +1521,7 @@ Tins::Dot11Data::Dot11Data(const address_type &dst_hw_addr, } -Tins::Dot11Data::Dot11Data(const NetworkInterface &iface, +Dot11Data::Dot11Data(const NetworkInterface &iface, const address_type &dst_hw_addr, const address_type &src_hw_addr, PDU* child) : Dot11(iface, dst_hw_addr, child) @@ -1528,40 +1530,40 @@ Tins::Dot11Data::Dot11Data(const NetworkInterface &iface, addr2(src_hw_addr); } -void Tins::Dot11Data::copy_ext_header(const Dot11Data* other) { +void Dot11Data::copy_ext_header(const Dot11Data* other) { Dot11::copy_80211_fields(other); std::memcpy(&this->_ext_header, &other->_ext_header, sizeof(this->_ext_header)); std::memcpy(this->_addr4, other->_addr4, 6); } -uint32_t Tins::Dot11Data::header_size() const { +uint32_t Dot11Data::header_size() const { uint32_t sz = Dot11::header_size() + sizeof(_ext_header); if (this->from_ds() && this->to_ds()) sz += 6; return sz; } -void Tins::Dot11Data::addr2(const address_type &new_addr2) { +void Dot11Data::addr2(const address_type &new_addr2) { std::copy(new_addr2.begin(), new_addr2.end(), _ext_header.addr2); } -void Tins::Dot11Data::addr3(const address_type &new_addr3) { +void Dot11Data::addr3(const address_type &new_addr3) { std::copy(new_addr3.begin(), new_addr3.end(), _ext_header.addr3); } -void Tins::Dot11Data::frag_num(uint8_t new_frag_num) { +void Dot11Data::frag_num(uint8_t new_frag_num) { this->_ext_header.seq_control.frag_number = new_frag_num; } -void Tins::Dot11Data::seq_num(uint16_t new_seq_num) { +void Dot11Data::seq_num(uint16_t new_seq_num) { this->_ext_header.seq_control.seq_number = new_seq_num; } -void Tins::Dot11Data::addr4(const uint8_t* new_addr4) { +void Dot11Data::addr4(const uint8_t* new_addr4) { memcpy(this->_addr4, new_addr4, 6); } -uint32_t Tins::Dot11Data::write_ext_header(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11Data::write_ext_header(uint8_t *buffer, uint32_t total_sz) { uint32_t written = sizeof(this->_ext_header); memcpy(buffer, &this->_ext_header, sizeof(this->_ext_header)); buffer += sizeof(this->_ext_header); @@ -1573,7 +1575,7 @@ uint32_t Tins::Dot11Data::write_ext_header(uint8_t *buffer, uint32_t total_sz) { } -Tins::PDU *Tins::Dot11Data::clone_pdu() const { +PDU *Dot11Data::clone_pdu() const { Dot11Data *new_pdu = new Dot11Data(); new_pdu->copy_80211_fields(this); return new_pdu; @@ -1581,14 +1583,14 @@ Tins::PDU *Tins::Dot11Data::clone_pdu() const { /* QoS data. */ -Tins::Dot11QoSData::Dot11QoSData(const address_type &dst_hw_addr, +Dot11QoSData::Dot11QoSData(const address_type &dst_hw_addr, const address_type &src_hw_addr, PDU* child) : Dot11Data(dst_hw_addr, src_hw_addr, child) { } -Tins::Dot11QoSData::Dot11QoSData(const NetworkInterface &iface, +Dot11QoSData::Dot11QoSData(const NetworkInterface &iface, const address_type &dst_hw_addr, const address_type &src_hw_addr, PDU* child) : Dot11Data(iface, dst_hw_addr, src_hw_addr, child) @@ -1597,7 +1599,7 @@ Tins::Dot11QoSData::Dot11QoSData(const NetworkInterface &iface, this->_qos_control = 0; } -Tins::Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) +Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) : Dot11Data(buffer, std::min(data_frame_size(), total_sz)) { uint32_t sz = data_frame_size(); buffer += sz; @@ -1611,37 +1613,37 @@ Tins::Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) inner_pdu(new Tins::SNAP(buffer, total_sz)); } -Tins::Dot11QoSData::Dot11QoSData(const Dot11QoSData &other) : Dot11Data(other) { +Dot11QoSData::Dot11QoSData(const Dot11QoSData &other) : Dot11Data(other) { copy_fields(&other); } -Tins::Dot11QoSData &Tins::Dot11QoSData::operator= (const Dot11QoSData &other) { +Dot11QoSData &Dot11QoSData::operator= (const Dot11QoSData &other) { copy_inner_pdu(other); copy_fields(&other); return *this; } -void Tins::Dot11QoSData::copy_fields(const Dot11QoSData *other) { +void Dot11QoSData::copy_fields(const Dot11QoSData *other) { Dot11Data::copy_ext_header(other); _qos_control = other->_qos_control; } -void Tins::Dot11QoSData::qos_control(uint16_t new_qos_control) { +void Dot11QoSData::qos_control(uint16_t new_qos_control) { this->_qos_control = new_qos_control; } -uint32_t Tins::Dot11QoSData::header_size() const { +uint32_t Dot11QoSData::header_size() const { return Dot11::header_size() + sizeof(this->_qos_control); } -uint32_t Tins::Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(this->_qos_control); assert(sz <= total_sz); *(uint16_t*)buffer = this->_qos_control; return sz; } -Tins::PDU *Tins::Dot11QoSData::clone_pdu() const { +PDU *Dot11QoSData::clone_pdu() const { Dot11QoSData *new_pdu = new Dot11QoSData(); new_pdu->copy_80211_fields(this); return new_pdu; @@ -1649,40 +1651,40 @@ Tins::PDU *Tins::Dot11QoSData::clone_pdu() const { /* Dot11Control */ -Tins::Dot11Control::Dot11Control(const address_type &dst_addr, PDU* child) +Dot11Control::Dot11Control(const address_type &dst_addr, PDU* child) : Dot11(dst_addr, child) { type(CONTROL); } -Tins::Dot11Control::Dot11Control(const NetworkInterface &iface, +Dot11Control::Dot11Control(const NetworkInterface &iface, const address_type &dst_addr, PDU* child) : Dot11(iface, dst_addr, child) { type(CONTROL); } -Tins::Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz) +Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) { } /* Dot11ControlTA */ -Tins::Dot11ControlTA::Dot11ControlTA(const address_type &dst_addr, +Dot11ControlTA::Dot11ControlTA(const address_type &dst_addr, const address_type &target_address, PDU* child) : Dot11Control(dst_addr, child) { target_addr(target_address); } -Tins::Dot11ControlTA::Dot11ControlTA(const NetworkInterface &iface, +Dot11ControlTA::Dot11ControlTA(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_address, PDU* child) : Dot11Control(iface, dst_addr, child) { target_addr(target_address); } -Tins::Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) { +Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) { buffer += sizeof(ieee80211_header); total_sz -= sizeof(ieee80211_header); if(total_sz < sizeof(_taddr)) @@ -1690,41 +1692,41 @@ Tins::Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : std::memcpy(_taddr, buffer, sizeof(_taddr)); } -uint32_t Tins::Dot11ControlTA::header_size() const { +uint32_t Dot11ControlTA::header_size() const { return Dot11::header_size() + sizeof(_taddr); } -uint32_t Tins::Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_sz) { assert(total_sz >= sizeof(_taddr)); std::memcpy(buffer, _taddr, sizeof(_taddr)); return sizeof(_taddr); } -void Tins::Dot11ControlTA::target_addr(const address_type &addr) { +void Dot11ControlTA::target_addr(const address_type &addr) { std::copy(addr.begin(), addr.end(), _taddr); } /* Dot11RTS */ -Tins::Dot11RTS::Dot11RTS(const address_type &dst_addr , +Dot11RTS::Dot11RTS(const address_type &dst_addr , const address_type &target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) { subtype(RTS); } -Tins::Dot11RTS::Dot11RTS(const NetworkInterface &iface, const address_type &dst_addr, +Dot11RTS::Dot11RTS(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) { subtype(RTS); } -Tins::Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz) +Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { } -Tins::PDU *Tins::Dot11RTS::clone_pdu() const { +PDU *Dot11RTS::clone_pdu() const { Dot11RTS *new_pdu = new Dot11RTS(); new_pdu->copy_80211_fields(this); return new_pdu; @@ -1732,26 +1734,26 @@ Tins::PDU *Tins::Dot11RTS::clone_pdu() const { /* Dot11PSPoll */ -Tins::Dot11PSPoll::Dot11PSPoll(const address_type &dst_addr, +Dot11PSPoll::Dot11PSPoll(const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) { subtype(PS); } -Tins::Dot11PSPoll::Dot11PSPoll(const NetworkInterface &iface, +Dot11PSPoll::Dot11PSPoll(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) { subtype(PS); } -Tins::Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz) +Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { } -Tins::PDU *Tins::Dot11PSPoll::clone_pdu() const { +PDU *Dot11PSPoll::clone_pdu() const { Dot11PSPoll *new_pdu = new Dot11PSPoll(); new_pdu->copy_80211_fields(this); return new_pdu; @@ -1759,26 +1761,26 @@ Tins::PDU *Tins::Dot11PSPoll::clone_pdu() const { /* Dot11CFEnd */ -Tins::Dot11CFEnd::Dot11CFEnd(const address_type &dst_addr, +Dot11CFEnd::Dot11CFEnd(const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) { subtype(CF_END); } -Tins::Dot11CFEnd::Dot11CFEnd(const NetworkInterface &iface, +Dot11CFEnd::Dot11CFEnd(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) { subtype(CF_END); } -Tins::Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz) +Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { } -Tins::PDU *Tins::Dot11CFEnd::clone_pdu() const { +PDU *Dot11CFEnd::clone_pdu() const { Dot11CFEnd *new_pdu = new Dot11CFEnd(); new_pdu->copy_80211_fields(this); return new_pdu; @@ -1786,26 +1788,26 @@ Tins::PDU *Tins::Dot11CFEnd::clone_pdu() const { /* Dot11EndCFAck */ -Tins::Dot11EndCFAck::Dot11EndCFAck(const address_type &dst_addr, +Dot11EndCFAck::Dot11EndCFAck(const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) { subtype(CF_END_ACK); } -Tins::Dot11EndCFAck::Dot11EndCFAck(const NetworkInterface &iface, +Dot11EndCFAck::Dot11EndCFAck(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) { subtype(CF_END_ACK); } -Tins::Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz) +Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { } -Tins::PDU *Tins::Dot11EndCFAck::clone_pdu() const { +PDU *Dot11EndCFAck::clone_pdu() const { Dot11EndCFAck *new_pdu = new Dot11EndCFAck(); new_pdu->copy_80211_fields(this); return new_pdu; @@ -1813,24 +1815,24 @@ Tins::PDU *Tins::Dot11EndCFAck::clone_pdu() const { /* Dot11Ack */ -Tins::Dot11Ack::Dot11Ack(const address_type &dst_addr, PDU* child) +Dot11Ack::Dot11Ack(const address_type &dst_addr, PDU* child) : Dot11Control(dst_addr, child) { subtype(ACK); } -Tins::Dot11Ack::Dot11Ack(const NetworkInterface &iface, +Dot11Ack::Dot11Ack(const NetworkInterface &iface, const address_type &dst_addr, PDU* child) : Dot11Control(iface, dst_addr, child) { subtype(ACK); } -Tins::Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) { +Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) { } -Tins::PDU *Tins::Dot11Ack::clone_pdu() const { +PDU *Dot11Ack::clone_pdu() const { Dot11Ack *ack = new Dot11Ack(); ack->copy_80211_fields(this); return ack; @@ -1838,21 +1840,21 @@ Tins::PDU *Tins::Dot11Ack::clone_pdu() const { /* Dot11BlockAck */ -Tins::Dot11BlockAckRequest::Dot11BlockAckRequest( +Dot11BlockAckRequest::Dot11BlockAckRequest( const address_type &dst_addr , const address_type &target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) { init_block_ack(); } -Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const NetworkInterface &iface, +Dot11BlockAckRequest::Dot11BlockAckRequest(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) { init_block_ack(); } -Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { +Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { uint32_t padding = controlta_size(); buffer += padding; total_sz -= padding; @@ -1863,13 +1865,13 @@ Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t std::memcpy(&_start_sequence, buffer, sizeof(_start_sequence)); } -void Tins::Dot11BlockAckRequest::init_block_ack() { +void Dot11BlockAckRequest::init_block_ack() { subtype(BLOCK_ACK_REQ); std::memset(&_bar_control, 0, sizeof(_bar_control)); std::memset(&_start_sequence, 0, sizeof(_start_sequence)); } -uint32_t Tins::Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t total_sz) { uint32_t parent_size = Dot11ControlTA::write_ext_header(buffer, total_sz); buffer += parent_size; std::memcpy(buffer, &_bar_control, sizeof(_bar_control)); @@ -1878,26 +1880,26 @@ uint32_t Tins::Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t return parent_size + sizeof(_start_sequence) + sizeof(_bar_control); } -void Tins::Dot11BlockAckRequest::bar_control(uint16_t bar) { +void Dot11BlockAckRequest::bar_control(uint16_t bar) { std::memcpy(&_bar_control, &bar, sizeof(bar)); } -void Tins::Dot11BlockAckRequest::start_sequence(uint16_t seq) { +void Dot11BlockAckRequest::start_sequence(uint16_t seq) { std::memcpy(&_start_sequence, &seq, sizeof(seq)); } -uint32_t Tins::Dot11BlockAckRequest::header_size() const { +uint32_t Dot11BlockAckRequest::header_size() const { return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence); } -Tins::PDU *Tins::Dot11BlockAckRequest::clone_pdu() const { +PDU *Dot11BlockAckRequest::clone_pdu() const { Dot11BlockAckRequest *new_pdu = new Dot11BlockAckRequest(); new_pdu->copy_80211_fields(this); return new_pdu; } /* Dot11BlockAck */ -Tins::Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr, +Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) { @@ -1905,7 +1907,7 @@ Tins::Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr, std::memset(_bitmap, 0, sizeof(_bitmap)); } -Tins::Dot11BlockAck::Dot11BlockAck(const NetworkInterface &iface, +Dot11BlockAck::Dot11BlockAck(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) { @@ -1913,7 +1915,7 @@ Tins::Dot11BlockAck::Dot11BlockAck(const NetworkInterface &iface, std::memset(_bitmap, 0, sizeof(_bitmap)); } -Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { +Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { uint32_t padding = controlta_size(); buffer += padding; total_sz -= padding; @@ -1926,19 +1928,19 @@ Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : D std::memcpy(&_bitmap, buffer, sizeof(_bitmap)); } -void Tins::Dot11BlockAck::bar_control(uint16_t bar) { +void Dot11BlockAck::bar_control(uint16_t bar) { std::memcpy(&_bar_control, &bar, sizeof(bar)); } -void Tins::Dot11BlockAck::start_sequence(uint16_t seq) { +void Dot11BlockAck::start_sequence(uint16_t seq) { std::memcpy(&_start_sequence, &seq, sizeof(seq)); } -void Tins::Dot11BlockAck::bitmap(const uint8_t *bit) { +void Dot11BlockAck::bitmap(const uint8_t *bit) { std::memcpy(_bitmap, bit, sizeof(_bitmap)); } -uint32_t Tins::Dot11BlockAck::write_ext_header(uint8_t *buffer, uint32_t total_sz) { +uint32_t Dot11BlockAck::write_ext_header(uint8_t *buffer, uint32_t total_sz) { uint32_t parent_size = Dot11ControlTA::write_ext_header(buffer, total_sz); buffer += parent_size; std::memcpy(buffer, &_bar_control, sizeof(_bar_control)); @@ -1949,11 +1951,11 @@ uint32_t Tins::Dot11BlockAck::write_ext_header(uint8_t *buffer, uint32_t total_s return parent_size + sizeof(_bitmap) + sizeof(_bar_control) + sizeof(_start_sequence); } -uint32_t Tins::Dot11BlockAck::header_size() const { +uint32_t Dot11BlockAck::header_size() const { return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence) + sizeof(_bitmap); } -Tins::PDU *Tins::Dot11BlockAck::clone_pdu() const { +PDU *Dot11BlockAck::clone_pdu() const { Dot11BlockAck *new_pdu = new Dot11BlockAck(); new_pdu->copy_80211_fields(this); return new_pdu; @@ -1961,31 +1963,31 @@ Tins::PDU *Tins::Dot11BlockAck::clone_pdu() const { /* RSNInformation */ -Tins::RSNInformation::RSNInformation() : _version(1), _capabilities(0) { +RSNInformation::RSNInformation() : _version(1), _capabilities(0) { } -void Tins::RSNInformation::add_pairwise_cypher(CypherSuites cypher) { +void RSNInformation::add_pairwise_cypher(CypherSuites cypher) { _pairwise_cyphers.push_back(cypher); } -void Tins::RSNInformation::add_akm_cypher(AKMSuites akm) { +void RSNInformation::add_akm_cypher(AKMSuites akm) { _akm_cyphers.push_back(akm); } -void Tins::RSNInformation::group_suite(CypherSuites group) { +void RSNInformation::group_suite(CypherSuites group) { _group_suite = group; } -void Tins::RSNInformation::version(uint16_t ver) { +void RSNInformation::version(uint16_t ver) { _version = ver; } -void Tins::RSNInformation::capabilities(uint16_t cap) { +void RSNInformation::capabilities(uint16_t cap) { _capabilities = cap; } -uint8_t *Tins::RSNInformation::serialize(uint32_t &size) const { +uint8_t *RSNInformation::serialize(uint32_t &size) const { size = sizeof(_version) + sizeof(_capabilities) + sizeof(uint32_t); size += (sizeof(uint16_t) << 1); // 2 lists count. size += sizeof(uint32_t) * (_akm_cyphers.size() + _pairwise_cyphers.size()); @@ -2011,10 +2013,11 @@ uint8_t *Tins::RSNInformation::serialize(uint32_t &size) const { return buffer; } -Tins::RSNInformation Tins::RSNInformation::wpa2_psk() { +RSNInformation RSNInformation::wpa2_psk() { RSNInformation info; info.group_suite(RSNInformation::CCMP); info.add_pairwise_cypher(RSNInformation::CCMP); info.add_akm_cypher(RSNInformation::PSK); return info; } +} diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 58dd1bd..a3f3eb5 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -93,6 +93,8 @@ uint32_t Tins::EthernetII::header_size() const { } bool Tins::EthernetII::send(PacketSender* sender) { + if(!_iface) + throw std::runtime_error("Interface has not been set"); struct sockaddr_ll addr; memset(&addr, 0, sizeof(struct sockaddr_ll)); diff --git a/tests/src/dhcp.cpp b/tests/src/dhcp.cpp index 90b2f1b..643e107 100644 --- a/tests/src/dhcp.cpp +++ b/tests/src/dhcp.cpp @@ -7,6 +7,7 @@ #include "dhcp.h" #include "utils.h" #include "ethernetII.h" +#include "hwaddress.h" #include "ipaddress.h" using namespace std; @@ -15,14 +16,15 @@ using namespace Tins; class DHCPTest : public testing::Test { public: static const uint8_t expected_packet[]; - static const uint8_t chaddr[], sname[], file[]; + static const BootP::chaddr_type chaddr; + static const uint8_t sname[], file[]; static const IPv4Address addr; void test_equals(const DHCP &dhcp1, const DHCP &dhcp2); void test_option(const DHCP &dhcp, DHCP::Options opt, uint32_t len = 0, uint8_t *value = 0); }; -const uint8_t DHCPTest::chaddr[] = "\x16\xab\x54\x12\xfa\xca\x56\x7f\x1b\x65\x11\xfa\xda\xab\x19\x18"; +const BootP::chaddr_type DHCPTest::chaddr("16:ab:54:12:fa:ca:56:7f:1b:65:11:fa:da:ab:19:18"); const uint8_t DHCPTest::sname[] = "\x16\xab\x54\x12\xfa\xca\x56\x7f\x1b\x65\x11\xfa\xda\xbb\x19\x18" "\x16\xab\x54\x12\xfa\xca\x56\x7f\x1b\x65\x11\xfa\xda\xcb\x19\x18" "\x16\xab\x54\x12\xfa\xca\x56\x7f\x1b\x65\x11\xfa\xda\xeb\x19\x18" @@ -150,7 +152,12 @@ TEST_F(DHCPTest, Giaddr) { TEST_F(DHCPTest, Chaddr) { DHCP dhcp; dhcp.chaddr(chaddr); - EXPECT_TRUE(memcmp(dhcp.chaddr(), chaddr, dhcp.hlen()) == 0); + EXPECT_EQ(dhcp.chaddr(), chaddr); + + HWAddress<4> hwaddr("31:33:70:00"); + dhcp.chaddr(hwaddr); + HWAddress<4> copied(dhcp.chaddr()); + EXPECT_EQ(copied, hwaddr); } TEST_F(DHCPTest, Sname) { @@ -267,7 +274,7 @@ void DHCPTest::test_equals(const DHCP &dhcp1, const DHCP &dhcp2) { EXPECT_EQ(dhcp1.yiaddr(), dhcp2.yiaddr()); EXPECT_EQ(dhcp1.siaddr(), dhcp2.siaddr()); EXPECT_EQ(dhcp1.giaddr(), dhcp2.giaddr()); - EXPECT_TRUE(memcmp(dhcp1.chaddr(), dhcp2.chaddr(), dhcp1.hlen()) == 0); + EXPECT_EQ(dhcp1.chaddr(), dhcp2.chaddr()); EXPECT_TRUE(memcmp(dhcp1.sname(), dhcp2.sname(), 64) == 0); EXPECT_TRUE(memcmp(dhcp1.file(), dhcp2.file(), 128) == 0); const std::list options1(dhcp1.options());