diff options
author | rubidium <rubidium@openttd.org> | 2009-04-03 00:33:00 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-03 00:33:00 +0000 |
commit | ba5aafb9bba4887b502dba32e56747fe10af604e (patch) | |
tree | aed246d3f133b865c118d25907878c21f972bbf4 /src/network/core/address.h | |
parent | c7b6469dabe5018775d075bee0a5293175024b42 (diff) | |
download | openttd-ba5aafb9bba4887b502dba32e56747fe10af604e.tar.xz |
(svn r15921) -Fix: some OSes don't like sizeof(sockaddr_storage) but want sizeof(sockaddr) or whatever is 'valid' for the given protocol
Diffstat (limited to 'src/network/core/address.h')
-rw-r--r-- | src/network/core/address.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/network/core/address.h b/src/network/core/address.h index 598cd305e..3e8ca0343 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -16,8 +16,8 @@ */ class NetworkAddress { private: - bool resolved; ///< Has the IP address been resolved char *hostname; ///< The hostname, NULL if there isn't one + size_t address_length; ///< The length of the resolved address sockaddr_storage address; ///< The resolved address public: @@ -27,8 +27,8 @@ public: * @param port the port */ NetworkAddress(in_addr_t ip, uint16 port) : - resolved(true), - hostname(NULL) + hostname(NULL), + address_length(sizeof(sockaddr)) { memset(&this->address, 0, sizeof(this->address)); this->address.ss_family = AF_INET; @@ -40,9 +40,9 @@ public: * Create a network address based on a resolved IP and port * @param address the IP address with port */ - NetworkAddress(struct sockaddr_storage &address) : - resolved(true), + NetworkAddress(struct sockaddr_storage &address, size_t address_length) : hostname(NULL), + address_length(address_length), address(address) { } @@ -53,8 +53,8 @@ public: * @param port the port */ NetworkAddress(const char *hostname = NULL, uint16 port = 0) : - resolved(false), - hostname(hostname == NULL ? NULL : strdup(hostname)) + hostname(hostname == NULL ? NULL : strdup(hostname)), + address_length(0) { memset(&this->address, 0, sizeof(this->address)); this->address.ss_family = AF_INET; @@ -66,8 +66,8 @@ public: * @param address the address to clone */ NetworkAddress(const NetworkAddress &address) : - resolved(address.resolved), hostname(address.hostname == NULL ? NULL : strdup(address.hostname)), + address_length(address.address_length), address(address.address) { } @@ -98,6 +98,17 @@ public: const sockaddr_storage *GetAddress(); /** + * Get the (valid) length of the address. + * @return the length + */ + size_t GetAddressLength() + { + /* Resolve it if we didn't do it already */ + if (!this->IsResolved()) this->GetAddress(); + return this->address_length; + } + + /** * Get the port * @return the port */ @@ -115,7 +126,7 @@ public: */ bool IsResolved() const { - return this->resolved; + return this->address_length != 0; } /** |