(svn r15917) -Codechange: remove the latest traces of NetworkAddress::GetIP.

This commit is contained in:
rubidium
2009-04-02 20:39:30 +00:00
parent 785779ca62
commit f22566f8df
6 changed files with 21 additions and 38 deletions

View File

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

View File

@@ -97,13 +97,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 */

View File

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