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
|
#include "dnsrecords.hh"
#include "iputils.hh"
static inline std::shared_ptr<DNSRecordContent> getRecordContent(uint16_t type, const std::string& content)
{
std::shared_ptr<DNSRecordContent> result = nullptr;
if (type == QType::NS) {
result = std::make_shared<NSRecordContent>(DNSName(content));
}
else if (type == QType::A) {
result = std::make_shared<ARecordContent>(ComboAddress(content));
}
else if (type == QType::AAAA) {
result = std::make_shared<AAAARecordContent>(ComboAddress(content));
}
else if (type == QType::CNAME) {
result = std::make_shared<CNAMERecordContent>(DNSName(content));
}
else if (type == QType::OPT) {
result = std::make_shared<OPTRecordContent>();
}
else {
result = DNSRecordContent::make(type, QClass::IN, content);
}
return result;
}
static inline void addRecordToList(std::vector<DNSRecord>& records, const DNSName& name, uint16_t type, const std::string& content, DNSResourceRecord::Place place=DNSResourceRecord::ANSWER, uint32_t ttl=3600)
{
DNSRecord rec;
rec.d_place = place;
rec.d_name = name;
rec.d_type = type;
rec.d_ttl = ttl;
rec.setContent(getRecordContent(type, content));
records.push_back(rec);
}
|