|
5 | 5 | #include <Common/InterruptListener.h> |
6 | 6 | #include <Common/ShellCommand.h> |
7 | 7 | #include <Common/Stopwatch.h> |
| 8 | +#include <Common/DNSResolver.h> |
8 | 9 | #include <Core/ExternalTable.h> |
9 | 10 | #include <Poco/Util/Application.h> |
10 | 11 | #include <Interpreters/Context.h> |
@@ -239,20 +240,27 @@ class ClientBase : public Poco::Util::Application, public IHints<2, ClientBase> |
239 | 240 | struct HostPort |
240 | 241 | { |
241 | 242 | String host; |
242 | | - std::optional<int> port{}; |
| 243 | + std::optional<UInt16> port{}; |
243 | 244 | friend std::istream & operator>>(std::istream & in, HostPort & hostPort) |
244 | 245 | { |
245 | 246 | String host_with_port; |
246 | | - String delimiter = ":"; |
247 | 247 | in >> host_with_port; |
248 | | - size_t delimiter_pos = host_with_port.find(delimiter); |
249 | | - if (delimiter_pos != String::npos) |
| 248 | + DB::DNSResolver & resolver = DB::DNSResolver::instance(); |
| 249 | + try |
250 | 250 | { |
251 | | - hostPort.host = host_with_port.substr(0, delimiter_pos); |
252 | | - hostPort.port = boost::lexical_cast<uint>(host_with_port.substr(delimiter_pos + 1, host_with_port.length())); |
| 251 | + Poco::Net::SocketAddress address = resolver.resolveAddress(host_with_port); |
| 252 | + hostPort.host = address.host().toString(); |
| 253 | + hostPort.port = address.port(); |
| 254 | + } |
| 255 | + catch (const Exception & e) |
| 256 | + { |
| 257 | + if (e.message() == "Missing port number") { |
| 258 | + hostPort.host = resolver.resolveHost(host_with_port).toString(); |
| 259 | + hostPort.port = std::nullopt; |
| 260 | + return in; |
| 261 | + } |
| 262 | + throw; |
253 | 263 | } |
254 | | - else |
255 | | - hostPort.host = host_with_port; |
256 | 264 | return in; |
257 | 265 | } |
258 | 266 | }; |
|
0 commit comments