diff options
author | rubidium <rubidium@openttd.org> | 2009-04-08 12:52:53 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-08 12:52:53 +0000 |
commit | cd8da0d69eaec81702ca033f375957bb24acdbf1 (patch) | |
tree | 16a31da24b9f3d69e92fd7965947edf06c042b00 /src/network | |
parent | 9d6edae94d5e5e852b461b09e6515cc83861745f (diff) | |
download | openttd-cd8da0d69eaec81702ca033f375957bb24acdbf1.tar.xz |
(svn r15982) -Codechange: use GetAddressAsString to get the name instead of passing the hostname and the IP into a string.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/address.cpp | 14 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 5 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp index ad0e6b18f..963a2e970 100644 --- a/src/network/core/address.cpp +++ b/src/network/core/address.cpp @@ -16,10 +16,7 @@ const char *NetworkAddress::GetHostname() { if (StrEmpty(this->hostname)) { assert(this->address_length != 0); - char *buf = this->hostname; - if (this->address.ss_family == AF_INET6) buf = strecpy(buf, "[", lastof(this->hostname)); - getnameinfo((struct sockaddr *)&this->address, this->address_length, buf, lastof(this->hostname) - buf, NULL, 0, NI_NUMERICHOST); - if (this->address.ss_family == AF_INET6) strecat(buf, "]", lastof(this->hostname)); + getnameinfo((struct sockaddr *)&this->address, this->address_length, this->hostname, sizeof(this->hostname), NULL, 0, NI_NUMERICHOST); } return this->hostname; } @@ -60,6 +57,11 @@ const char *NetworkAddress::GetAddressAsString(bool with_family) { /* 6 = for the : and 5 for the decimal port number */ static char buf[NETWORK_HOSTNAME_LENGTH + 6 + 7]; + char *p = buf; + if (this->address.ss_family == AF_INET6) p = strecpy(p, "[", lastof(buf)); + p = strecpy(p, this->GetHostname(), lastof(buf)); + if (this->address.ss_family == AF_INET6) p = strecpy(p, "]", lastof(buf)); + p += seprintf(p, lastof(buf), ":%d", this->GetPort()); if (with_family) { char family; @@ -68,9 +70,7 @@ const char *NetworkAddress::GetAddressAsString(bool with_family) case AF_INET6: family = '6'; break; default: family = '?'; break; } - seprintf(buf, lastof(buf), "%s:%d (IPv%c)", this->GetHostname(), this->GetPort(), family); - } else { - seprintf(buf, lastof(buf), "%s:%d", this->GetHostname(), this->GetPort()); + seprintf(p, lastof(buf), " (IPv%c)", family); } return buf; } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 50a902d59..8c16f4ddc 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -352,7 +352,7 @@ public: virtual void OnPaint() { - const NetworkGameList *sel = this->server; + NetworkGameList *sel = this->server; const SortButtonState arrow = this->servers.IsDescSortOrder() ? SBS_DOWN : SBS_UP; if (this->servers.NeedRebuild()) { @@ -453,8 +453,7 @@ public: DrawString(x, this->widget[NGWW_DETAILS].right, y, STR_NETWORK_SERVER_VERSION, TC_GOLD); // server version y += 10; - SetDParamStr(0, sel->info.hostname); - SetDParam(1, sel->address.GetPort()); + SetDParamStr(0, sel->address.GetAddressAsString()); DrawString(x, this->widget[NGWW_DETAILS].right, y, STR_NETWORK_SERVER_ADDRESS, TC_GOLD); // server address y += 10; |