sp
[ghsmtp.git] / DNS-iostream.hpp
blob85d5880f02f008017cfb95839af36ae8859c38e0
1 #ifndef DNS_IOSTREAM_DOT_HPP
2 #define DNS_IOSTREAM_DOT_HPP
4 #include "DNS-rrs.hpp"
6 #include <iostream>
8 inline std::ostream& operator<<(std::ostream& os, DNS::RR_A const& rr_a)
10 return os << "A " << rr_a.c_str();
13 inline std::ostream& operator<<(std::ostream& os, DNS::RR_CNAME const& rr_c)
15 return os << "CNAME " << rr_c.str();
18 inline std::ostream& operator<<(std::ostream& os, DNS::RR_PTR const& rr_ptr)
20 return os << "PTR " << rr_ptr.str();
23 inline std::ostream& operator<<(std::ostream& os, DNS::RR_MX const& rr_mx)
25 return os << "MX " << rr_mx.preference() << ' ' << rr_mx.exchange();
28 inline std::ostream& operator<<(std::ostream& os, DNS::RR_TXT const& rr_txt)
30 return os << "TXT " << rr_txt.str();
33 inline std::ostream& operator<<(std::ostream& os, DNS::RR_AAAA const& rr_aaaa)
35 return os << "AAAA " << rr_aaaa.c_str();
38 inline std::ostream& operator<<(std::ostream& os, DNS::RR_TLSA const& rr_tlsa)
40 os << "TLSA " << rr_tlsa.cert_usage() << ' ' << rr_tlsa.selector() << ' '
41 << rr_tlsa.matching_type() << ' ';
43 for (auto const ch : rr_tlsa.assoc_data()) {
44 auto const lo = ch & 0xF;
45 auto const hi = (ch >> 4) & 0xF;
47 auto constexpr hex_digits = "0123456789abcdef";
49 os << hex_digits[hi] << hex_digits[lo];
52 return os;
55 inline std::ostream& operator<<(std::ostream& os, DNS::RR_type const& type)
57 return os << DNS::RR_type_c_str(type);
60 #endif // DNS_IOSTREAM_DOT_HPP