summaryrefslogtreecommitdiff
path: root/src/network/core/address.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/core/address.cpp')
-rw-r--r--src/network/core/address.cpp16
1 files changed, 15 insertions, 1 deletions
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 */