(svn r15935) -Codechange: function to compare IP addresses (to sort them)

This commit is contained in:
rubidium 2009-04-03 15:42:41 +00:00
parent 2bfc9ca50c
commit e05e1822d6

View File

@ -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