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

Added PDU::clone_pdu.

This commit is contained in:
Matias Fontanini
2011-09-03 00:13:31 -03:00
parent e37ba2bf2e
commit fdcefd2132
6 changed files with 141 additions and 7 deletions

View File

@@ -74,6 +74,16 @@ namespace Tins {
*/
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.
@@ -176,6 +186,13 @@ 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;
private:
/**
* Struct that represents the Ethernet II header
@@ -192,6 +209,7 @@ namespace Tins {
*/
EthernetII(const ethhdr *eth_ptr);
void copy_fields(const EthernetII *other);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);

View File

@@ -76,6 +76,11 @@ namespace Tins {
IPOPT_QS = 25
};
/**
* \brief Default constructor.
*/
IP();
/**
* \brief Constructor for building the IP PDU taking strings as ip addresses.
*
@@ -86,7 +91,7 @@ namespace Tins {
* \param ip_src string containing the source hostname(optional).
* \param child pointer to a PDU which will be set as the inner_pdu for the packet being constructed(optional).
*/
IP(const std::string &ip_dst = "", const std::string &ip_src = "", PDU *child = 0);
IP(const std::string &ip_dst, const std::string &ip_src = "", PDU *child = 0);
/**
* \brief Constructor for building the IP PDU taking integer as ip addresses.
@@ -98,7 +103,12 @@ namespace Tins {
* \param ip_src The source ip address(optional).
* \param child pointer to a PDU which will be set as the inner_pdu for the packet being constructed(optional).
*/
IP(uint32_t ip_dst = 0, uint32_t ip_src = 0, PDU *child = 0);
IP(uint32_t ip_dst, uint32_t ip_src = 0, PDU *child = 0);
/**
* \brief Copy constructor.
*/
IP(const IP &other);
/**
* \brief Constructor which creates an IP object from a buffer and adds all identifiable
@@ -116,6 +126,11 @@ namespace Tins {
*/
~IP();
/**
* \brief Copy assignment operator.
*/
IP &operator= (const IP &other);
/* Getters */
/**
@@ -349,6 +364,13 @@ 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;
private:
static const uint8_t DEFAULT_TTL;
@@ -398,7 +420,8 @@ namespace Tins {
* \param ptr The ip header pointer.
*/
IP(const iphdr *ptr);
void copy_fields(const IP *other);
void init_ip_fields();
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);

View File

@@ -95,12 +95,15 @@ namespace Tins {
*/
uint32_t size() const;
/** \brief This PDU's type flag identifier.
*
/**
* \brief Getter for this PDU's type flag identifier.
* \return The type flag identifier.
*/
inline uint32_t flag() const { return _flag; }
/** \brief The child PDU.
/**
* \brief Getter for the inner PDU.
* \return The current inner PDU. Might be 0.
*/
inline PDU *inner_pdu() const { return _inner_pdu; }
@@ -108,7 +111,8 @@ namespace Tins {
*/
void flag(uint32_t new_flag);
/** \brief Sets the child PDU.
/**
* \brief Sets the child PDU.
*
* \param next_pdu The new child PDU.
* When setting a new inner_pdu, the instance takesownership of
@@ -143,6 +147,28 @@ namespace Tins {
return 0;
}
/**
* \brief Clones this packet.
*
* This method clones this PDU and clones every inner PDU,
* therefore obtaining a clone of the whole inner PDU chain.
* The pointer returned must be deleted by the user.
* \return A pointer to a clone of this packet.
*/
PDU *clone_packet() const;
/**
* \brief Clones this PDU.
*
* This method does not clone the inner PDUs. \sa PDU::clone_packet
* \return A pointer to a copy of this PDU.
*/
virtual PDU *clone_pdu() const {
/* Should be pure virtual. It's this way to avoid compiling issues.
* Once every pdu has implemented it, make it pure virtual. */
return 0;
}
/** \brief Send the stack of PDUs through a PacketSender.
*
* This method will be called only for the PDU on the bottom of the stack,