mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 13:04:28 +01:00
Fixed some bugs. Added documentation.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <typeinfo>
|
||||
#include "dns_record.h"
|
||||
#include "endianness.h"
|
||||
@@ -50,10 +51,11 @@ DNSResourceRecord::DNSResourceRecord(DNSRRImpl *impl,
|
||||
DNSResourceRecord::DNSResourceRecord(const uint8_t *buffer, uint32_t size)
|
||||
{
|
||||
const uint8_t *buffer_end = buffer + size;
|
||||
std::auto_ptr<DNSRRImpl> tmp_impl;
|
||||
if((*buffer & 0xc0)) {
|
||||
uint16_t offset(*reinterpret_cast<const uint16_t*>(buffer));
|
||||
offset = Endian::be_to_host(offset) & 0x3fff;
|
||||
impl = new OffsetedDNSRRImpl(Endian::host_to_be(offset));
|
||||
tmp_impl.reset(new OffsetedDNSRRImpl(Endian::host_to_be(offset)));
|
||||
buffer += sizeof(uint16_t);
|
||||
}
|
||||
else {
|
||||
@@ -63,7 +65,7 @@ DNSResourceRecord::DNSResourceRecord(const uint8_t *buffer, uint32_t size)
|
||||
if(str_end == buffer_end)
|
||||
throw std::runtime_error("Not enough size for a resource domain name.");
|
||||
//str_end++;
|
||||
impl = new NamedDNSRRImpl(buffer, str_end);
|
||||
tmp_impl.reset(new NamedDNSRRImpl(buffer, str_end));
|
||||
buffer = ++str_end;
|
||||
}
|
||||
if(buffer + sizeof(info_) > buffer_end)
|
||||
@@ -86,6 +88,7 @@ DNSResourceRecord::DNSResourceRecord(const uint8_t *buffer, uint32_t size)
|
||||
*(uint32_t*)&data[0] = *(uint32_t*)buffer;
|
||||
else
|
||||
throw std::runtime_error("Not enough size for resource data");
|
||||
impl = tmp_impl.release();
|
||||
}
|
||||
|
||||
DNSResourceRecord::DNSResourceRecord(const DNSResourceRecord &rhs)
|
||||
|
||||
@@ -77,7 +77,7 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
|
||||
buffer += head_len() * sizeof(uint32_t);
|
||||
|
||||
_options_size = 0;
|
||||
_padded_options_size = head_len() * sizeof(uint32_t) - sizeof(iphdr);
|
||||
//_padded_options_size = head_len() * sizeof(uint32_t) - sizeof(iphdr);
|
||||
/* While the end of the options is not reached read an option */
|
||||
while (ptr_buffer < buffer && (*ptr_buffer != 0)) {
|
||||
//ip_option opt_to_add;
|
||||
@@ -126,6 +126,8 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
_options_size += _ip_options.back().data_size() + 2;
|
||||
}
|
||||
uint8_t padding = _options_size % 4;
|
||||
_padded_options_size = padding ? (_options_size - padding + 4) : _options_size;
|
||||
// check this line PLX
|
||||
total_sz -= head_len() * sizeof(uint32_t);
|
||||
if (total_sz) {
|
||||
@@ -304,7 +306,7 @@ uint16_t IP::stream_identifier() const {
|
||||
void IP::add_option(const ip_option &option) {
|
||||
_ip_options.push_back(option);
|
||||
_options_size += 1 + option.data_size();
|
||||
uint8_t padding = _options_size & 3;
|
||||
uint8_t padding = _options_size % 4;
|
||||
_padded_options_size = padding ? (_options_size - padding + 4) : _options_size;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,21 +51,20 @@ RSNInformation::RSNInformation(const uint8_t *buffer, uint32_t total_sz) {
|
||||
|
||||
void RSNInformation::init(const uint8_t *buffer, uint32_t total_sz) {
|
||||
const char *err_msg = "Malformed RSN information structure";
|
||||
check_size<uint16_t>(total_sz, err_msg);
|
||||
if(total_sz <= sizeof(uint16_t) * 2 + sizeof(uint32_t))
|
||||
throw std::runtime_error(err_msg);
|
||||
version(Endian::le_to_host(*(uint16_t*)buffer));
|
||||
buffer += sizeof(uint16_t);
|
||||
total_sz -= sizeof(uint16_t);
|
||||
group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer);
|
||||
|
||||
check_size<uint32_t>(total_sz, err_msg);
|
||||
group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer);
|
||||
buffer += sizeof(uint32_t);
|
||||
total_sz -= sizeof(uint32_t);
|
||||
|
||||
check_size<uint16_t>(total_sz, err_msg);
|
||||
|
||||
uint16_t count = *(uint16_t*)buffer;
|
||||
buffer += sizeof(uint16_t);
|
||||
total_sz -= sizeof(uint16_t);
|
||||
|
||||
if(count * sizeof(uint32_t) > total_sz)
|
||||
throw std::runtime_error(err_msg);
|
||||
total_sz -= count * sizeof(uint32_t);
|
||||
|
||||
Reference in New Issue
Block a user