diff options
author | rubidium <rubidium@openttd.org> | 2009-04-02 20:17:46 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-02 20:17:46 +0000 |
commit | 1e205e01b83ac995c14105e0eb1f992cbd3e0625 (patch) | |
tree | a5d71eebbdd7eef0f674eaff8b56f9a5785084f9 /src/network/core/address.cpp | |
parent | c0c6e07081fb55d1ec5c46cc3606185062cfe45c (diff) | |
download | openttd-1e205e01b83ac995c14105e0eb1f992cbd3e0625.tar.xz |
(svn r15916) -Codechange: let the network game list use NetworkAddress
Diffstat (limited to 'src/network/core/address.cpp')
-rw-r--r-- | src/network/core/address.cpp | 16 |
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 */ |