1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 04:34:27 +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

@@ -46,6 +46,16 @@ Tins::UDP::UDP(const uint8_t *buffer, uint32_t total_sz) : PDU(IPPROTO_UDP) {
inner_pdu(new RawPDU(buffer + sizeof(udphdr), total_sz));
}
Tins::UDP::UDP(const UDP &other) : PDU(other) {
copy_fields(&other);
}
Tins::UDP &Tins::UDP::operator= (const UDP& other) {
copy_fields(&other);
copy_inner_pdu(other);
return *this;
}
void Tins::UDP::payload(uint8_t *new_payload, uint32_t new_payload_size) {
inner_pdu(new RawPDU(new_payload, new_payload_size));
}
@@ -82,3 +92,12 @@ void Tins::UDP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PD
_udp.check = 0;
}
void Tins::UDP::copy_fields(const UDP *other) {
std::memcpy(&_udp, &other->_udp, sizeof(_udp));
}
Tins::PDU *Tins::UDP::clone_pdu() const {
UDP *new_pdu = new UDP();
new_pdu->copy_fields(this);
return new_pdu;
}