(svn r15915) -Codechange: let the udp code use NetworkAddress.
This commit is contained in:
@@ -11,25 +11,37 @@
|
||||
#include "host.h"
|
||||
#include "../../string_func.h"
|
||||
|
||||
const char *NetworkAddress::GetHostname() const
|
||||
const char *NetworkAddress::GetHostname()
|
||||
{
|
||||
if (this->hostname != NULL) return this->hostname;
|
||||
|
||||
in_addr addr;
|
||||
addr.s_addr = this->ip;
|
||||
return inet_ntoa(addr);
|
||||
if (this->hostname == NULL) {
|
||||
this->hostname = strdup(inet_ntoa(((struct sockaddr_in *)&this->address)->sin_addr));
|
||||
}
|
||||
return this->hostname;
|
||||
}
|
||||
|
||||
uint32 NetworkAddress::GetIP()
|
||||
{
|
||||
assert(this->address.ss_family == AF_INET);
|
||||
|
||||
if (!this->resolved) {
|
||||
this->ip = NetworkResolveHost(this->hostname);
|
||||
((struct sockaddr_in *)&this->address)->sin_addr.s_addr = NetworkResolveHost(this->hostname);
|
||||
this->resolved = true;
|
||||
}
|
||||
return this->ip;
|
||||
return ((struct sockaddr_in *)&this->address)->sin_addr.s_addr;
|
||||
}
|
||||
|
||||
const char *NetworkAddress::GetAddressAsString() const
|
||||
uint16 NetworkAddress::GetPort() const
|
||||
{
|
||||
switch (this->address.ss_family) {
|
||||
case AF_INET:
|
||||
return ntohs(((struct sockaddr_in *)&this->address)->sin_port);
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
const char *NetworkAddress::GetAddressAsString()
|
||||
{
|
||||
/* 6 = for the : and 5 for the decimal port number */
|
||||
static char buf[NETWORK_HOSTNAME_LENGTH + 6];
|
||||
@@ -38,4 +50,10 @@ const char *NetworkAddress::GetAddressAsString() const
|
||||
return buf;
|
||||
}
|
||||
|
||||
const sockaddr_storage *NetworkAddress::GetAddress()
|
||||
{
|
||||
if (!this->resolved) this->GetIP();
|
||||
return &this->address;
|
||||
}
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
Reference in New Issue
Block a user