1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-26 20:01:35 +01:00

Add input memory stream class and port some PDUs to use it

This commit is contained in:
Matias Fontanini
2015-12-24 15:21:07 -08:00
parent 6d90b0ce32
commit 13c05fbdb1
20 changed files with 408 additions and 295 deletions

View File

@@ -32,23 +32,25 @@
#include <cassert>
#include "bootp.h"
#include "exceptions.h"
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
namespace Tins{
BootP::BootP()
: _vend(64) {
std::memset(&_bootp, 0, sizeof(bootphdr));
: _bootp(), _vend(64) {
}
BootP::BootP(const uint8_t *buffer, uint32_t total_sz, uint32_t vend_field_size)
: _vend(vend_field_size)
{
if(total_sz < sizeof(bootphdr) + vend_field_size)
throw malformed_packet();
std::memcpy(&_bootp, buffer, sizeof(bootphdr));
InputMemoryStream stream(buffer, total_sz);
stream.read(_bootp);
buffer += sizeof(bootphdr);
total_sz -= sizeof(bootphdr);
_vend.assign(buffer, buffer + vend_field_size);
// Maybe RawPDU on what is left on the buffer?...
_vend.assign(stream.pointer(), stream.pointer() + vend_field_size);
}
uint32_t BootP::header_size() const {