NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
dns_message.hpp
浏览该文件的文档.
1#ifndef NEFORCE_NETWORK_DNS_DNS_MESSAGE_HPP__
2#define NEFORCE_NETWORK_DNS_DNS_MESSAGE_HPP__
3
19
23NEFORCE_BEGIN_NAMESPACE__
24
168
175enum class dns_opcode : uint8_t {
176 QUERY = 0,
177 IQUERY = 1,
178 STATUS = 2,
179 NOTIFY = 4,
181};
182
190enum class dns_class : uint16_t {
192 CHAOS = 3,
193 HESIOD = 4,
194 ANY = 255
195};
196
211 // DNS
213
218
225class dns_exception final : public network_exception {
226public:
239
240 explicit dns_exception(const string& what) :
242
243 dns_exception(const string& what, const code code) :
244 network_exception(what.data(), static_type, static_cast<int>(code)) {}
245
250 static dns_exception timeout() { return {"DNS query timeout", code::TIMEOUT}; }
251
258 static dns_exception network_error(const string& detail, const code code = code::NETWORK_ERROR) {
259 return {"Network error: " + detail, code};
260 }
261
267 static dns_exception parse_error(const string& detail) { return {"Parse error: " + detail, code::PARSE_ERROR}; }
268
269 static constexpr auto static_type = "dns_exception";
270};
271 // Exceptions
273
278
292 enum raw : uint16_t {
293 A = 1,
294 NS = 2,
295 CNAME = 5,
296 SOA = 6,
297 PTR = 12,
298 MX = 15,
299 TXT = 16,
300 AAAA = 28,
301 SRV = 33
302 };
303
304 string name;
305 string data;
309
313 dns_record() = default;
314
323 dns_record(string n, const raw t, const dns_class c, const uint32_t ttl_val, string d) noexcept :
324 name(_NEFORCE move(n)),
325 data(_NEFORCE move(d)),
326 ttl(ttl_val),
327 type(t),
328 class_type(c) {}
329};
330
365
380
388namespace edns {
389 NEFORCE_INLINE17 constexpr uint16_t OPT_TYPE = 41;
390 NEFORCE_INLINE17 constexpr uint16_t DEFAULT_UDP_PAYLOAD = 1232;
391 NEFORCE_INLINE17 constexpr uint16_t MAX_UDP_PAYLOAD = 4096;
392 NEFORCE_INLINE17 constexpr uint8_t VERSION = 0;
393 NEFORCE_INLINE17 constexpr uint8_t EXT_RCODE_SHIFT = 24;
394 NEFORCE_INLINE17 constexpr uint8_t VERSION_SHIFT = 16;
395 NEFORCE_INLINE17 constexpr uint16_t DO_BIT = 0x8000;
396 NEFORCE_INLINE17 constexpr uint8_t MAX_UDP_RETRIES = 2;
397 NEFORCE_INLINE17 constexpr seconds NEGATIVE_CACHE_TTL{30};
398} // namespace edns
399
406struct dns_srv_record {
410 string target;
411
412 dns_srv_record() = default;
413 dns_srv_record(const uint16_t prio, const uint16_t w, const uint16_t p, string t) :
414 priority(prio),
415 weight(w),
416 port(p),
417 target(_NEFORCE move(t)) {}
418};
419
426struct dns_soa_record {
427 string mname;
428 string rname;
434
435 dns_soa_record() = default;
436};
437 // DNS
439
440NEFORCE_END_NAMESPACE__
441#endif // NEFORCE_NETWORK_DNS_DNS_MESSAGE_HPP__
static dns_exception network_error(const string &detail, const code code=code::NETWORK_ERROR)
创建网络错误异常
code
DNS异常错误码
@ TRUNCATED
响应被截断
@ SERVER_FAILURE
服务器失败
static dns_exception parse_error(const string &detail)
创建解析错误异常
static dns_exception timeout()
创建超时异常
动态大小数组容器
持续时间类型
unsigned char uint8_t
8位无符号整数类型
unsigned int uint32_t
32位无符号整数类型
unsigned short uint16_t
16位无符号整数类型
dns_response
DNS响应码枚举
dns_class
DNS查询类枚举
dns_opcode
DNS操作码枚举
@ REFUSED
拒绝,服务器拒绝执行查询
@ NOT_IMPLEMENTED
未实现,服务器不支持该查询类型
@ FORMAT_ERROR
格式错误,服务器无法解析查询
@ NON_ERROR
无错误,查询成功
@ SERVER_FAILURE
服务器失败,无法处理查询
@ NAME_ERROR
名称错误,域名不存在
@ INTERNET
Internet (IN)
@ UPDATE
区域更新
@ IQUERY
反向查询
@ QUERY
标准查询
@ STATUS
服务器状态请求
@ NOTIFY
区域通知
duration< int64_t, milli > milliseconds
毫秒持续时间
duration< int64_t > seconds
秒持续时间
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针
EDNS0 协议常量(RFC 6891)
constexpr uint8_t VERSION
EDNS版本号
constexpr uint16_t DO_BIT
DNSSEC OK标志位
constexpr uint8_t MAX_UDP_RETRIES
UDP最大重试次数
constexpr uint16_t OPT_TYPE
OPT伪资源记录类型
constexpr uint8_t EXT_RCODE_SHIFT
扩展RCODE在TTL字段中的偏移
constexpr uint16_t MAX_UDP_PAYLOAD
最大UDP载荷大小
constexpr uint8_t VERSION_SHIFT
EDNS版本在TTL字段中的偏移
constexpr seconds NEGATIVE_CACHE_TTL
否定缓存TTL(RFC 2308)
constexpr uint16_t DEFAULT_UDP_PAYLOAD
默认UDP载荷大小(RFC 6891 建议值)
字符串类型别名和实用函数
DNS消息头部结构
uint16_t qdcount
问题计数
uint16_t arcount
附加计数
uint16_t nscount
权威计数
uint16_t ancount
答案计数
uint16_t flags
标志位
DNS查询结果结构
bool dnssec_ok
服务器支持DNSSEC(DO标志位)
milliseconds query_time
查询耗时
uint16_t udp_payload_size
服务器支持的UDP载荷大小(EDNS0)
vector< dns_record > authorities
权威记录
bool truncated
响应是否被截断
uint16_t full_rcode() const noexcept
获取完整响应码(含EDNS0扩展位)
uint8_t extended_rcode
扩展响应码(EDNS0,RFC 6891)
bool recursive_available
递归查询是否可用
bool authoritative
权威应答(AA标志位)
vector< dns_record > additional
附加记录
bool is_success() const noexcept
检查查询是否成功
uint8_t edns_version
EDNS版本号
dns_response response_code
响应码
vector< dns_record > answers
答案记录
string data
记录数据
dns_class class_type
查询类
dns_record(string n, const raw t, const dns_class c, const uint32_t ttl_val, string d) noexcept
构造函数
raw
DNS记录类型枚举
@ CNAME
规范名称记录
@ SRV
服务定位记录
@ SOA
授权开始记录
@ MX
邮件交换记录
@ A
IPv4地址记录
@ AAAA
IPv6地址记录
@ NS
名称服务器记录
@ PTR
指针记录
@ TXT
文本记录
string name
记录名称
raw type
记录类型
dns_record()=default
默认构造函数
uint32_t ttl
生存时间(秒)
DNS SOA(Start of Authority)资源记录
string mname
主名称服务器
uint32_t expire
过期时间(秒)
uint32_t refresh
刷新间隔(秒)
uint32_t retry
重试间隔(秒)
uint32_t serial
区域序列号
string rname
管理员邮箱
uint32_t minimum
最小TTL(秒)
uint16_t weight
权重(同优先级下负载均衡)
string target
目标主机名
uint16_t port
服务端口号
uint16_t priority
优先级(越低越优先)
const char * what() const noexcept
获取错误信息
static constexpr auto static_type
静态类型字符串
网络操作或行为异常
动态大小数组容器