2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
#include <Poco/Util/Application.h>
|
|
|
|
#include <Poco/Net/NetworkInterface.h>
|
|
|
|
#include <Poco/Net/SocketAddress.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/isLocalAddress.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
bool isLocalAddress(const Poco::Net::SocketAddress & address)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
const UInt16 clickhouse_port = Poco::Util::Application::instance().config().getInt("tcp_port", 0);
|
|
|
|
static auto interfaces = Poco::Net::NetworkInterface::list();
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (clickhouse_port == address.port())
|
|
|
|
{
|
|
|
|
return interfaces.end() != std::find_if(interfaces.begin(), interfaces.end(),
|
|
|
|
[&] (const Poco::Net::NetworkInterface & interface)
|
|
|
|
{
|
|
|
|
/** Compare the addresses without taking into account `scope`.
|
|
|
|
* Theoretically, this may not be correct - depends on `route` setting
|
|
|
|
* - through which interface we will actually access the specified address.
|
|
|
|
*/
|
|
|
|
return interface.address().length() == address.host().length()
|
|
|
|
&& 0 == memcmp(interface.address().addr(), address.host().addr(), address.host().length());
|
|
|
|
});
|
|
|
|
}
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|