1 #include "DNS-fcrdns.hpp"
2 #include "DNS-iostream.hpp"
3 #include "DNS-ldns.hpp"
10 #include <glog/logging.h>
12 template <typename
... Ts
>
13 std::ostream
& operator<<(std::ostream
& os
, const std::variant
<Ts
...>& v
)
15 std::visit([&os
](auto&& arg
) { os
<< arg
; }, v
);
19 int main(int argc
, char const* argv
[])
21 auto const config_path
= osutil::get_config_dir();
23 DNS::Resolver
res(config_path
);
24 DNS_ldns::Resolver res_ldns
;
32 {DNS::RR_type::A
, "amazon.com"},
33 {DNS::RR_type::A
, "dee.test.digilicious.com"},
34 {DNS::RR_type::A
, "does-not-exist.test.digilicious.com"},
35 {DNS::RR_type::A
, "google-public-dns-a.google.com"},
36 {DNS::RR_type::A
, "google-public-dns-b.google.com"},
37 {DNS::RR_type::AAAA
, "google-public-dns-a.google.com"},
38 {DNS::RR_type::AAAA
, "google-public-dns-b.google.com"},
39 {DNS::RR_type::CNAME
, "cname4.digilicious.com"},
40 {DNS::RR_type::CNAME
, "com.digilicious.in-addr.arpa"},
41 {DNS::RR_type::MX
, "anyold.host"},
42 {DNS::RR_type::MX
, "cname.test.digilicious.com"},
43 {DNS::RR_type::PTR
, "com.digilicious.in-addr.arpa"},
44 {DNS::RR_type::PTR
, "com.google.in-addr.arpa"},
45 {DNS::RR_type::TLSA
, "_25._tcp.digilicious.com"},
46 {DNS::RR_type::TLSA
, "_443._tcp.digilicious.com"},
47 {DNS::RR_type::TXT
, "digilicious.com"},
50 for (auto const& lookup
: lookups
) {
51 DNS::Query
q(res
, lookup
.typ
, lookup
.name
);
52 DNS_ldns::Query
q_ldns(res_ldns
, lookup
.typ
, lookup
.name
);
54 CHECK_EQ(q
.nx_domain(), q_ldns
.nx_domain()) << lookup
.name
;
56 CHECK_EQ(q
.bogus_or_indeterminate(), q_ldns
.bogus_or_indeterminate())
59 CHECK_EQ(q
.authentic_data(), q_ldns
.authentic_data()) << lookup
.name
;
61 auto rrs
{q
.get_records()};
62 auto rrs_ldns
{q_ldns
.get_records()};
64 CHECK_EQ(size(rrs
), size(rrs_ldns
));
66 std::sort(begin(rrs
), end(rrs
));
67 std::sort(begin(rrs_ldns
), end(rrs_ldns
));
70 std::mismatch(begin(rrs
), end(rrs
), begin(rrs_ldns
), end(rrs_ldns
));
72 LOG(FATAL
) << *rr
<< " != " << *rr_ldns
;
76 // These IP addresses might be stable for a while.
78 auto const goog_a
{"google-public-dns-a.google.com"};
79 auto const goog_b
{"google-public-dns-b.google.com"};
81 auto const aaaaddrs_a
{res
.get_strings(DNS::RR_type::AAAA
, goog_a
)};
82 CHECK_EQ(aaaaddrs_a
.size(), 1U);
83 CHECK_EQ(aaaaddrs_a
[0], "2001:4860:4860::8888");
85 auto const aaaaddrs_b
{res
.get_strings(DNS::RR_type::AAAA
, goog_b
)};
86 CHECK_EQ(aaaaddrs_b
.size(), 1U);
87 CHECK_EQ(aaaaddrs_b
[0], "2001:4860:4860::8844");
89 auto const addrs_a
{res
.get_strings(DNS::RR_type::A
, goog_a
)};
90 CHECK_EQ(addrs_a
.size(), 1U);
91 CHECK_EQ(addrs_a
[0], "8.8.8.8");
93 auto const addrs_b
{res
.get_strings(DNS::RR_type::A
, goog_b
)};
94 CHECK_EQ(addrs_b
.size(), 1U);
95 CHECK_EQ(addrs_b
[0], "8.8.4.4");
97 auto const fcrdnses4
{fcrdns4(res
, "1.1.1.1")};
98 CHECK_EQ(fcrdnses4
.size(), 1);
99 CHECK_EQ(fcrdnses4
.front(), "one.one.one.one")
100 << "no match for " << fcrdnses4
.front();
102 auto const fcrdnses6
{fcrdns6(res
, "2606:4700:4700::1111")};
103 CHECK_EQ(fcrdnses6
.size(), 1);
104 CHECK_EQ(fcrdnses6
.front(), "one.one.one.one")
105 << "no match for " << fcrdnses6
.front();
107 auto const quad9
{fcrdns4(res
, "9.9.9.9")};
108 CHECK_EQ(quad9
.front(), "dns9.quad9.net") << "no match for " << quad9
.front();