mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
RawPDU now can copy the payload. Modified PDU::clone_inner_pdu to use this.
This commit is contained in:
@@ -37,13 +37,28 @@ namespace Tins {
|
|||||||
public:
|
public:
|
||||||
/** \brief Creates an instance of RawPDU.
|
/** \brief Creates an instance of RawPDU.
|
||||||
*
|
*
|
||||||
* The payload is NOT copied. Therefore, it must be manually freed by the user.
|
* The payload is not copied by default, therefore it must be
|
||||||
* \param payload The payload which the RawPDU will contain.
|
* manually freed by the user. If the payload was to be copied,
|
||||||
|
* then the copy flag must be set to true.
|
||||||
|
* \param pload The payload which the RawPDU will contain.
|
||||||
* \param size The size of the payload.
|
* \param size The size of the payload.
|
||||||
|
* \param copy Flag indicating wether to copy the payload.
|
||||||
*/
|
*/
|
||||||
|
RawPDU(uint8_t *pload, uint32_t size, bool copy = false);
|
||||||
|
|
||||||
RawPDU(uint8_t *payload, uint32_t size);
|
/** \brief RawPDU destructor.
|
||||||
|
*
|
||||||
|
* Deletes the payload only if it was created setting the copy
|
||||||
|
* flag to true.
|
||||||
|
*/
|
||||||
|
~RawPDU();
|
||||||
|
|
||||||
|
/** \brief Getter for the payload.
|
||||||
|
*
|
||||||
|
* \return The RawPDU's payload.
|
||||||
|
*/
|
||||||
|
const uint8_t *payload() const { return _payload; }
|
||||||
|
|
||||||
/** \brief Returns the header size.
|
/** \brief Returns the header size.
|
||||||
*
|
*
|
||||||
* This metod overrides PDU::header_size. \sa PDU::header_size
|
* This metod overrides PDU::header_size. \sa PDU::header_size
|
||||||
@@ -55,12 +70,12 @@ namespace Tins {
|
|||||||
* \sa PDU::pdu_type
|
* \sa PDU::pdu_type
|
||||||
*/
|
*/
|
||||||
PDUType pdu_type() const { return PDU::RAW; }
|
PDUType pdu_type() const { return PDU::RAW; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
|
||||||
|
|
||||||
uint8_t *_payload;
|
uint8_t *_payload;
|
||||||
uint32_t _payload_size;
|
uint32_t _payload_size;
|
||||||
|
bool _owns_payload;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ Tins::PDU *Tins::PDU::clone_inner_pdu(uint8_t *ptr, uint32_t total_sz) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
child = new RawPDU(ptr, total_sz);
|
child = new RawPDU(ptr, total_sz, true);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,18 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "rawpdu.h"
|
#include "rawpdu.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
Tins::RawPDU::RawPDU(uint8_t *payload, uint32_t size) : PDU(255), _payload(payload), _payload_size(size) {
|
Tins::RawPDU::RawPDU(uint8_t *pload, uint32_t size, bool copy) : PDU(255), _payload(pload), _payload_size(size), _owns_payload(copy) {
|
||||||
|
if(copy) {
|
||||||
|
_payload = new uint8_t[size];
|
||||||
|
std::memcpy(_payload, pload, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Tins::RawPDU::~RawPDU() {
|
||||||
|
if(_owns_payload)
|
||||||
|
delete[] _payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Tins::RawPDU::header_size() const {
|
uint32_t Tins::RawPDU::header_size() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user