unit testing for ptr

pull/103/head
Jeff Becker 6 years ago
parent ebb42ca46f
commit 1f104881be
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -73,22 +73,22 @@ namespace llarp
bool
DecodePTR(const Name_t& name, huint32_t& ip)
{
auto pos = name.find(".in-addr.arpa.");
if(pos == Name_t::npos)
auto pos = name.find(".in-addr.arpa");
if(pos == std::string::npos)
return false;
std::string sub = name.substr(0, pos - 1);
std::string sub = name.substr(0, pos + 1);
if(std::count(sub.begin(), sub.end(), '.') == 4)
{
uint8_t a, b, c, d;
pos = sub.find('.');
d = atoi(sub.substr(0, pos).c_str());
sub = sub.substr(pos);
sub = sub.substr(pos + 1);
pos = sub.find('.');
c = atoi(sub.substr(0, pos).c_str());
sub = sub.substr(pos);
sub = sub.substr(pos + 1);
pos = sub.find('.');
b = atoi(sub.substr(0, pos).c_str());
sub = sub.substr(pos);
sub = sub.substr(pos + 1);
pos = sub.find('.');
a = atoi(sub.substr(0, pos).c_str());
ip = llarp::ipaddr_ipv4_bits(a, b, c, d);

@ -1,6 +1,7 @@
#include <llarp/dns/dns.hpp>
#include <gtest/gtest.h>
#include <algorithm>
#include <llarp/net.hpp>
struct DNSLibTest : public ::testing::Test
{
@ -22,6 +23,14 @@ struct DNSLibTest : public ::testing::Test
}
};
TEST_F(DNSLibTest, TestPTR)
{
llarp::huint32_t ip = {0};
llarp::huint32_t expected = llarp::ipaddr_ipv4_bits(10, 10, 10, 1);
ASSERT_TRUE(llarp::dns::DecodePTR("1.10.10.10.in-addr.arpa.", ip));
ASSERT_EQ(ip, expected);
};
TEST_F(DNSLibTest, TestSerializeHeader)
{
llarp::dns::MessageHeader hdr, other;

Loading…
Cancel
Save