summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/core/address.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/network/core/address.h b/src/network/core/address.h
index 30e79f7a4..9515de976 100644
--- a/src/network/core/address.h
+++ b/src/network/core/address.h
@@ -168,6 +168,23 @@ public:
}
/**
+ * Compare the address of this class with the address of another.
+ * @param address the other address.
+ */
+ bool operator < (NetworkAddress &address)
+ {
+ int r = this->address.ss_family - address.address.ss_family;
+ if (r == 0 && this->IsResolved() && address.IsResolved()) {
+ r = this->address_length - address.address_length;
+ if (r == 0) r = memcmp(&this->address, &address.address, this->address_length) == 0;
+ } else {
+ r = strcmp(this->GetHostname(), address.GetHostname());
+ }
+ if (r == 0) r = this->GetPort() - address.GetPort();
+ return r < 0;
+ }
+
+ /**
* Assign another address to ourself
* @param other obviously the address to assign to us
* @return 'this'