mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-03 04:43:12 +00:00
(svn r15935) -Codechange: function to compare IP addresses (to sort them)
This commit is contained in:
parent
2bfc9ca50c
commit
e05e1822d6
@ -167,6 +167,23 @@ public:
|
||||
return this->GetPort() == address.GetPort() && strcmp(this->GetHostname(), address.GetHostname()) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
Loading…
Reference in New Issue
Block a user