summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/HostAddress.cpp')
-rw-r--r--Swiften/Network/HostAddress.cpp15
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,5 +1,5 @@
/*
- * 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.
*/
@@ -15,6 +15,9 @@
#include <Swiften/Base/foreach.h>
#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 {
HostAddress::HostAddress() {
@@ -28,18 +31,18 @@ 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];
}
address_ = boost::asio::ip::address(boost::asio::ip::address_v4(data));
}
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];
}
address_ = boost::asio::ip::address(boost::asio::ip::address_v6(data));
@@ -61,4 +64,8 @@ boost::asio::ip::address HostAddress::getRawAddress() const {
return address_;
}
+bool HostAddress::isLocalhost() const {
+ return address_ == localhost4 || address_ == localhost6;
+}
+
}