From 1e205e01b83ac995c14105e0eb1f992cbd3e0625 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 2 Apr 2009 20:17:46 +0000 Subject: (svn r15916) -Codechange: let the network game list use NetworkAddress --- src/network/core/address.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/network/core/address.cpp') diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp index bd7f569ae..a29640056 100644 --- a/src/network/core/address.cpp +++ b/src/network/core/address.cpp @@ -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 */ -- cgit v1.2.3-54-g00ecf