diff options
| author | Matias Fontanini <matias.fontanini@gmail.com> | 2012-10-20 11:12:59 -0300 |
|---|---|---|
| committer | Matias Fontanini <matias.fontanini@gmail.com> | 2012-10-20 11:12:59 -0300 |
| commit | 5fd892c77e2744dd2a05e4f5d8b3224d70b83483 (patch) | |
| tree | 4e42bf75290fe68d790d3c8aa0bd6714fb67d873 /src/dns_record.cpp | |
| parent | abaa2bf9265eabd448e255410533f04186a3cb9e (diff) | |
Fixed some bugs. Added documentation.v0.2
Diffstat (limited to 'src/dns_record.cpp')
| -rw-r--r-- | src/dns_record.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/dns_record.cpp b/src/dns_record.cpp index 7555e1a..e64127e 100644 --- a/src/dns_record.cpp +++ b/src/dns_record.cpp @@ -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) |
