(svn r15916) -Codechange: let the network game list use NetworkAddress

This commit is contained in:
rubidium
2009-04-02 20:17:46 +00:00
parent bdf3611d02
commit 785779ca62
7 changed files with 61 additions and 33 deletions

View File

@@ -14,7 +14,9 @@
const char *NetworkAddress::GetHostname()
{
if (this->hostname == NULL) {
this->hostname = strdup(inet_ntoa(((struct sockaddr_in *)&this->address)->sin_addr));
char buf[NETWORK_HOSTNAME_LENGTH] = { '\0' };
getnameinfo((struct sockaddr *)&this->address, sizeof(this->address), buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
this->hostname = strdup(buf);
}
return this->hostname;
}
@@ -41,6 +43,18 @@ uint16 NetworkAddress::GetPort() const
}
}
void NetworkAddress::SetPort(uint16 port)
{
switch (this->address.ss_family) {
case AF_INET:
((struct sockaddr_in*)&this->address)->sin_port = htons(port);
break;
default:
NOT_REACHED();
}
}
const char *NetworkAddress::GetAddressAsString()
{
/* 6 = for the : and 5 for the decimal port number */