summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-04 01:51:32 +0000
committerrubidium <rubidium@openttd.org>2009-04-04 01:51:32 +0000
commita779611665dc04d1255b0ea5cfd5af3803f95d25 (patch)
treeacb451a83d90128e44c4b3a37a256862ce0a0a8a /src/network
parentc9ebf14ba5a4461edd8790a96f13f0d1e87d60e1 (diff)
downloadopenttd-a779611665dc04d1255b0ea5cfd5af3803f95d25.tar.xz
(svn r15948) -Fix: resolve network addresses before comparing them
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/address.h31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/network/core/address.h b/src/network/core/address.h
index f972a0397..1bec20a27 100644
--- a/src/network/core/address.h
+++ b/src/network/core/address.h
@@ -169,28 +169,33 @@ public:
/**
* Compare the address of this class with the address of another.
* @param address the other address.
+ * @return < 0 if address is less, 0 if equal and > 0 if address is more
*/
- bool operator == (NetworkAddress &address)
+ int CompareTo(NetworkAddress address)
{
- if (this->IsResolved() && address.IsResolved()) return memcmp(&this->address, &address.address, sizeof(this->address)) == 0;
- return this->GetPort() == address.GetPort() && strcmp(this->GetHostname(), address.GetHostname()) == 0;
+ int r = this->GetAddressLength() - address.GetAddressLength();
+ if (r == 0) r = this->address.ss_family - address.address.ss_family;
+ if (r == 0) r = memcmp(&this->address, &address.address, this->address_length) == 0;
+ if (r == 0) r = this->GetPort() - address.GetPort();
+ return r;
}
/**
* Compare the address of this class with the address of another.
* @param address the other address.
*/
- bool operator < (NetworkAddress &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;
+ return this->CompareTo(address) == 0;
+ }
+
+ /**
+ * Compare the address of this class with the address of another.
+ * @param address the other address.
+ */
+ bool operator < (NetworkAddress address)
+ {
+ return this->CompareTo(address) < 0;
}
/**