diff options
Diffstat (limited to 'Swiften/Network/HostAddress.cpp')
-rw-r--r-- | Swiften/Network/HostAddress.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Swiften/Network/HostAddress.cpp b/Swiften/Network/HostAddress.cpp index f00581f..ff5c1c4 100644 --- a/Swiften/Network/HostAddress.cpp +++ b/Swiften/Network/HostAddress.cpp @@ -1,4 +1,4 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -16,4 +16,7 @@ #include <string> +static boost::asio::ip::address localhost4 = boost::asio::ip::address(boost::asio::ip::address_v4::loopback()); +static boost::asio::ip::address localhost6 = boost::asio::ip::address(boost::asio::ip::address_v6::loopback()); + namespace Swift { @@ -29,9 +32,9 @@ HostAddress::HostAddress(const std::string& address) { } -HostAddress::HostAddress(const unsigned char* address, int length) { +HostAddress::HostAddress(const unsigned char* address, size_t length) { assert(length == 4 || length == 16); if (length == 4) { boost::asio::ip::address_v4::bytes_type data; - for (int i = 0; i < length; ++i) { + for (size_t i = 0; i < length; ++i) { data[i] = address[i]; } @@ -40,5 +43,5 @@ HostAddress::HostAddress(const unsigned char* address, int length) { else { boost::asio::ip::address_v6::bytes_type data; - for (int i = 0; i < length; ++i) { + for (size_t i = 0; i < length; ++i) { data[i] = address[i]; } @@ -62,3 +65,7 @@ boost::asio::ip::address HostAddress::getRawAddress() const { } +bool HostAddress::isLocalhost() const { + return address_ == localhost4 || address_ == localhost6; +} + } |