summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-03 15:42:41 +0000
committerrubidium <rubidium@openttd.org>2009-04-03 15:42:41 +0000
commite05e1822d61e8147889167896e97dd8687c10f69 (patch)
treebb403e25513633af02f27a32342839a8b1e32415
parent2bfc9ca50ccaa0056a6ab4b7e89c1065e6d93d9f (diff)
downloadopenttd-e05e1822d61e8147889167896e97dd8687c10f69.tar.xz
(svn r15935) -Codechange: function to compare IP addresses (to sort them)
-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'