mirror of
https://github.com/mfontanini/libtins
synced 2026-01-27 04:11:35 +01:00
Port all PDUs to use InputMemoryStream on constructors from buffer
This commit is contained in:
@@ -32,30 +32,29 @@
|
||||
#include "exceptions.h"
|
||||
#include "pktap.h"
|
||||
#include "internals.h"
|
||||
#include "memory_helpers.h"
|
||||
|
||||
using Tins::Memory::InputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
|
||||
PKTAP::PKTAP() {
|
||||
memset(&header_, 0, sizeof(header_));
|
||||
PKTAP::PKTAP() : header_() {
|
||||
}
|
||||
|
||||
PKTAP::PKTAP(const uint8_t* buffer, uint32_t total_sz) {
|
||||
if (total_sz < sizeof(pktap_header)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
memcpy(&header_, buffer, sizeof(header_));
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.read(header_);
|
||||
uint32_t header_length = header_.length;
|
||||
if (header_length > total_sz) {
|
||||
if (header_length > total_sz || header_length < sizeof(header_)) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
buffer += header_length;
|
||||
total_sz -= header_length;
|
||||
if (header_.next && total_sz > 0) {
|
||||
stream.skip(header_length - sizeof(header_));
|
||||
if (header_.next && stream) {
|
||||
inner_pdu(
|
||||
Internals::pdu_from_dlt_flag(
|
||||
header_.dlt,
|
||||
buffer,
|
||||
total_sz
|
||||
stream.pointer(),
|
||||
stream.size()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user