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

Added SLL pseudo protocol header.

This commit is contained in:
Matias Fontanini
2013-01-16 00:05:28 -03:00
parent a13d7d0cb1
commit 02265061cc
16 changed files with 492 additions and 2023 deletions

151
depends.d
View File

@@ -49,7 +49,7 @@ src/crypto.o: src/crypto.cpp include/crypto.h include/dot11.h \
include/macros.h include/pdu.h include/endianness.h include/hw_address.h \
include/small_uint.h include/pdu_option.h include/network_interface.h \
include/ip_address.h include/utils.h include/ipv6_address.h \
include/internals.h include/snap.h include/rawpdu.h
include/internals.h include/constants.h include/snap.h include/rawpdu.h
include/crypto.h:
@@ -77,6 +77,8 @@ include/ipv6_address.h:
include/internals.h:
include/constants.h:
include/snap.h:
include/rawpdu.h:
@@ -199,7 +201,8 @@ src/ethernetII.o: src/ethernetII.cpp include/macros.h \
include/hw_address.h include/network_interface.h include/ip_address.h \
include/packet_sender.h include/rawpdu.h include/ip.h \
include/small_uint.h include/pdu_option.h include/ipv6.h \
include/ipv6_address.h include/arp.h include/constants.h
include/ipv6_address.h include/arp.h include/constants.h \
include/internals.h include/constants.h
include/macros.h:
@@ -233,11 +236,15 @@ include/ipv6_address.h:
include/arp.h:
include/constants.h:
include/internals.h:
include/constants.h:
src/icmp.o: src/icmp.cpp include/icmp.h include/macros.h include/pdu.h \
include/endianness.h include/rawpdu.h include/utils.h \
include/ip_address.h include/ipv6_address.h include/hw_address.h \
include/internals.h
include/internals.h include/constants.h
include/icmp.h:
@@ -258,11 +265,13 @@ include/ipv6_address.h:
include/hw_address.h:
include/internals.h:
include/constants.h:
src/icmpv6.o: src/icmpv6.cpp include/icmpv6.h include/macros.h \
include/pdu.h include/ipv6_address.h include/pdu_option.h \
include/endianness.h include/small_uint.h include/hw_address.h \
include/ipv6.h include/rawpdu.h include/utils.h include/ip_address.h \
include/internals.h include/constants.h
include/internals.h include/constants.h include/constants.h
include/icmpv6.h:
@@ -290,6 +299,8 @@ include/ip_address.h:
include/internals.h:
include/constants.h:
include/constants.h:
src/ieee802_3.o: src/ieee802_3.cpp include/macros.h include/ieee802_3.h \
include/macros.h include/pdu.h include/endianness.h include/hw_address.h \
@@ -315,15 +326,47 @@ include/ip_address.h:
include/packet_sender.h:
include/llc.h:
src/internals.o: src/internals.cpp include/internals.h
src/internals.o: src/internals.cpp include/internals.h \
include/constants.h include/pdu.h include/ip.h include/small_uint.h \
include/endianness.h include/macros.h include/ip_address.h \
include/pdu_option.h include/ipv6.h include/ipv6_address.h include/arp.h \
include/hw_address.h include/eapol.h include/rawpdu.h
include/internals.h:
include/constants.h:
include/pdu.h:
include/ip.h:
include/small_uint.h:
include/endianness.h:
include/macros.h:
include/ip_address.h:
include/pdu_option.h:
include/ipv6.h:
include/ipv6_address.h:
include/arp.h:
include/hw_address.h:
include/eapol.h:
include/rawpdu.h:
src/ip.o: src/ip.cpp include/ip.h include/pdu.h include/small_uint.h \
include/endianness.h include/macros.h include/ip_address.h \
include/pdu_option.h include/ipv6.h include/ipv6_address.h include/tcp.h \
include/udp.h include/icmp.h include/rawpdu.h include/utils.h \
include/hw_address.h include/internals.h include/packet_sender.h \
include/network_interface.h include/constants.h
include/hw_address.h include/internals.h include/constants.h \
include/packet_sender.h include/network_interface.h include/constants.h
include/ip.h:
@@ -357,6 +400,8 @@ include/hw_address.h:
include/internals.h:
include/constants.h:
include/packet_sender.h:
include/network_interface.h:
@@ -433,16 +478,16 @@ include/endianness.h:
include/rawpdu.h:
src/loopback.o: src/loopback.cpp include/loopback.h include/pdu.h \
include/packet_sender.h include/network_interface.h include/hw_address.h \
include/ip_address.h include/macros.h include/ip.h include/small_uint.h \
include/endianness.h include/pdu_option.h include/llc.h include/macros.h \
include/rawpdu.h
include/macros.h include/network_interface.h include/hw_address.h \
include/ip_address.h include/packet_sender.h include/ip.h \
include/small_uint.h include/endianness.h include/pdu_option.h \
include/llc.h include/rawpdu.h
include/loopback.h:
include/pdu.h:
include/packet_sender.h:
include/macros.h:
include/network_interface.h:
@@ -450,7 +495,7 @@ include/hw_address.h:
include/ip_address.h:
include/macros.h:
include/packet_sender.h:
include/ip.h:
@@ -462,13 +507,12 @@ include/pdu_option.h:
include/llc.h:
include/macros.h:
include/rawpdu.h:
src/network_interface.o: src/network_interface.cpp include/macros.h \
include/network_interface.h include/hw_address.h include/ip_address.h \
include/utils.h include/macros.h include/ipv6_address.h \
include/internals.h include/endianness.h
include/internals.h include/constants.h include/pdu.h \
include/endianness.h
include/macros.h:
@@ -486,6 +530,10 @@ include/ipv6_address.h:
include/internals.h:
include/constants.h:
include/pdu.h:
include/endianness.h:
src/packet_sender.o: src/packet_sender.cpp include/packet_sender.h \
include/network_interface.h include/hw_address.h include/ip_address.h \
@@ -510,7 +558,7 @@ include/network_interface.h:
src/packet_writer.o: src/packet_writer.cpp include/packet_writer.h \
include/utils.h include/macros.h include/ip_address.h \
include/ipv6_address.h include/hw_address.h include/internals.h \
include/pdu.h
include/constants.h include/pdu.h include/pdu.h
include/packet_writer.h:
@@ -526,6 +574,10 @@ include/hw_address.h:
include/internals.h:
include/constants.h:
include/pdu.h:
include/pdu.h:
src/pdu.o: src/pdu.cpp include/pdu.h include/rawpdu.h include/pdu.h \
include/packet_sender.h include/network_interface.h include/hw_address.h \
@@ -551,7 +603,7 @@ src/radiotap.o: src/radiotap.cpp include/macros.h include/radiotap.h \
include/network_interface.h include/hw_address.h include/ip_address.h \
include/dot11.h include/small_uint.h include/pdu_option.h \
include/utils.h include/ipv6_address.h include/internals.h \
include/packet_sender.h
include/constants.h include/packet_sender.h
include/macros.h:
@@ -581,6 +633,8 @@ include/ipv6_address.h:
include/internals.h:
include/constants.h:
include/packet_sender.h:
src/rawpdu.o: src/rawpdu.cpp include/rawpdu.h include/pdu.h
@@ -595,10 +649,28 @@ include/rsn_information.h:
include/endianness.h:
include/macros.h:
src/sll.o: src/sll.cpp include/sll.h include/pdu.h include/endianness.h \
include/macros.h include/hw_address.h include/internals.h \
include/constants.h
include/sll.h:
include/pdu.h:
include/endianness.h:
include/macros.h:
include/hw_address.h:
include/internals.h:
include/constants.h:
src/snap.o: src/snap.cpp include/snap.h include/pdu.h include/macros.h \
include/endianness.h include/small_uint.h include/constants.h \
include/arp.h include/hw_address.h include/ip_address.h include/ip.h \
include/pdu_option.h include/eapol.h
include/pdu_option.h include/eapol.h include/internals.h \
include/constants.h
include/snap.h:
@@ -623,12 +695,16 @@ include/ip.h:
include/pdu_option.h:
include/eapol.h:
include/internals.h:
include/constants.h:
src/sniffer.o: src/sniffer.cpp include/sniffer.h include/pdu.h \
include/ethernetII.h include/macros.h include/endianness.h \
include/hw_address.h include/network_interface.h include/ip_address.h \
include/radiotap.h include/packet.h include/cxxstd.h include/timestamp.h \
include/loopback.h include/dot11.h include/small_uint.h \
include/pdu_option.h
include/pdu_option.h include/sll.h
include/sniffer.h:
@@ -661,11 +737,13 @@ include/dot11.h:
include/small_uint.h:
include/pdu_option.h:
include/sll.h:
src/tcp.o: src/tcp.cpp include/tcp.h include/pdu.h include/macros.h \
include/endianness.h include/small_uint.h include/pdu_option.h \
include/ip.h include/ip_address.h include/ipv6.h include/ipv6_address.h \
include/constants.h include/rawpdu.h include/utils.h \
include/hw_address.h include/internals.h
include/hw_address.h include/internals.h include/constants.h
include/tcp.h:
@@ -696,13 +774,16 @@ include/utils.h:
include/hw_address.h:
include/internals.h:
include/constants.h:
src/tcp_stream.o: src/tcp_stream.cpp include/rawpdu.h include/pdu.h \
include/tcp_stream.h include/sniffer.h include/ethernetII.h \
include/macros.h include/endianness.h include/hw_address.h \
include/network_interface.h include/ip_address.h include/radiotap.h \
include/packet.h include/cxxstd.h include/timestamp.h include/loopback.h \
include/dot11.h include/small_uint.h include/pdu_option.h include/tcp.h \
include/utils.h include/ipv6_address.h include/internals.h include/ip.h
include/dot11.h include/small_uint.h include/pdu_option.h include/sll.h \
include/tcp.h include/utils.h include/ipv6_address.h include/internals.h \
include/constants.h include/ip.h
include/rawpdu.h:
@@ -740,6 +821,8 @@ include/small_uint.h:
include/pdu_option.h:
include/sll.h:
include/tcp.h:
include/utils.h:
@@ -748,12 +831,14 @@ include/ipv6_address.h:
include/internals.h:
include/constants.h:
include/ip.h:
src/udp.o: src/udp.cpp include/udp.h include/macros.h include/pdu.h \
include/endianness.h include/constants.h include/utils.h \
include/ip_address.h include/ipv6_address.h include/hw_address.h \
include/internals.h include/ip.h include/small_uint.h \
include/pdu_option.h include/rawpdu.h
include/internals.h include/constants.h include/ip.h \
include/small_uint.h include/pdu_option.h include/rawpdu.h
include/udp.h:
@@ -775,6 +860,8 @@ include/hw_address.h:
include/internals.h:
include/constants.h:
include/ip.h:
include/small_uint.h:
@@ -784,10 +871,10 @@ include/pdu_option.h:
include/rawpdu.h:
src/utils.o: src/utils.cpp include/utils.h include/macros.h \
include/ip_address.h include/ipv6_address.h include/hw_address.h \
include/internals.h include/pdu.h include/arp.h include/pdu.h \
include/endianness.h include/ethernetII.h include/network_interface.h \
include/endianness.h include/network_interface.h include/packet_sender.h \
include/cxxstd.h
include/internals.h include/constants.h include/pdu.h include/pdu.h \
include/arp.h include/endianness.h include/ethernetII.h \
include/network_interface.h include/endianness.h \
include/network_interface.h include/packet_sender.h include/cxxstd.h
include/utils.h:
@@ -801,12 +888,14 @@ include/hw_address.h:
include/internals.h:
include/constants.h:
include/pdu.h:
include/pdu.h:
include/arp.h:
include/pdu.h:
include/endianness.h:
include/ethernetII.h:

View File

@@ -73,6 +73,7 @@ namespace Tins {
struct Ethernet {
enum e {
UNKNOWN = 0,
//~ PUP = 0x0200, /* Xerox PUP */
SPRITE = 0x0500, /* Sprite */
IP = 0x0800, /* IP */

View File

@@ -33,6 +33,8 @@
#include <sstream>
#include <string>
#include <stdint.h>
#include "constants.h"
#include "pdu.h"
/**
* \cond
@@ -52,15 +54,10 @@ namespace Internals {
typedef T type;
};
template<typename T1, typename T2>
struct is_same {
static const bool value = false;
};
PDU *pdu_from_flag(Constants::Ethernet::e flag, const uint8_t *buffer,
uint32_t size, bool rawpdu_on_no_match = true);
template<typename T1>
struct is_same<T1, T1> {
static const bool value = true;
};
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag);
}
}
/**

View File

@@ -231,8 +231,9 @@ namespace Tins {
PDU *child = 0);
/**
* \brief Constructor which creates an IP object from a buffer and adds all identifiable
* PDUs found in the buffer as children of this one.
* \brief Constructor which constructs an IP 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.
*/

View File

@@ -53,7 +53,8 @@ public:
enum LinkType {
RADIOTAP = DLT_IEEE802_11_RADIO,
DOT11 = DLT_IEEE802_11,
ETH2 = DLT_EN10MB
ETH2 = DLT_EN10MB,
SLL = DLT_LINUX_SLL
};
/**

View File

@@ -103,7 +103,8 @@ namespace Tins {
DNS,
LOOPBACK,
IPv6,
ICMPv6
ICMPv6,
SLL
};
/** \brief PDU constructor

172
include/sll.h Normal file
View File

@@ -0,0 +1,172 @@
/*
* Copyright (c) 2012, Nasel
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_SLL_H
#define TINS_SLL_H
#include <vector>
#include "pdu.h"
#include "endianness.h"
#include "hw_address.h"
namespace Tins {
class SLL : public PDU {
public:
/**
* This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::SLL;
/**
* The type of the address type
*/
typedef HWAddress<8> address_type;
/**
* Default constructor
*/
SLL();
/**
* \brief Constructor which constructs an SLL 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.
*/
SLL(const uint8_t *buffer, uint32_t total_sz);
// Getters
/**
* \brief Getter for the packet_type field.
* \return The stored packet_type field value.
*/
uint16_t packet_type() const {
return Endian::be_to_host(_header.packet_type);
}
/**
* \brief Getter for the lladdr_type field.
* \return The stored lladdr_type field value.
*/
uint16_t lladdr_type() const {
return Endian::be_to_host(_header.lladdr_type);
}
/**
* \brief Getter for the lladdr_len field.
* \return The stored lladdr_len field value.
*/
uint16_t lladdr_len() const {
return Endian::be_to_host(_header.lladdr_len);
}
/**
* \brief Getter for the address field.
* \return The stored address field value.
*/
address_type address() const {
return _header.address;
}
/**
* \brief Getter for the protocol field.
* \return The stored protocol field value.
*/
uint16_t protocol() const {
return Endian::be_to_host(_header.protocol);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
// Setters
/**
* \brief Setter for the packet_type field.
* \param new_packet_type The new packet_type field value.
*/
void packet_type(uint16_t new_packet_type);
/**
* \brief Setter for the lladdr_type field.
* \param new_lladdr_type The new lladdr_type field value.
*/
void lladdr_type(uint16_t new_lladdr_type);
/**
* \brief Setter for the lladdr_len field.
* \param new_lladdr_len The new lladdr_len field value.
*/
void lladdr_len(uint16_t new_lladdr_len);
/**
* \brief Setter for the address field.
* \param new_address The new address field value.
*/
void address(const address_type &new_address);
/**
* \brief Setter for the protocol field.
* \param new_protocol The new protocol field value.
*/
void protocol(uint16_t new_protocol);
/**
* \brief Returns the header size.
*
* This metod overrides PDU::header_size. \sa PDU::header_size
*/
uint32_t header_size() const;
/**
* \sa PDU::clone
*/
SLL *clone() const {
return new SLL(*this);
}
private:
TINS_BEGIN_PACK
struct sllhdr {
uint16_t packet_type, lladdr_type, lladdr_len;
uint8_t address[8];
uint16_t protocol;
} TINS_END_PACK;
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *);
sllhdr _header;
};
}
#endif // TINS_SLL_H

View File

@@ -42,6 +42,7 @@
#include "packet.h"
#include "loopback.h"
#include "dot11.h"
#include "sll.h"
#include "cxxstd.h"
namespace Tins {
@@ -268,6 +269,8 @@ namespace Tins {
}
else if(data->iface_type == DLT_NULL)
ret_val = call_functor<Tins::Loopback>(data, packet, header);
else if(data->iface_type == DLT_LINUX_SLL)
ret_val = call_functor<Tins::SLL>(data, packet, header);
if(!ret_val)
pcap_breakloop(data->handle);

View File

@@ -30,6 +30,7 @@
#ifndef TINS_TINS_H
#define TINS_TINS_H
#include "dns.h"
#include "arp.h"
#include "bootp.h"
#include "dhcp.h"
@@ -52,7 +53,6 @@
#include "tcp.h"
#include "udp.h"
#include "utils.h"
#include "dns.h"
#include "tcp_stream.h"
#include "crypto.h"
#include "pdu_cacher.h"
@@ -61,5 +61,6 @@
#include "ip_address.h"
#include "packet.h"
#include "timestamp.h"
#include "sll.h"
#endif // TINS_TINS_H

View File

@@ -48,6 +48,7 @@
#include "ipv6.h"
#include "arp.h"
#include "constants.h"
#include "internals.h"
namespace Tins {
const EthernetII::address_type EthernetII::BROADCAST("ff:ff:ff:ff:ff:ff");
@@ -70,25 +71,16 @@ EthernetII::EthernetII(const uint8_t *buffer, uint32_t total_sz)
if(total_sz < sizeof(ethhdr))
throw std::runtime_error("Not enough size for an ethernetII header in the buffer.");
memcpy(&_eth, buffer, sizeof(ethhdr));
PDU *next = 0;
buffer += sizeof(ethhdr);
total_sz -= sizeof(ethhdr);
if(total_sz) {
switch(payload_type()) {
case Constants::Ethernet::IP:
next = new Tins::IP(buffer, total_sz);
break;
case Constants::Ethernet::IPV6:
next = new Tins::IPv6(buffer, total_sz);
break;
case Constants::Ethernet::ARP:
next = new Tins::ARP(buffer, total_sz);
break;
default:
next = new Tins::RawPDU(buffer, total_sz);
// Other protos plz
}
inner_pdu(next);
inner_pdu(
Internals::pdu_from_flag(
(Constants::Ethernet::e)payload_type(),
buffer,
total_sz
)
);
}
}
@@ -152,21 +144,10 @@ void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const P
/* Inner type defaults to IP */
if ((_eth.payload_type == 0) && inner_pdu()) {
uint16_t type = Constants::Ethernet::IP;
switch (inner_pdu()->pdu_type()) {
case PDU::IP:
type = Constants::Ethernet::IP;
break;
case PDU::IPv6:
type = Constants::Ethernet::IPV6;
break;
case PDU::ARP:
type = Constants::Ethernet::ARP;
break;
default:
type = 0;
}
_eth.payload_type = Endian::host_to_be(type);
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
inner_pdu()->pdu_type()
);
payload_type(static_cast<uint16_t>(flag));
}
memcpy(buffer, &_eth, sizeof(ethhdr));
}

View File

@@ -28,6 +28,11 @@
*/
#include "internals.h"
#include "ip.h"
#include "ipv6.h"
#include "arp.h"
#include "eapol.h"
#include "rawpdu.h"
using std::string;
@@ -55,5 +60,35 @@ void skip_line(std::istream &input) {
while(c != '\n' && input)
c = input.get();
}
Tins::PDU *pdu_from_flag(Constants::Ethernet::e flag, const uint8_t *buffer,
uint32_t size, bool rawpdu_on_no_match)
{
switch(flag) {
case Tins::Constants::Ethernet::IP:
return new Tins::IP(buffer, size);
case Constants::Ethernet::IPV6:
return new Tins::IPv6(buffer, size);
case Tins::Constants::Ethernet::ARP:
return new Tins::ARP(buffer, size);
case Tins::Constants::Ethernet::EAPOL:
return Tins::EAPOL::from_bytes(buffer, size);
default:
return rawpdu_on_no_match ? new RawPDU(buffer, size) : 0;
};
}
Constants::Ethernet::e pdu_flag_to_ether_type(PDU::PDUType flag) {
switch (flag) {
case PDU::IP:
return Constants::Ethernet::IP;
case PDU::IPv6:
return Constants::Ethernet::IPV6;
case PDU::ARP:
return Constants::Ethernet::ARP;
default:
return Constants::Ethernet::UNKNOWN;
}
}
}
}

91
src/sll.cpp Normal file
View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2012, Nasel
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdexcept>
#include <cstring>
#include "sll.h"
#include "internals.h"
namespace Tins {
SLL::SLL() : _header() {
}
SLL::SLL(const uint8_t *buffer, uint32_t total_sz) {
const char *err_msg = "Not enough size for a SLL header";
if(total_sz < sizeof(_header))
throw std::runtime_error(err_msg);
std::memcpy(&_header, buffer, sizeof(_header));
buffer += sizeof(_header);
total_sz -= sizeof(_header);
if(total_sz) {
inner_pdu(
Internals::pdu_from_flag(
(Constants::Ethernet::e)protocol(),
buffer,
total_sz
)
);
}
}
void SLL::packet_type(uint16_t new_packet_type) {
_header.packet_type = Endian::host_to_be(new_packet_type);
}
void SLL::lladdr_type(uint16_t new_lladdr_type) {
_header.lladdr_type = Endian::host_to_be(new_lladdr_type);
}
void SLL::lladdr_len(uint16_t new_lladdr_len) {
_header.lladdr_len = Endian::host_to_be(new_lladdr_len);
}
void SLL::address(const address_type &new_address) {
new_address.copy(_header.address);
}
void SLL::protocol(uint16_t new_protocol) {
_header.protocol = Endian::host_to_be(new_protocol);
}
uint32_t SLL::header_size() const {
return sizeof(_header);
}
void SLL::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *) {
if(inner_pdu()) {
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
inner_pdu()->pdu_type()
);
protocol(static_cast<uint16_t>(flag));
}
std::memcpy(buffer, &_header, sizeof(_header));
}
}

View File

@@ -38,6 +38,7 @@
#include "arp.h"
#include "ip.h"
#include "eapol.h"
#include "internals.h"
Tins::SNAP::SNAP(PDU *child) : PDU(child)
@@ -55,7 +56,7 @@ Tins::SNAP::SNAP(const uint8_t *buffer, uint32_t total_sz)
buffer += sizeof(_snap);
total_sz -= sizeof(_snap);
if(total_sz) {
switch(eth_type()) {
/*switch(eth_type()) {
case Tins::Constants::Ethernet::IP:
inner_pdu(new Tins::IP(buffer, total_sz));
break;
@@ -65,7 +66,14 @@ Tins::SNAP::SNAP(const uint8_t *buffer, uint32_t total_sz)
case Tins::Constants::Ethernet::EAPOL:
inner_pdu(Tins::EAPOL::from_bytes(buffer, total_sz));
break;
};
};*/
inner_pdu(
Internals::pdu_from_flag(
(Constants::Ethernet::e)eth_type(),
buffer,
total_sz
)
);
}
}

View File

@@ -95,6 +95,8 @@ PtrPacket BaseSniffer::next_packet() {
ret = Dot11::from_bytes((const uint8_t*)content, header.caplen);
else if(iface_type == DLT_LOOP)
ret = new Tins::Loopback((const uint8_t*)content, header.caplen);
else if(iface_type == DLT_LINUX_SLL)
ret = new Tins::SLL((const uint8_t*)content, header.caplen);
}
return PtrPacket(ret, header.ts);
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,8 @@
#include "ethernetII.h"
#include "utils.h"
#include "macros.h"
#include "ipv6.h"
#include "ip.h"
#include "network_interface.h"
using namespace Tins;
@@ -11,7 +13,7 @@ typedef EthernetII::address_type address_type;
class EthernetIITest : public ::testing::Test {
public:
static const uint8_t expected_packet[];
static const uint8_t expected_packet[], ip_packet[], ipv6_packet[];
static address_type src_addr;
static address_type dst_addr;
static address_type empty_addr;
@@ -22,10 +24,24 @@ public:
};
const uint8_t EthernetIITest::expected_packet[] = {
'\xaa', '\xbb', '\xcc', '\xdd',
'\xee', '\xff', '\x8a', '\x8b',
'\x8c', '\x8d', '\x8e', '\x8f',
'\xd0', '\xab'
'\xaa', '\xbb', '\xcc', '\xdd',
'\xee', '\xff', '\x8a', '\x8b',
'\x8c', '\x8d', '\x8e', '\x8f',
'\xd0', '\xab'
},
EthernetIITest::ip_packet[] = {
'\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x08', '\x00', 'E', '\x00', '\x00', '\x14',
'\x00', '\x01', '\x00', '\x00', '@', '\x00', '|', '\xe7', '\x7f', '\x00',
'\x00', '\x01', '\x7f', '\x00', '\x00', '\x01'
},
EthernetIITest::ipv6_packet[] = {
'\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x86', '\xdd', '`', '\x00', '\x00', '\x00',
'\x00', '\x00', ';', '@', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x01', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01'
};
address_type EthernetIITest::src_addr("8a:8b:8c:8d:8e:8f");
@@ -130,4 +146,15 @@ TEST_F(EthernetIITest, ConstructorFromBuffer) {
EXPECT_EQ(eth.payload_type(), p_type);
}
TEST_F(EthernetIITest, ConstructorFromIPBuffer) {
EthernetII eth(ip_packet, sizeof(ip_packet));
ASSERT_TRUE(eth.inner_pdu());
EXPECT_EQ(eth.find_pdu<IP>(), eth.inner_pdu());
}
TEST_F(EthernetIITest, ConstructorFromIPv6Buffer) {
EthernetII eth(ipv6_packet, sizeof(ipv6_packet));
ASSERT_TRUE(eth.inner_pdu());
EXPECT_EQ(eth.find_pdu<IPv6>(), eth.inner_pdu());
}