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

Added test for EthernetII PDU

This commit is contained in:
Santiago Alessandri
2011-09-15 12:01:45 -03:00
parent 13e260b825
commit 8b7f016278
2 changed files with 20 additions and 32 deletions

View File

@@ -26,6 +26,7 @@
#include <stdexcept>
#include "pdu.h"
#include "utils.h"
namespace Tins {
@@ -36,11 +37,11 @@ namespace Tins {
public:
/**
/**
* \brief Represents the ethernetII broadcast address.
*/
static const uint8_t* BROADCAST;
/**
* \brief Ethernet II hardware address size.
*/
@@ -79,17 +80,7 @@ namespace Tins {
* \param total_sz The total size of the buffer.
*/
EthernetII(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Copy constructor.
*/
EthernetII(const EthernetII &other);
/**
* \brief Copy assignment operator.
*/
EthernetII &operator= (const EthernetII &other);
/* Getters */
/**
* \brief Getter for the destination's mac address.
@@ -116,10 +107,10 @@ namespace Tins {
* \brief Getter for the payload_type
* \return The payload type.
*/
uint16_t payload_type() const;
inline uint16_t payload_type() const { return Utils::net_to_host_s(_eth.payload_type); };
/* Setters */
/**
* \brief Setter for the destination's MAC.
*
@@ -148,6 +139,13 @@ namespace Tins {
*/
void iface(const std::string& new_iface) throw (std::runtime_error);
/**
* \brief Setter for the payload type.
*
* \param new_payload_type uint16_t with the new value of the payload type field.
*/
void payload_type(uint16_t new_payload_type);
/* Virtual methods */
/**
* \brief Returns the ethernet frame's header length.
@@ -192,10 +190,10 @@ namespace Tins {
* \sa PDU::clone_packet
*/
PDU *clone_packet(const uint8_t *ptr, uint32_t total_sz);
/**
* \brief Clones this PDU.
*
*
* \sa PDU::clone_pdu
*/
PDU *clone_pdu() const;
@@ -211,7 +209,7 @@ namespace Tins {
void copy_fields(const EthernetII *other);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
ethhdr _eth;
uint32_t _iface_index;

View File

@@ -77,20 +77,6 @@ Tins::EthernetII::EthernetII(const uint8_t *buffer, uint32_t total_sz) : PDU(ETH
}
}
Tins::EthernetII::EthernetII(const EthernetII &other) : PDU(other) {
copy_fields(&other);
}
Tins::EthernetII &Tins::EthernetII::operator= (const EthernetII &other) {
copy_fields(&other);
copy_inner_pdu(other);
return *this;
}
uint16_t Tins::EthernetII::payload_type() const {
return Utils::net_to_host_s(_eth.payload_type);
}
void Tins::EthernetII::dst_addr(const uint8_t* new_dst_mac) {
memcpy(_eth.dst_mac, new_dst_mac, sizeof(_eth.dst_mac));
}
@@ -109,6 +95,10 @@ void Tins::EthernetII::iface(const std::string& new_iface) throw (std::runtime_e
}
}
void Tins::EthernetII::payload_type(uint16_t new_payload_type) {
this->_eth.payload_type = Utils::net_to_host_s(new_payload_type);
}
uint32_t Tins::EthernetII::header_size() const {
return sizeof(ethhdr);
}