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

@@ -39,30 +39,28 @@
#include "exceptions.h"
#include "rawpdu.h"
#include "endianness.h"
#include "memory_helpers.h"
using std::string;
using std::list;
using Tins::Memory::InputMemoryStream;
namespace Tins {
DNS::DNS()
: answers_idx(), authority_idx(), additional_idx()
: dns(), answers_idx(), authority_idx(), additional_idx()
{
std::memset(&dns, 0, sizeof(dns));
}
DNS::DNS(const uint8_t *buffer, uint32_t total_sz)
: answers_idx(), authority_idx(), additional_idx()
{
if(total_sz < sizeof(dnshdr))
throw malformed_packet();
std::memcpy(&dns, buffer, sizeof(dnshdr));
records_data.assign(
buffer + sizeof(dnshdr),
buffer + total_sz
);
InputMemoryStream stream(buffer, total_sz);
stream.read(dns);
records_data.assign(stream.pointer(), stream.pointer() + stream.size());
// Avoid doing this if there's no data. Otherwise VS's asserts fail.
if(!records_data.empty()) {
if (!records_data.empty()) {
buffer = &records_data[0];
const uint8_t *end = &records_data[0] + records_data.size(), *prev_start = buffer;
uint16_t nquestions = questions_count();