be explicit about calling string ctor at return
[ghsmtp.git] / DNS-message.hpp
blobf0d1aabdcc3c58d020c519ebc188f8bd492f5d18
1 #ifndef DNS_MESSAGE_DOT_HPP
2 #define DNS_MESSAGE_DOT_HPP
4 #include <limits>
5 #include <memory>
7 #include "DNS-rrs.hpp"
9 #include "iobuffer.hpp"
11 #include <glog/logging.h>
13 namespace Config {
14 auto constexpr max_udp_sz{uint16_t(4 * 1024)};
15 } // namespace Config
17 namespace DNS {
19 class message {
20 public:
21 using octet = unsigned char;
23 using container_t = iobuffer<octet>;
25 message() = default;
27 explicit message(container_t::size_type sz)
28 : bfr_(sz)
30 CHECK_LE(sz, std::numeric_limits<uint16_t>::max());
33 explicit message(container_t&& bfr)
34 : bfr_{std::move(bfr)}
36 CHECK_LE(size(), std::numeric_limits<uint16_t>::max());
39 uint16_t size() const { return bfr_.size(); }
41 auto begin() const { return bfr_.data(); }
42 auto end() const { return bfr_.data() + bfr_.size(); }
44 uint16_t id() const;
46 private:
47 container_t bfr_;
50 inline auto begin(message const& pkt) { return pkt.begin(); }
51 inline auto end(message const& pkt) { return pkt.end(); }
52 inline auto size(message const& pkt) { return pkt.size(); }
54 size_t min_udp_sz();
56 DNS::message
57 create_question(char const* name, DNS::RR_type type, uint16_t cls, uint16_t id);
59 void check_answer(bool& nx_domain,
60 bool& bogus_or_indeterminate,
61 uint16_t& rcode,
62 uint16_t& extended_rcode,
63 bool& authentic_data,
64 bool& has_record,
65 message const& question,
66 message const& answer,
67 RR_type type,
68 char const* name);
70 RR_collection get_records(message const& pkt, bool& bogus_or_indeterminate);
72 } // namespace DNS
74 #endif // DNS_MESSAGE_DOT_HPP