1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

IEEE802_11 data packets now can be created from raw buffers. Not tested yet.

This commit is contained in:
Matias Fontanini
2011-08-25 22:22:57 -03:00
parent 9e56c3681e
commit 479d6c4acd
3 changed files with 32 additions and 1 deletions

View File

@@ -41,6 +41,14 @@ namespace Tins {
*/
SNAP(PDU *child = 0);
/**
* \brief Constructor which creates a SNAP object from a buffer and adds all identifiable
* PDUs found in the buffer as children of this one.
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
SNAP(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Returns the SNAP frame's header length.
*

View File

@@ -32,6 +32,7 @@
#include "radiotap.h"
#include "sniffer.h"
#include "utils.h"
#include "snap.h"
using namespace std;
@@ -74,7 +75,10 @@ Tins::IEEE802_11::IEEE802_11(const uint8_t *buffer, uint32_t total_sz) : PDU(ETH
std::memcpy(&_header, buffer, sizeof(_header));
buffer += sizeof(_header);
total_sz -= sizeof(_header);
if(type() == 0 && subtype() < 4) {
// It's a data packet
inner_pdu(new Tins::SNAP(buffer, total_sz));
}
// subclass specific parsing missing too.
}

View File

@@ -21,11 +21,14 @@
#include <cstring>
#include <cassert>
#include <stdexcept>
#ifndef WIN32
#include <net/ethernet.h>
#endif
#include "snap.h"
#include "utils.h"
#include "arp.h"
#include "ip.h"
Tins::SNAP::SNAP(PDU *child) : PDU(0xff, child) {
@@ -34,6 +37,22 @@ Tins::SNAP::SNAP(PDU *child) : PDU(0xff, child) {
_snap.id = 3;
}
Tins::SNAP::SNAP(const uint8_t *buffer, uint32_t total_sz) : PDU(0xff) {
if(total_sz < sizeof(_snap))
throw std::runtime_error("Not enough size for a SNAP header in the buffer.");
std::memcpy(&_snap, buffer, sizeof(_snap));
buffer += sizeof(_snap);
total_sz -= sizeof(_snap);
switch(Utils::net_to_host_s(_snap.eth_type)) {
case ETHERTYPE_IP:
inner_pdu(new Tins::IP(buffer, total_sz));
break;
case ETHERTYPE_ARP:
inner_pdu(new Tins::ARP(buffer, total_sz));
break;
};
}
uint32_t Tins::SNAP::header_size() const {
return sizeof(_snap);
}