NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
dns_message.hpp
浏览该文件的文档.
1#ifndef NEFORCE_NETWORK_DNS_MESSAGE_HPP
2#define NEFORCE_NETWORK_DNS_MESSAGE_HPP
3
19
23NEFORCE_BEGIN_NAMESPACE__
24
30
36
43enum class dns_opcode : uint8_t {
44 QUERY = 0,
45 IQUERY = 1,
46 STATUS = 2,
47 NOTIFY = 4,
48 UPDATE = 5
49};
50
57enum class dns_query : uint16_t {
59 CHAOS = 3,
60 HESIOD = 4,
61 ANY = 255
62};
63
78 // DNS
80 // Network
82
88
95class dns_exception final : public network_exception {
96public:
109
114 explicit dns_exception(const string& what) :
115 network_exception(what.data()) {}
116
122 dns_exception(const string& what, const code code) :
123 network_exception(what.data(), static_type, static_cast<int>(code)) {}
124
129 static dns_exception timeout() { return dns_exception("DNS query timeout", code::TIMEOUT); }
130
137 static dns_exception network_error(const string& detail, const code code = code::NETWORK_ERROR) {
138 return dns_exception("Network error: " + detail, code);
139 }
140
146 static dns_exception parse_error(const string& detail) {
147 return dns_exception("Parse error: " + detail, code::PARSE_ERROR);
148 }
149
150 static constexpr auto static_type = "dns_exception";
151};
152 // Exceptions
154
160
166
180 enum raw : uint16_t {
181 A = 1,
182 NS = 2,
183 CNAME = 5,
184 SOA = 6,
185 PTR = 12,
186 MX = 15,
187 TXT = 16,
188 AAAA = 28,
189 SRV = 33
190 };
191
192 string name;
193 string data;
197
201 dns_record() = default;
202
211 dns_record(string n, const raw t, const dns_query c, const uint32_t ttl_val, string d) noexcept :
212 name(_NEFORCE move(n)),
213 data(_NEFORCE move(d)),
214 ttl(ttl_val),
215 type(t),
216 class_type(c) {}
217};
218
240
255 // DNS
257 // Network
259
260NEFORCE_END_NAMESPACE__
261#endif // NEFORCE_NETWORK_DNS_MESSAGE_HPP
static dns_exception network_error(const string &detail, const code code=code::NETWORK_ERROR)
创建网络错误异常
dns_exception(const string &what)
构造函数
code
DNS异常错误码
@ TRUNCATED
响应被截断
@ SERVER_FAILURE
服务器失败
static dns_exception parse_error(const string &detail)
创建解析错误异常
dns_exception(const string &what, const code code)
构造函数
static dns_exception timeout()
创建超时异常
动态大小数组容器
持续时间类型
unsigned char uint8_t
8位无符号整数类型
unsigned int uint32_t
32位无符号整数类型
unsigned short uint16_t
16位无符号整数类型
dns_query
DNS查询类型枚举
dns_response
DNS响应码枚举
dns_opcode
DNS操作码枚举
@ HESIOD
HESIOD类
@ INTERNET
Internet类
@ REFUSED
拒绝,服务器拒绝执行查询
@ NOT_IMPLEMENTED
未实现,服务器不支持该查询类型
@ FORMAT_ERROR
格式错误,服务器无法解析查询
@ NON_ERROR
无错误,查询成功
@ SERVER_FAILURE
服务器失败,无法处理查询
@ NAME_ERROR
名称错误,域名不存在
@ UPDATE
区域更新
@ IQUERY
反向查询
@ QUERY
标准查询
@ STATUS
服务器状态请求
@ NOTIFY
区域通知
duration< int64_t, milli > milliseconds
毫秒持续时间
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针
字符串类型别名和实用函数
DNS消息头部结构
uint16_t qdcount
问题计数
uint16_t arcount
附加计数
uint16_t nscount
权威计数
uint16_t ancount
答案计数
uint16_t flags
标志位
DNS查询结果结构
milliseconds query_time
查询耗时
vector< dns_record > authorities
权威记录
bool truncated
响应是否被截断
bool recursive_available
递归查询是否可用
vector< dns_record > additional
附加记录
dns_response response_code
响应码
vector< dns_record > answers
答案记录
NEFORCE_NODISCARD bool is_success() const noexcept
检查查询是否成功
dns_query class_type
查询类
dns_record(string n, const raw t, const dns_query c, const uint32_t ttl_val, string d) noexcept
构造函数
string data
记录数据
raw
DNS记录类型枚举
@ CNAME
规范名称记录
@ SRV
服务定位记录
@ SOA
授权开始记录
@ MX
邮件交换记录
@ A
IPv4地址记录
@ AAAA
IPv6地址记录
@ NS
名称服务器记录
@ PTR
指针记录
@ TXT
文本记录
string name
记录名称
raw type
记录类型
dns_record()=default
默认构造函数
uint32_t ttl
生存时间(秒)
NEFORCE_NODISCARD const char * what() const noexcept
获取错误信息
static constexpr auto static_type
静态类型字符串
动态大小数组容器