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

Removed copy constructor from several PDUs.

This commit is contained in:
Matias Fontanini
2011-09-08 10:18:15 -03:00
parent f30f404632
commit b17ee6a6cb
7 changed files with 44 additions and 51 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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.");

View File

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

View File

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