Server-Root/TeaDNS/server/main.cpp

38 lines
878 B
C++
Raw Normal View History

2019-11-22 14:51:52 -05:00
#include <iostream>
#include <cstring>
#include "server/src/server.h"
#include "server/src/handler.h"
using namespace ts::dns;
std::vector<sockaddr_storage> bindings() {
std::vector<sockaddr_storage> result{};
{
sockaddr_in& any_v4{reinterpret_cast<sockaddr_in&>(result.emplace_back())};
memset(&any_v4, 0, sizeof(sockaddr_in));
any_v4.sin_family = AF_INET;
any_v4.sin_port = htons(1222); //htons(53);
any_v4.sin_addr.s_addr = (1UL << 24U) | 127U;
}
return result;
}
int main() {
std::string error{};
auto handler = std::make_shared<DNSHandler>();
WebDNSServer server{handler};
if(!server.start(bindings(), error)) {
for(auto& binding : server.bindings())
std::cout << " - " << binding->error << "\n";
std::cerr << "Failed to start server: " << error << "\n";
return 1;
}
std::this_thread::sleep_for(std::chrono::seconds{100});
return 0;
}