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

Fixed/added copy constructor to IP/TCP/UDP/ARP/EthernetII PDUs.

This commit is contained in:
Matias Fontanini
2012-03-24 01:27:22 -03:00
parent 594eabd282
commit e6ccdcd75e
9 changed files with 39 additions and 0 deletions

View File

@@ -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 */
/**

View File

@@ -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 */
/**

View File

@@ -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.
*

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}