mirror of
https://github.com/mfontanini/libtins
synced 2026-01-30 13:34:27 +01:00
Added support for IPv6 addresses in DNS.
This commit is contained in:
17
src/dns.cpp
17
src/dns.cpp
@@ -34,6 +34,7 @@
|
||||
#include <memory>
|
||||
#include "dns.h"
|
||||
#include "ip_address.h"
|
||||
#include "ipv6_address.h"
|
||||
|
||||
using std::string;
|
||||
using std::list;
|
||||
@@ -166,6 +167,13 @@ void DNS::add_answer(const string &name, const DNSResourceRecord::info &info,
|
||||
dns.answers = Endian::host_to_be<uint16_t>(ans.size());
|
||||
}
|
||||
|
||||
void DNS::add_answer(const string &name, const DNSResourceRecord::info &info,
|
||||
address_v6_type ip)
|
||||
{
|
||||
ans.push_back(make_record(name, info, ip.begin(), address_v6_type::address_size));
|
||||
dns.answers = Endian::host_to_be<uint16_t>(ans.size());
|
||||
}
|
||||
|
||||
void DNS::add_answer(const std::string &name, const DNSResourceRecord::info &info,
|
||||
const std::string &dname)
|
||||
{
|
||||
@@ -433,14 +441,7 @@ void DNS::convert_resources(const ResourcesType &lst, std::list<Resource> &res)
|
||||
if(Endian::be_to_host(it->information().type) == DNS::AAAA) {
|
||||
if(sz != 16)
|
||||
throw std::runtime_error("Malformed IPv6 address");
|
||||
std::ostringstream oss;
|
||||
oss << std::hex;
|
||||
for(size_t i = 0; i < 16; i += 2) {
|
||||
oss << (int)ptr[i] << (int)ptr[i+1];
|
||||
if(i != 14)
|
||||
oss << ':';
|
||||
}
|
||||
addr = oss.str();
|
||||
addr = IPv6Address(ptr).to_string();
|
||||
}
|
||||
else
|
||||
compose_name(ptr, sz, addr);
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace Tins {
|
||||
std::fill(address, address + address_size, 0);
|
||||
}
|
||||
|
||||
IPv6Address::IPv6Address(const_iterator ptr) {
|
||||
std::copy(ptr, ptr + address_size, address);
|
||||
}
|
||||
|
||||
IPv6Address::IPv6Address(const std::string &addr) {
|
||||
if(inet_pton(AF_INET6, addr.c_str(), address) == 0)
|
||||
throw malformed_address();
|
||||
|
||||
Reference in New Issue
Block a user