From b17ee6a6cbca0022999e8e396aa6daee60a38ac9 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Thu, 8 Sep 2011 10:18:15 -0300 Subject: [PATCH] Removed copy constructor from several PDUs. --- include/arp.h | 10 ---------- include/icmp.h | 10 ---------- include/pdu.h | 47 +++++++++++++++++++++++++++++++++++++---------- src/arp.cpp | 10 ---------- src/icmp.cpp | 10 ---------- src/pdu.cpp | 6 ++++++ src/tcp.cpp | 2 +- 7 files changed, 44 insertions(+), 51 deletions(-) diff --git a/include/arp.h b/include/arp.h index 50d8d7d..f15f947 100644 --- a/include/arp.h +++ b/include/arp.h @@ -60,16 +60,6 @@ namespace Tins { */ ARP(const uint8_t *buffer, uint32_t total_sz); - /** - * \brief Copy constructor. - */ - ARP(const ARP &other); - - /** - * \brief Copy asignment operator. - */ - ARP &operator= (const ARP &other); - /* Getters */ /** * \brief Getter for the sender's hardware address. diff --git a/include/icmp.h b/include/icmp.h index 5ee7d56..9340248 100644 --- a/include/icmp.h +++ b/include/icmp.h @@ -56,16 +56,6 @@ namespace Tins { * \param flag The type flag which will be set. */ ICMP(Flags flag = ECHO_REQUEST); - - /** - * \brief Copy constructor. - */ - ICMP(const ICMP &other); - - /** - * \brief Copy assignment operator. - */ - ICMP &operator= (const ICMP &other); /** * \brief Constructor which creates an ICMP object from a buffer and adds all identifiable diff --git a/include/pdu.h b/include/pdu.h index 137c2ef..77f7c10 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -52,16 +52,26 @@ namespace Tins { enum PDUType { RAW, ETHERNET_II, - DOT11, - DOT11_DATA, - DOT11_QOS_DATA, - DOT11_BEACON, - DOT11_CONTROL, - DOT11_ACK, - DOT11_BLOCK_ACK, - DOT11_RTS, - SNAP, RADIOTAP, + DOT11, + DOT11_ACK, + DOT11_ASSOC_REQ, + DOT11_ASSOC_RESP, + DOT11_BEACON, + DOT11_BLOCK_ACK, + DOT11_CFEND, + DOT11_DATA, + DOT11_CONTROL, + DOT11_DEAUTH, + DOT11_DIASSOC, + DOT11_ENDCFACK, + DOT11_MANAGEMENT, + DOT11_PROBE_REQ, + DOT11_PROBE_RESP, + DOT11_PS_POLL, + DOT11_RTS, + DOT11_QOS_DATA, + SNAP, IP, ARP, TCP, @@ -205,6 +215,18 @@ namespace Tins { * \param total_sz The size of the buffer. */ virtual bool matches_response(uint8_t *ptr, uint32_t total_sz) { return false; } + + /** + * \brief Check wether this PDU matches the specified flag. + * + * This method should be reimplemented in PDU classes which have + * subclasses, and try to match the given PDU to each of its parent + * classes' flag. + * \param flag The flag to match. + */ + virtual bool matches_flag(PDUType flag) { + return flag == pdu_type(); + } /** * \brief Getter for the PDU's type. @@ -223,10 +245,15 @@ namespace Tins { virtual PDU *clone_packet(const uint8_t *ptr, uint32_t total_sz) { return 0; } protected: /** - * \brief Copy consstructor. + * \brief Copy constructor. */ PDU(const PDU &other); + /** + * \brief Copy assignment operator. + */ + PDU &operator=(const PDU &other); + /** * \brief Copy other PDU's inner PDU(if any). * \param pdu The PDU from which to copy the inner PDU. diff --git a/src/arp.cpp b/src/arp.cpp index 0a71b13..ba9e801 100644 --- a/src/arp.cpp +++ b/src/arp.cpp @@ -55,16 +55,6 @@ Tins::ARP::ARP(const uint8_t *buffer, uint32_t total_sz) : PDU(0x0608) { inner_pdu(new RawPDU(buffer + sizeof(arphdr), total_sz)); } -Tins::ARP::ARP(const ARP &other) : PDU(other) { - copy_fields(&other); -} - -Tins::ARP &Tins::ARP::operator= (const ARP &other) { - copy_fields(&other); - copy_inner_pdu(other); - return *this; -} - Tins::ARP::ARP(const arphdr *arp_ptr) : PDU(Utils::net_to_host_s(0x0806)) { memcpy(&_arp, arp_ptr, sizeof(arphdr)); } diff --git a/src/icmp.cpp b/src/icmp.cpp index ff5e3c2..8791cad 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -48,16 +48,6 @@ 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."); diff --git a/src/pdu.cpp b/src/pdu.cpp index 2ec2d40..f45817e 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -34,6 +34,12 @@ Tins::PDU::PDU(const PDU &other) : _inner_pdu(0) { copy_inner_pdu(other); } +Tins::PDU &Tins::PDU::operator=(const PDU &other) { + _flag = other.flag(); + copy_inner_pdu(other); + return *this; +} + Tins::PDU::~PDU() { delete _inner_pdu; } diff --git a/src/tcp.cpp b/src/tcp.cpp index c17a580..bc6655b 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -47,8 +47,8 @@ Tins::TCP::TCP(const TCP &other) : PDU(other) { } Tins::TCP &Tins::TCP::operator= (const TCP &other) { + PDU::operator=(other); copy_fields(&other); - copy_inner_pdu(other); return *this; }