38 #include <tins/macros.h> 40 #include <tins/endianness.h> 53 class InputMemoryStream;
188 : name_(
std::move(nm)), type_(tp), qclass_(cl) {}
191 : name_(nm), type_(tp), qclass_(cl) {}
299 soa_record(
const uint8_t* buffer, uint32_t total_sz);
313 const std::string& rname,
318 uint32_t minimum_ttl);
386 void mname(
const std::string& value);
392 void rname(
const std::string& value);
398 void serial(uint32_t value);
404 void refresh(uint32_t value);
410 void retry(uint32_t value);
416 void expire(uint32_t value);
422 void minimum_ttl(uint32_t value);
430 void init(
const uint8_t* buffer, uint32_t total_sz);
438 uint32_t minimum_ttl_;
462 uint16_t preference = 0)
463 : dname_(
std::move(dname)), data_(
std::move(data)), type_(type),
464 qclass_(rclass), ttl_(ttl), preference_(preference) {}
467 const std::string& data,
471 uint16_t preference = 0)
472 : dname_(dname), data_(data), type_(type), qclass_(rclass),
473 ttl_(ttl), preference_(preference) {}
476 resource() : type_(), qclass_(), ttl_(), preference_() {}
491 const std::string&
data()
const {
540 void dname(
const std::string& data) {
556 void data(
const std::string& data) {
566 data_.assign(buffer.begin(), buffer.end());
611 std::string dname_, data_;
612 uint16_t type_, qclass_;
614 uint16_t preference_;
617 TINS_DEPRECATED(
typedef query Query);
618 TINS_DEPRECATED(
typedef resource Resource);
620 typedef std::vector<query> queries_type;
621 typedef std::vector<resource> resources_type;
631 static metadata extract_metadata(
const uint8_t *buffer, uint32_t total_sz);
650 DNS(
const uint8_t* buffer, uint32_t total_sz);
659 uint16_t
id()
const {
660 return Endian::be_to_host(header_.id);
670 return static_cast<QRType>(header_.qr);
679 return header_.opcode;
756 return header_.rcode;
765 return Endian::be_to_host(header_.questions);
774 return Endian::be_to_host(header_.answers);
783 return Endian::be_to_host(header_.authority);
792 return Endian::be_to_host(header_.additional);
807 uint32_t header_size()
const;
816 void id(uint16_t new_id);
830 void opcode(uint8_t new_opcode);
838 void authoritative_answer(uint8_t new_aa);
846 void truncated(uint8_t new_tc);
854 void recursion_desired(uint8_t new_rd);
862 void recursion_available(uint8_t new_ra);
869 void z(uint8_t new_z);
877 void authenticated_data(uint8_t new_ad);
884 void checking_disabled(uint8_t new_cd);
891 void rcode(uint8_t new_rcode);
914 void add_authority(
const resource& resource);
921 void add_additional(
const resource& resource);
928 queries_type queries()
const;
935 resources_type answers()
const;
942 resources_type authority()
const;
949 resources_type additional()
const;
966 static std::string encode_domain_name(
const std::string& domain_name);
980 static std::string decode_domain_name(
const std::string& domain_name);
989 bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
995 return new DNS(*
this);
1003 #if TINS_IS_LITTLE_ENDIAN 1015 #elif TINS_IS_BIG_ENDIAN 1028 uint16_t questions, answers,
1029 authority, additional;
1032 typedef std::vector<std::pair<uint32_t*, uint32_t> > sections_type;
1034 uint32_t compose_name(
const uint8_t* ptr,
char* out_ptr)
const;
1035 void convert_records(
const uint8_t* ptr,
1037 resources_type& res)
const;
1038 void skip_to_section_end(Memory::InputMemoryStream& stream,
1039 const uint32_t num_records)
const;
1040 void skip_to_dname_end(Memory::InputMemoryStream& stream)
const;
1041 void update_records(uint32_t& section_start,
1042 uint32_t num_records,
1045 uint8_t* update_dname(uint8_t* ptr, uint32_t threshold, uint32_t offset);
1046 static void inline_convert_v4(uint32_t value,
char* output);
1047 static bool contains_dname(uint16_t type);
1048 void write_serialization(uint8_t* buffer, uint32_t total_sz);
1049 void add_record(
const resource& resource,
const sections_type& sections);
1053 uint32_t answers_idx_, authority_idx_, additional_idx_;
1058 #endif // TINS_DNS_H uint8_t authoritative_answer() const
Setter for the authoritative answer field.
Definition: dns.h:688
uint8_t rcode() const
Setter for the rcode field.
Definition: dns.h:755
const std::string & dname() const
Getter for the domain name field.
Definition: dns.h:484
uint8_t authenticated_data() const
Setter for the authenticated data field.
Definition: dns.h:736
void preference(uint16_t data)
Setter for the preference field.
Definition: dns.h:607
QRType type() const
Setter for the query response field.
Definition: dns.h:669
PDUType pdu_type() const
Getter for the PDU's type.
Definition: dns.h:800
uint32_t expire() const
Getter for the expire field.
Definition: dns.h:370
QueryType
Query types enum.
Definition: dns.h:103
TINS_DEPRECATED(QueryType type() const)
Getter for the query type field.
Definition: dns.h:260
std::vector< uint8_t > byte_array
Definition: pdu.h:45
uint32_t ttl() const
Definition: dns.h:524
uint16_t id() const
Setter for the id field.
Definition: dns.h:659
Represents a DNS PDU.
Definition: dns.h:85
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
uint8_t z() const
Setter for the z desired field.
Definition: dns.h:726
void dname(const std::string &nm)
Setter for the name field.
Definition: dns.h:204
TINS_DEPRECATED(void type(QueryType tp))
Setter for the query type field.
Definition: dns.h:225
Definition: hw_address.h:456
QueryType query_type() const
Getter for the query type field.
Definition: dns.h:248
uint8_t truncated() const
Setter for the truncated field.
Definition: dns.h:697
Struct that represent DNS queries.
Definition: dns.h:177
query(std::string nm, QueryType tp, QueryClass cl)
Constructs a DNS query.
Definition: dns.h:187
Class that represents a Start Of Authority record.
Definition: dns.h:281
uint16_t query_type() const
Definition: dns.h:498
query()
Default constructs this Query.
Definition: dns.h:197
void query_class(QueryClass cl)
Setter for the query class field.
Definition: dns.h:234
uint8_t recursion_available() const
Setter for the recursion available field.
Definition: dns.h:717
uint32_t serial() const
Getter for the serial number field.
Definition: dns.h:346
uint16_t preference() const
Getter for the preferece field.
Definition: dns.h:533
DNS * clone() const
Definition: dns.h:994
TINS_DEPRECATED(uint16_t type() const)
Getter for the query type field.
Definition: dns.h:510
const std::string & data() const
Definition: dns.h:491
TINS_DEPRECATED(void type(uint16_t data))
Setter for the query type field.
Definition: dns.h:584
const std::string & mname() const
Getter for the primary source name field.
Definition: dns.h:327
PDU::serialization_type serialize() const
Serialize this SOA record.
Definition: dns.cpp:669
void dname(const std::string &data)
Definition: dns.h:540
QRType
Definition: dns.h:95
uint32_t minimum_ttl() const
Getter for the minimum TTL field.
Definition: dns.h:378
const std::string & dname() const
Getter for the name field.
Definition: dns.h:241
void data(const std::string &data)
Setter for the data field.
Definition: dns.h:556
The Tins namespace.
Definition: address_range.h:38
void query_type(uint16_t data)
Definition: dns.h:572
uint8_t checking_disabled() const
Setter for the checking disabled field.
Definition: dns.h:746
uint16_t answers_count() const
Setter for the answers field.
Definition: dns.h:773
void query_class(uint16_t data)
Definition: dns.h:591
const std::string & rname() const
Getter for the responsible person name field.
Definition: dns.h:338
uint16_t query_class() const
Definition: dns.h:517
resource(std::string dname, std::string data, uint16_t type, uint16_t rclass, uint32_t ttl, uint16_t preference=0)
Definition: dns.h:457
uint32_t refresh() const
Getter for the refresh field.
Definition: dns.h:354
uint8_t recursion_desired() const
Setter for the recursion desired field.
Definition: dns.h:707
Abstraction of an IPv4 address.
Definition: ip_address.h:45
void ttl(uint32_t data)
Definition: dns.h:598
void data(const soa_record &data)
Sets the contents of this resource to the provided SOA record.
Definition: dns.h:564
Definition: ipv6_address.h:45
uint16_t questions_count() const
Setter for the questions field.
Definition: dns.h:764
uint16_t authority_count() const
Setter for the authority field.
Definition: dns.h:782
byte_array serialization_type
Definition: pdu.h:112
QueryClass query_class() const
Getter for the query class field.
Definition: dns.h:267
Base class for protocol data units.
Definition: pdu.h:107
uint8_t opcode() const
Setter for the opcode field.
Definition: dns.h:678
uint32_t retry() const
Getter for the retry field.
Definition: dns.h:362
uint16_t additional_count() const
Setter for the additional field.
Definition: dns.h:791
Class that represent DNS resource records.
Definition: dns.h:444
void query_type(QueryType tp)
Setter for the query type field.
Definition: dns.h:213