diff --git a/include/ieee802-11.h b/include/ieee802-11.h index 164e701..f2f72d3 100644 --- a/include/ieee802-11.h +++ b/include/ieee802-11.h @@ -349,7 +349,6 @@ namespace Tins { * \sa PDU::pdu_type */ PDUType pdu_type() const { return PDU::IEEE802_11; } - private: /** * Struct that represents the 802.11 header diff --git a/include/pdu.h b/include/pdu.h index 86ccf16..6e9491f 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -53,6 +53,7 @@ namespace Tins { RAW, ETHERNET_II, IEEE802_11, + SNAP, IP, ARP, TCP, diff --git a/include/snap.h b/include/snap.h new file mode 100644 index 0000000..09f2f8e --- /dev/null +++ b/include/snap.h @@ -0,0 +1,76 @@ +/* + * 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 + */ + +#ifndef __IEEE8022_H +#define __IEEE8022_H + + +#include +#include "pdu.h" + +namespace Tins { + + /** + * \brief Class representing a SNAP frame. + * + * So far only unnumbered information structure is supported. + */ + class SNAP : public PDU { + public: + /** + * \brief Creates an instance of SNAP + * \param child The child PDU.(optional) + */ + SNAP(PDU *child = 0); + + /** + * \brief Returns the SNAP frame's header length. + * + * \return The header's size. + * \sa PDU::header_size() + */ + uint32_t header_size() const; + + /** + * \brief Getter for the PDU's type. + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::SNAP; } + private: + struct snaphdr { + uint8_t dsap; + uint8_t ssap; + uint32_t id:2, + reserved1:2, + poll:2, + reserved2:2, + org_code:24; + uint16_t eth_type; + } __attribute__((__packed__)); + + void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent); + + snaphdr _snap; + }; + +}; + +#endif diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 77af3e8..9a3f38e 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -133,9 +133,9 @@ void Tins::EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, c assert(total_sz >= my_sz); /* Inner type defaults to IP */ - if ((this->_eth.payload_type == 0) && this->inner_pdu()) { + if ((_eth.payload_type == 0) && inner_pdu()) { uint16_t type = ETHERTYPE_IP; - switch (this->inner_pdu()->pdu_type()) { + switch (inner_pdu()->pdu_type()) { case PDU::IP: type = ETHERTYPE_IP; break; @@ -145,9 +145,9 @@ void Tins::EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, c default: type = 0; } - this->_eth.payload_type = Utils::net_to_host_s(type); + _eth.payload_type = Utils::net_to_host_s(type); } - memcpy(buffer, &this->_eth, sizeof(ethhdr)); + memcpy(buffer, &_eth, sizeof(ethhdr)); } Tins::PDU *Tins::EthernetII::recv_response(PacketSender *sender) { diff --git a/src/snap.cpp b/src/snap.cpp new file mode 100644 index 0000000..0b0621c --- /dev/null +++ b/src/snap.cpp @@ -0,0 +1,59 @@ +/* + * 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 +#ifndef WIN32 + #include +#endif +#include "snap.h" +#include "utils.h" + + +Tins::SNAP::SNAP(PDU *child) : PDU(0xff, child) { + std::memset(&_snap, 0, sizeof(_snap)); + _snap.dsap = _snap.ssap = 0xaa; + _snap.id = 3; +} + +uint32_t Tins::SNAP::header_size() const { + return sizeof(_snap); +} + +void Tins::SNAP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { + assert(total_sz >= sizeof(_snap)); + if (!_snap.eth_type && inner_pdu()) { + uint16_t type = ETHERTYPE_IP; + switch (inner_pdu()->pdu_type()) { + case PDU::IP: + type = ETHERTYPE_IP; + break; + case PDU::ARP: + type = ETHERTYPE_ARP; + break; + default: + type = 0; + } + _snap.eth_type = Utils::net_to_host_s(type); + } + std::memcpy(buffer, &_snap, sizeof(_snap)); +} +