Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
resolve.cpp
Go to the documentation of this file.
1#include <boost/asio.hpp>
3
4namespace fc
5{
6 std::vector<boost::asio::ip::udp::endpoint> resolve(boost::asio::io_service& io_service,
7 const std::string& host, uint16_t port)
8 {
9 using q = boost::asio::ip::udp::resolver::query;
10 using b = boost::asio::ip::resolver_query_base;
11 boost::asio::ip::udp::resolver res(io_service);
12 boost::system::error_code ec;
13 auto ep = res.resolve(q(host, std::to_string(uint64_t(port)),
14 b::address_configured | b::numeric_service), ec);
15 if(!ec)
16 {
17 std::vector<boost::asio::ip::udp::endpoint> eps;
18 while(ep != boost::asio::ip::udp::resolver::iterator())
19 {
20 if(ep->endpoint().address().is_v4())
21 {
22 eps.push_back(*ep);
23 }
24 // TODO: add support for v6
25 ++ep;
26 }
27 return eps;
28 }
29 FC_THROW_EXCEPTION(unknown_host_exception,
30 "name resolution failed: ${reason}",
31 ("reason", ec.message()));
32 }
33}
Defines exception's used by fc.
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
namespace sysio::chain
Definition authority.cpp:3
std::vector< boost::asio::ip::udp::endpoint > resolve(boost::asio::io_service &io_service, const std::string &host, uint16_t port)
Definition resolve.cpp:6
unsigned short uint16_t
Definition stdint.h:125
unsigned __int64 uint64_t
Definition stdint.h:136