From 2cfe7ad13684baa25d4c488d66cc8ade104e1a43 Mon Sep 17 00:00:00 2001 From: Johannes Quast Date: Fri, 1 Mar 2019 15:06:25 +0100 Subject: [PATCH] Resolve hostname for streaming client - Allows usage of hostnames instead of IP addresses only with carla::Client --- CHANGELOG.md | 3 +++ LibCarla/source/carla/streaming/EndPoint.h | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab5a892b..d2ec76dfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/LibCarla/source/carla/streaming/EndPoint.h b/LibCarla/source/carla/streaming/EndPoint.h index 1003e8e75..f97fcabf6 100644 --- a/LibCarla/source/carla/streaming/EndPoint.h +++ b/LibCarla/source/carla/streaming/EndPoint.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -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