New utility

This commit is contained in:
Baptiste Wicht 2016-09-18 10:46:45 +02:00
parent 03ee69e9a6
commit e6d5dd2b71
2 changed files with 7 additions and 1 deletions

View File

@ -24,6 +24,8 @@ std::expected<void> send_request(tlib::socket& sock, const std::string& domain,
std::expected<std::string> resolve(const std::string& domain, size_t timeout = 1000, size_t retries = 1);
tlib::ip::address gateway_address();
} // end of namespace dns
} // end of namespace tlib

View File

@ -37,6 +37,10 @@ std::string tlib::dns::decode_domain(char* payload, size_t& offset) {
return domain;
}
tlib::ip::address tlib::dns::gateway_address(){
return tlib::ip::make_address(10, 0, 2, 3);
}
std::expected<void> tlib::dns::send_request(tlib::socket& sock, const std::string& domain, uint16_t rr_type, uint16_t rr_class){
auto parts = std::split(domain, '.');
@ -45,7 +49,7 @@ std::expected<void> tlib::dns::send_request(tlib::socket& sock, const std::strin
tlib::dns::packet_descriptor desc;
desc.payload_size = labels + characters + 1 + 2 * 2;
desc.target_ip = tlib::ip::make_address(10, 0, 2, 3);
desc.target_ip = gateway_address();
desc.identification = 0x666;
desc.query = true;