mirror of
https://github.com/sogou/workflow.git
synced 2026-10-29 03:27:04 +08:00
DnsMessage support add and encode raw record (#1691)
This commit is contained in:
@@ -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++;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user