Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
DnsService.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19
20#pragma once
21
26#include <sese/thread/Thread.h>
27
28#include <asio.hpp>
29
31
33class DnsService final : public sese::service::Service {
34 asio::io_service io_service;
35 asio::ip::udp::socket socket;
36 asio::error_code error;
37 std::array<uint8_t, 512> buffer;
40 std::atomic_bool running;
41
42 std::map<std::string, sese::net::IPv4Address::Ptr> v4map;
43 std::map<std::string, sese::net::IPv6Address::Ptr> v6map;
44
45 void handleBySelf(
46 std::vector<sese::net::dns::DnsPackage::Question> &questions,
48 );
49
51 std::vector<sese::net::dns::DnsPackage::Question> &questions,
53 );
54
55 void handle();
56
57public:
58
60 DnsService();
61
65 bool bind(const sese::net::IPAddress::Ptr &address);
66
70
74
79 bool addUpstreamNameServer(const std::string &ip, uint16_t port = 53);
80
84 void addRecord(const std::string &name, const sese::net::IPAddress::Ptr &address);
85
88 bool startup() override;
89
92 bool shutdown() override;
93
96 int getLastError() override;
97
100 std::string getLastErrorMessage() override;
101
102private:
104};
105
106} // namespace sese::internal::net::service::dns