1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-26 12:01:34 +01:00

Added SNAP. Couldn't test it yet.

This commit is contained in:
Matias Fontanini
2011-08-21 16:29:10 -03:00
parent 2d27d02d32
commit 3f239b8022
5 changed files with 140 additions and 5 deletions

View File

@@ -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

View File

@@ -53,6 +53,7 @@ namespace Tins {
RAW,
ETHERNET_II,
IEEE802_11,
SNAP,
IP,
ARP,
TCP,

76
include/snap.h Normal file
View File

@@ -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 <stdint.h>
#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

View File

@@ -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) {

59
src/snap.cpp Normal file
View File

@@ -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 <cstring>
#include <cassert>
#ifndef WIN32
#include <net/ethernet.h>
#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));
}