diff --git a/include/arp.h b/include/arp.h index 30a8df6..67502de 100644 --- a/include/arp.h +++ b/include/arp.h @@ -59,6 +59,13 @@ namespace Tins { * \param total_sz The total size of the buffer. */ ARP(const uint8_t *buffer, uint32_t total_sz); + + /** + * \brief Copy constructor + * + * \param other The object which will be copied. + */ + ARP(const ARP &other); /* Getters */ /** diff --git a/include/ethernetII.h b/include/ethernetII.h index 80821f3..fbc5d91 100644 --- a/include/ethernetII.h +++ b/include/ethernetII.h @@ -80,6 +80,13 @@ namespace Tins { * \param total_sz The total size of the buffer. */ EthernetII(const uint8_t *buffer, uint32_t total_sz); + + /** + * \brief EthernetII copy constructor. + * + * \param other The packet which will be copied. + */ + EthernetII(const EthernetII &other); /* Getters */ /** diff --git a/include/icmp.h b/include/icmp.h index 6cb13a1..2ad11a2 100644 --- a/include/icmp.h +++ b/include/icmp.h @@ -65,6 +65,13 @@ namespace Tins { */ ICMP(const uint8_t *buffer, uint32_t total_sz); + /** + * \brief Copy constructor + * + * \param other The object which will be copied. + */ + ICMP(const ICMP &other); + /** * \brief Sets the code field. * diff --git a/src/arp.cpp b/src/arp.cpp index 4301940..1988c6f 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -57,6 +57,10 @@ Tins::ARP::ARP(const uint8_t *buffer, uint32_t total_sz) : PDU(Utils::net_to_hos inner_pdu(new RawPDU(buffer + sizeof(arphdr), total_sz)); } +Tins::ARP::ARP(const ARP &other) : PDU(other) { + copy_fields(&other); +} + void Tins::ARP::sender_hw_addr(const uint8_t* new_snd_hw_addr) { memcpy(this->_arp.ar_sha, new_snd_hw_addr, 6); //Should this use hardware address' length? } @@ -208,6 +212,7 @@ Tins::PDU* Tins::ARP::make_arp_reply(const string& iface, Tins::PDU *Tins::ARP::clone_pdu() const { ARP *new_pdu = new ARP(); new_pdu->copy_fields(this); + new_pdu->copy_inner_pdu(*this); return new_pdu; } diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 18e5e5c..f180290 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -56,6 +56,10 @@ Tins::EthernetII::EthernetII(uint32_t iface_index, const uint8_t* dst_hw_addr, c this->_eth.payload_type = 0; } +Tins::EthernetII::EthernetII(const EthernetII &other) : PDU(other) { + copy_fields(&other); +} + Tins::EthernetII::EthernetII(const uint8_t *buffer, uint32_t total_sz) : PDU(ETHERTYPE_IP) { if(total_sz < sizeof(ethhdr)) throw std::runtime_error("Not enough size for an ethernetII header in the buffer."); @@ -184,5 +188,6 @@ void Tins::EthernetII::copy_fields(const EthernetII *other) { Tins::PDU *Tins::EthernetII::clone_pdu() const { EthernetII *new_pdu = new EthernetII(_iface_index); new_pdu->copy_fields(this); + new_pdu->copy_inner_pdu(*this); return new_pdu; } diff --git a/src/icmp.cpp b/src/icmp.cpp index c300613..f9428e8 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -57,6 +57,10 @@ Tins::ICMP::ICMP(const uint8_t *buffer, uint32_t total_sz) : PDU(IPPROTO_ICMP) { inner_pdu(new RawPDU(buffer + sizeof(icmphdr), total_sz)); } +Tins::ICMP::ICMP(const ICMP &other) : PDU(other) { + copy_fields(&other); +} + void Tins::ICMP::code(uint8_t new_code) { _icmp.code = new_code; } @@ -207,5 +211,6 @@ void Tins::ICMP::copy_fields(const ICMP *other) { Tins::PDU *Tins::ICMP::clone_pdu() const { ICMP *new_pdu = new ICMP(); new_pdu->copy_fields(this); + new_pdu->copy_inner_pdu(*this); return new_pdu; } diff --git a/src/ip.cpp b/src/ip.cpp index aa80478..e7dc320 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -395,5 +395,6 @@ void Tins::IP::copy_fields(const IP *other) { Tins::PDU *Tins::IP::clone_pdu() const { IP *new_pdu = new IP(); new_pdu->copy_fields(this); + new_pdu->copy_inner_pdu(*this); return new_pdu; } diff --git a/src/tcp.cpp b/src/tcp.cpp index 33ecd28..b2a148e 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -373,6 +373,7 @@ void Tins::TCP::copy_fields(const TCP *other) { Tins::PDU *Tins::TCP::clone_pdu() const { TCP *new_pdu = new TCP(); new_pdu->copy_fields(this); + new_pdu->copy_inner_pdu(*this); return new_pdu; } diff --git a/src/udp.cpp b/src/udp.cpp index c7cb435..a3c5453 100644 --- a/src/udp.cpp +++ b/src/udp.cpp @@ -96,5 +96,6 @@ void Tins::UDP::copy_fields(const UDP *other) { Tins::PDU *Tins::UDP::clone_pdu() const { UDP *new_pdu = new UDP(); new_pdu->copy_fields(this); + new_pdu->copy_inner_pdu(*this); return new_pdu; }