-
Notifications
You must be signed in to change notification settings - Fork 3
/
DNS-iostream.hpp
61 lines (46 loc) · 1.47 KB
/
DNS-iostream.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef DNS_IOSTREAM_DOT_HPP
#define DNS_IOSTREAM_DOT_HPP
#include "DNS-rrs.hpp"
#include <iostream>
inline std::ostream& operator<<(std::ostream& os, DNS::RR_A const& rr_a)
{
return os << "A " << rr_a.c_str();
}
inline std::ostream& operator<<(std::ostream& os, DNS::RR_CNAME const& rr_c)
{
return os << "CNAME " << rr_c.str();
}
inline std::ostream& operator<<(std::ostream& os, DNS::RR_PTR const& rr_ptr)
{
return os << "PTR " << rr_ptr.str();
}
inline std::ostream& operator<<(std::ostream& os, DNS::RR_MX const& rr_mx)
{
return os << "MX " << rr_mx.preference() << ' ' << rr_mx.exchange();
}
inline std::ostream& operator<<(std::ostream& os, DNS::RR_TXT const& rr_txt)
{
return os << "TXT " << rr_txt.str();
}
inline std::ostream& operator<<(std::ostream& os, DNS::RR_AAAA const& rr_aaaa)
{
return os << "AAAA " << rr_aaaa.c_str();
}
inline std::ostream& operator<<(std::ostream& os, DNS::RR_TLSA const& rr_tlsa)
{
os << "TLSA " << rr_tlsa.cert_usage() << ' ' << rr_tlsa.selector() << ' '
<< rr_tlsa.matching_type() << ' ';
for (auto const& ch : rr_tlsa.assoc_data()) {
auto const lo = ch & 0xF;
auto const hi = (ch >> 4) & 0xF;
using namespace std::literals::string_view_literals;
auto constexpr hex_digits{"0123456789abcdef"sv};
os << hex_digits[hi] << hex_digits[lo];
}
return os;
}
inline std::ostream& operator<<(std::ostream& os, DNS::RR_type const& type)
{
return os << DNS::RR_type_c_str(type);
}
#endif // DNS_IOSTREAM_DOT_HPP