summaryrefslogtreecommitdiff
path: root/src/network/core/address.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-02 20:17:46 +0000
committerrubidium <rubidium@openttd.org>2009-04-02 20:17:46 +0000
commit1e205e01b83ac995c14105e0eb1f992cbd3e0625 (patch)
treea5d71eebbdd7eef0f674eaff8b56f9a5785084f9 /src/network/core/address.h
parentc0c6e07081fb55d1ec5c46cc3606185062cfe45c (diff)
downloadopenttd-1e205e01b83ac995c14105e0eb1f992cbd3e0625.tar.xz
(svn r15916) -Codechange: let the network game list use NetworkAddress
Diffstat (limited to 'src/network/core/address.h')
-rw-r--r--src/network/core/address.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/network/core/address.h b/src/network/core/address.h
index 7488aad3f..faa173493 100644
--- a/src/network/core/address.h
+++ b/src/network/core/address.h
@@ -33,7 +33,7 @@ public:
memset(&this->address, 0, sizeof(this->address));
this->address.ss_family = AF_INET;
((struct sockaddr_in*)&this->address)->sin_addr.s_addr = ip;
- ((struct sockaddr_in*)&this->address)->sin_port = htons(port);
+ this->SetPort(port);
}
/**
@@ -58,7 +58,7 @@ public:
{
memset(&this->address, 0, sizeof(this->address));
this->address.ss_family = AF_INET;
- ((struct sockaddr_in*)&this->address)->sin_port = htons(port);
+ this->SetPort(port);
}
/**
@@ -111,6 +111,12 @@ public:
uint16 GetPort() const;
/**
+ * Set the port
+ * @param port set the port number
+ */
+ void SetPort(uint16 port);
+
+ /**
* Check whether the IP address has been resolved already
* @return true iff the port has been resolved
*/
@@ -118,6 +124,19 @@ public:
{
return this->resolved;
}
+
+ /**
+ * Compare the address of this class with the address of another.
+ * @param address the other address.
+ */
+ bool operator == (NetworkAddress &address)
+ {
+ if (this->IsResolved() != address.IsResolved()) return false;
+
+ if (this->IsResolved()) return memcmp(&this->address, &address.address, sizeof(this->address)) == 0;
+
+ return this->GetPort() == address.GetPort() && strcmp(this->GetHostname(), address.GetHostname()) == 0;
+ }
};
#endif /* ENABLE_NETWORK */