1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 12:44:25 +01:00

Added copy constructor and copy assignment operator to all PDUs.

This commit is contained in:
Matias Fontanini
2011-09-03 18:58:57 -03:00
parent fdcefd2132
commit 3178c217b3
22 changed files with 615 additions and 22 deletions

View File

@@ -48,6 +48,16 @@ Tins::ICMP::ICMP(Flags flag) : PDU(IPPROTO_ICMP) {
};
}
Tins::ICMP::ICMP(const ICMP &other) : PDU(other) {
copy_fields(&other);
}
Tins::ICMP &Tins::ICMP::operator= (const ICMP &other) {
copy_fields(&other);
copy_inner_pdu(other);
return *this;
}
Tins::ICMP::ICMP(const uint8_t *buffer, uint32_t total_sz) : PDU(IPPROTO_ICMP) {
if(total_sz < sizeof(icmphdr))
throw std::runtime_error("Not enough size for an ICMP header in the buffer.");
@@ -199,3 +209,13 @@ Tins::PDU *Tins::ICMP::clone_packet(const uint8_t *ptr, uint32_t total_sz) {
cloned->inner_pdu(child);
return cloned;
}
void Tins::ICMP::copy_fields(const ICMP *other) {
std::memcpy(&_icmp, &other->_icmp, sizeof(_icmp));
}
Tins::PDU *Tins::ICMP::clone_pdu() const {
ICMP *new_pdu = new ICMP();
new_pdu->copy_fields(this);
return new_pdu;
}