You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
1.2 KiB

  1. #include "dnsrecords.hh"
  2. #include "iputils.hh"
  3. static inline std::shared_ptr<DNSRecordContent> getRecordContent(uint16_t type, const std::string& content)
  4. {
  5. std::shared_ptr<DNSRecordContent> result = nullptr;
  6. if (type == QType::NS) {
  7. result = std::make_shared<NSRecordContent>(DNSName(content));
  8. }
  9. else if (type == QType::A) {
  10. result = std::make_shared<ARecordContent>(ComboAddress(content));
  11. }
  12. else if (type == QType::AAAA) {
  13. result = std::make_shared<AAAARecordContent>(ComboAddress(content));
  14. }
  15. else if (type == QType::CNAME) {
  16. result = std::make_shared<CNAMERecordContent>(DNSName(content));
  17. }
  18. else if (type == QType::OPT) {
  19. result = std::make_shared<OPTRecordContent>();
  20. }
  21. else {
  22. result = DNSRecordContent::mastermake(type, QClass::IN, content);
  23. }
  24. return result;
  25. }
  26. 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)
  27. {
  28. DNSRecord rec;
  29. rec.d_place = place;
  30. rec.d_name = name;
  31. rec.d_type = type;
  32. rec.d_ttl = ttl;
  33. rec.d_content = getRecordContent(type, content);
  34. records.push_back(rec);
  35. }