diff options
author | rubidium <rubidium@openttd.org> | 2009-04-02 20:39:30 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-02 20:39:30 +0000 |
commit | c5160c7c8e80b1b64bf474ec1d2a54c2bcef690b (patch) | |
tree | a76360971db13f30d480449e26cf22d898d0a178 /src | |
parent | 1e205e01b83ac995c14105e0eb1f992cbd3e0625 (diff) | |
download | openttd-c5160c7c8e80b1b64bf474ec1d2a54c2bcef690b.tar.xz |
(svn r15917) -Codechange: remove the latest traces of NetworkAddress::GetIP.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/core/address.cpp | 16 | ||||
-rw-r--r-- | src/network/core/address.h | 23 | ||||
-rw-r--r-- | src/network/core/tcp_connect.cpp | 7 | ||||
-rw-r--r-- | src/network/network.cpp | 9 | ||||
-rw-r--r-- | src/network/network_gamelist.cpp | 2 | ||||
-rw-r--r-- | src/network/network_udp.cpp | 2 |
6 files changed, 21 insertions, 38 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp index a29640056..888625dc1 100644 --- a/src/network/core/address.cpp +++ b/src/network/core/address.cpp @@ -21,17 +21,6 @@ const char *NetworkAddress::GetHostname() return this->hostname; } -uint32 NetworkAddress::GetIP() -{ - assert(this->address.ss_family == AF_INET); - - if (!this->resolved) { - ((struct sockaddr_in *)&this->address)->sin_addr.s_addr = NetworkResolveHost(this->hostname); - this->resolved = true; - } - return ((struct sockaddr_in *)&this->address)->sin_addr.s_addr; -} - uint16 NetworkAddress::GetPort() const { switch (this->address.ss_family) { @@ -66,7 +55,10 @@ const char *NetworkAddress::GetAddressAsString() const sockaddr_storage *NetworkAddress::GetAddress() { - if (!this->resolved) this->GetIP(); + if (!this->resolved) { + ((struct sockaddr_in *)&this->address)->sin_addr.s_addr = NetworkResolveHost(this->hostname); + this->resolved = true; + } return &this->address; } diff --git a/src/network/core/address.h b/src/network/core/address.h index faa173493..3a4b8c06e 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -98,13 +98,6 @@ public: const sockaddr_storage *GetAddress(); /** - * Get the IP address. If the IP has not been resolved yet this will resolve - * it possibly blocking this function for a while - * @return the IP address - */ - uint32 GetIP(); - - /** * Get the port * @return the port */ @@ -131,12 +124,20 @@ public: */ bool operator == (NetworkAddress &address) { - if (this->IsResolved() != address.IsResolved()) return false; - - if (this->IsResolved()) return memcmp(&this->address, &address.address, sizeof(this->address)) == 0; - + 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; } + + NetworkAddress& operator = (const NetworkAddress &other) + { + if (this != &other) { // protect against invalid self-assignment + free(this->hostname); + memcpy(this, &other, sizeof(*this)); + if (other.hostname != NULL) this->hostname = strdup(other.hostname); + } + return *this; + } + }; #endif /* ENABLE_NETWORK */ diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp index 88501b260..a994fc6d2 100644 --- a/src/network/core/tcp_connect.cpp +++ b/src/network/core/tcp_connect.cpp @@ -41,13 +41,8 @@ void TCPConnecter::Connect() if (!SetNoDelay(this->sock)) DEBUG(net, 1, "Setting TCP_NODELAY failed"); - struct sockaddr_in sin; - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = address.GetIP(); - sin.sin_port = htons(address.GetPort()); - /* We failed to connect for which reason what so ever */ - if (connect(this->sock, (struct sockaddr*) &sin, sizeof(sin)) != 0) { + if (connect(this->sock, (struct sockaddr*)this->address.GetAddress(), sizeof(*this->address.GetAddress())) != 0) { closesocket(this->sock); this->sock = INVALID_SOCKET; this->aborted = true; diff --git a/src/network/network.cpp b/src/network/network.cpp index 9e78f0411..e88b7a1f8 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1090,7 +1090,6 @@ void NetworkStartDebugLog(NetworkAddress address) { extern SOCKET _debug_socket; // Comes from debug.c SOCKET s; - struct sockaddr_in sin; DEBUG(net, 0, "Redirecting DEBUG() to %s:%d", address.GetHostname(), address.GetPort()); @@ -1102,12 +1101,8 @@ void NetworkStartDebugLog(NetworkAddress address) if (!SetNoDelay(s)) DEBUG(net, 1, "Setting TCP_NODELAY failed"); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = address.GetIP(); - sin.sin_port = htons(address.GetPort()); - - if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) != 0) { - DEBUG(net, 0, "Failed to redirection DEBUG() to %s:%d", address.GetHostname(), address.GetPort()); + if (connect(s, (struct sockaddr *)address.GetAddress(), sizeof(*address.GetAddress())) != 0) { + DEBUG(net, 0, "Failed to redirection DEBUG() to %s", address.GetAddressAsString()); return; } diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp index 3ade0e204..2dd36fa51 100644 --- a/src/network/network_gamelist.cpp +++ b/src/network/network_gamelist.cpp @@ -65,7 +65,7 @@ static void NetworkGameListHandleDelayedInsert() * @return a point to the newly added or already existing item */ NetworkGameList *NetworkGameListAddItem(NetworkAddress address) { - if (!address.IsResolved()) return NULL; + if (StrEmpty(address.GetHostname())) return NULL; NetworkGameList *item, *prev_item; diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp index 7032ab341..031e9cbf1 100644 --- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -429,7 +429,7 @@ void NetworkUDPQueryServerThread(void *pntr) /* Clear item in gamelist */ NetworkGameList *item = CallocT<NetworkGameList>(1); - item->address = NetworkAddress(*info); + item->address = *info; strecpy(item->info.server_name, info->GetHostname(), lastof(item->info.server_name)); strecpy(item->info.hostname, info->GetHostname(), lastof(item->info.hostname)); item->manually = info->manually; |