Resolve hostname for streaming client

- Allows usage of hostnames instead of IP addresses only
   with carla::Client
This commit is contained in:
Johannes Quast 2019-03-01 15:06:25 +01:00
parent 2e18abb576
commit 2cfe7ad136
2 changed files with 15 additions and 7 deletions

View File

@ -1,3 +1,6 @@
## Latest Changes
* Allow usage of hostname for carla::Client and resolve them to IP address
## CARLA 0.9.4
* Added recording and playback functionality

View File

@ -6,6 +6,7 @@
#pragma once
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ip/udp.hpp>
@ -71,14 +72,18 @@ namespace detail {
return boost::asio::ip::make_address("127.0.0.1");
}
static inline auto make_address(const char *address) {
return std::strcmp("localhost", address) == 0 ?
make_localhost_address() :
boost::asio::ip::make_address(address);
}
static inline auto make_address(const std::string &address) {
return make_address(address.c_str());
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(address, "");
boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
boost::asio::ip::tcp::resolver::iterator end;
while (iter != end)
{
boost::asio::ip::tcp::endpoint endpoint = *iter++;
return endpoint.address();
}
return boost::asio::ip::make_address(address);
}
template <typename Protocol>