1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-28 12:44:25 +01:00

Added PDUAllocator class, which makes extending PDUs easier.

This commit is contained in:
Matias Fontanini
2013-08-29 23:31:10 -03:00
parent 4ca21bdad7
commit 5f2c923c48
10 changed files with 438 additions and 20 deletions

View File

@@ -48,6 +48,7 @@
#include "icmpv6.h"
#include "rawpdu.h"
#include "exceptions.h"
#include "pdu_allocator.h"
namespace Tins {
@@ -101,7 +102,15 @@ IPv6::IPv6(const uint8_t *buffer, uint32_t total_sz)
inner_pdu(new Tins::ICMPv6(buffer, total_sz));
break;
default:
inner_pdu(new Tins::RawPDU(buffer, total_sz));
inner_pdu(
Internals::allocate<IPv6>(
current_header,
buffer,
total_sz
)
);
if(!inner_pdu())
inner_pdu(new Tins::RawPDU(buffer, total_sz));
break;
}
total_sz = 0;
@@ -214,10 +223,13 @@ void IPv6::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *pa
new_flag = Constants::IP::PROTO_ICMPV6;
break;
default:
if(Internals::pdu_type_registered<IPv6>(inner_pdu()->pdu_type()))
new_flag = static_cast<Constants::IP::e>(
Internals::pdu_type_to_id<IPv6>(inner_pdu()->pdu_type())
);
break;
};
if(new_flag != 0xff)
set_last_next_header(new_flag);
set_last_next_header(new_flag);
}
payload_length(total_sz - sizeof(_header));
std::memcpy(buffer, &_header, sizeof(_header));