2018-12-12 00:58:08 +00:00
|
|
|
#include <dns/rr.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
|
|
|
|
#include <util/logger.hpp>
|
2018-12-03 22:22:59 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dns
|
|
|
|
{
|
2018-12-04 16:16:43 +00:00
|
|
|
ResourceRecord::ResourceRecord(const ResourceRecord& other)
|
|
|
|
: rr_name(other.rr_name)
|
|
|
|
, rr_type(other.rr_type)
|
|
|
|
, rr_class(other.rr_class)
|
|
|
|
, ttl(other.ttl)
|
|
|
|
, rData(other.rData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceRecord::ResourceRecord(ResourceRecord&& other)
|
|
|
|
: rr_name(std::move(other.rr_name))
|
|
|
|
, rr_type(std::move(other.rr_type))
|
|
|
|
, rr_class(std::move(other.rr_class))
|
|
|
|
, ttl(std::move(other.ttl))
|
|
|
|
, rData(std::move(other.rData))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-03 22:22:59 +00:00
|
|
|
bool
|
|
|
|
ResourceRecord::Encode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!EncodeName(buf, rr_name))
|
2018-12-04 16:16:43 +00:00
|
|
|
{
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
if(!llarp_buffer_put_uint16(buf, rr_type))
|
|
|
|
{
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
if(!llarp_buffer_put_uint16(buf, rr_class))
|
|
|
|
{
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
if(!llarp_buffer_put_uint32(buf, ttl))
|
|
|
|
{
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
if(!EncodeRData(buf, rData))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2018-12-03 22:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ResourceRecord::Decode(llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
if(!DecodeName(buf, rr_name))
|
2018-12-04 16:16:43 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("failed to decode rr name");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!llarp_buffer_read_uint16(buf, &rr_type))
|
|
|
|
{
|
|
|
|
llarp::LogError("failed to decode rr type");
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
if(!llarp_buffer_read_uint16(buf, &rr_class))
|
|
|
|
{
|
|
|
|
llarp::LogError("failed to decode rr class");
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
if(!llarp_buffer_read_uint32(buf, &ttl))
|
|
|
|
{
|
|
|
|
llarp::LogError("failed to decode ttl");
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
if(!DecodeRData(buf, rData))
|
|
|
|
{
|
|
|
|
llarp::LogError("failed to decode rr rdata");
|
2018-12-03 22:22:59 +00:00
|
|
|
return false;
|
2018-12-04 16:16:43 +00:00
|
|
|
}
|
|
|
|
return true;
|
2018-12-03 22:22:59 +00:00
|
|
|
}
|
|
|
|
} // namespace dns
|
|
|
|
} // namespace llarp
|