hello-dns/tdns/dns-types.cc
2018-04-09 23:04:13 +02:00

54 lines
1.3 KiB
C++

#include "dns-types.hh"
std::unique_ptr<RRGenerator> AGenerator::make(const ComboAddress& ca)
{
return std::move(std::make_unique<AGenerator>(ca.sin4.sin_addr.s_addr));
}
void AGenerator::toMessage(DNSMessageWriter& dmw)
{
dmw.payload.putUInt32(d_ip);
}
std::unique_ptr<RRGenerator> AAAAGenerator::make(const ComboAddress& ca)
{
if(ca.sin4.sin_family != AF_INET6)
throw std::runtime_error("This was not an IPv6 address in AAAA generator");
auto p = (const unsigned char*)ca.sin6.sin6_addr.s6_addr;
unsigned char ip[16];
memcpy(&ip, p, 16);
return std::move(std::make_unique<AAAAGenerator>(ip));
}
void AAAAGenerator::toMessage(DNSMessageWriter& dmw)
{
dmw.payload.putBlob(d_ip, 16);
}
void SOAGenerator::toMessage(DNSMessageWriter& dmw)
{
putName(dmw.payload, d_mname); putName(dmw.payload, d_rname);
dmw.payload.putUInt32(d_serial); dmw.payload.putUInt32(d_refresh);
dmw.payload.putUInt32(d_retry); dmw.payload.putUInt32(d_expire);
dmw.payload.putUInt32(d_minimum);
}
void NameGenerator::toMessage(DNSMessageWriter& dmw)
{
putName(dmw.payload, d_name);
}
void MXGenerator::toMessage(DNSMessageWriter& dmw)
{
dmw.payload.putUInt16(d_prio);
putName(dmw.payload, d_name);
}
void TXTGenerator::toMessage(DNSMessageWriter& dmw)
{
// XXX should autosplit
dmw.payload.putUInt8(d_txt.length());
dmw.payload.putBlob(d_txt);
}