DnsMessage support add and encode raw record (#1691)

This commit is contained in:
kedixa
2025-02-07 20:09:49 +08:00
committed by GitHub
parent 21b48e639e
commit 5fc57225b7
2 changed files with 15 additions and 7 deletions
+3 -7
View File
@@ -99,6 +99,7 @@ static inline int __append_record_list(std::string& s, int *count,
switch (record->type)
{
default: // encode unknown types as raw record
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
__append_uint16(record_buf, record->rdlength);
@@ -115,7 +116,6 @@ static inline int __append_record_list(std::string& s, int *count,
__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);
break;
case DNS_TYPE_SOA:
@@ -138,7 +138,6 @@ static inline int __append_record_list(std::string& s, int *count,
__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);
break;
}
@@ -156,12 +155,13 @@ static inline int __append_record_list(std::string& s, int *count,
__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);
break;
}
case DNS_TYPE_MX:
{
auto *mx = (struct dns_record_mx *)record->rdata;
rdata_buf.clear();
__append_uint16(rdata_buf, mx->preference);
ret = __append_name(rdata_buf, mx->exchange);
@@ -170,12 +170,8 @@ static inline int __append_record_list(std::string& s, int *count,
__append_uint16(record_buf, rdata_buf.size());
record_buf.append(rdata_buf);
break;
}
default:
// TODO not implement
continue;
}
cnt++;
+12
View File
@@ -255,6 +255,18 @@ public:
return dns_add_mx_record(name, rclass, ttl, preference, exchange, list);
}
int add_raw_record(int section, const char *name, uint16_t type,
uint16_t rclass, uint32_t ttl,
const void *data, uint16_t dlen)
{
struct list_head *list = get_section(section);
if (!list)
return -1;
return dns_add_raw_record(name, type, rclass, ttl, dlen, data, list);
}
// Inner use only
bool is_single_packet() const
{