summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-08 12:09:07 +0000
committerrubidium <rubidium@openttd.org>2009-04-08 12:09:07 +0000
commit9d6edae94d5e5e852b461b09e6515cc83861745f (patch)
tree1cbee29338e9eaa759d845ef73e2f390476df500 /src/network/core
parent18146572b0a0cbb3eb89738f633fefd903df9692 (diff)
downloadopenttd-9d6edae94d5e5e852b461b09e6515cc83861745f.tar.xz
(svn r15981) -Fix: don't print the address family when writing the IP+port to the config file.
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/address.cpp18
-rw-r--r--src/network/core/address.h3
2 files changed, 13 insertions, 8 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index ba81a6c0d..ad0e6b18f 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -56,18 +56,22 @@ void NetworkAddress::SetPort(uint16 port)
}
}
-const char *NetworkAddress::GetAddressAsString()
+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 family;
- switch (this->address.ss_family) {
- case AF_INET: family = '4'; break;
- case AF_INET6: family = '6'; break;
- default: family = '?'; break;
+ if (with_family) {
+ char family;
+ switch (this->address.ss_family) {
+ case AF_INET: family = '4'; break;
+ 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(buf, lastof(buf), "%s:%d (IPv%c)", this->GetHostname(), this->GetPort(), family);
return buf;
}
diff --git a/src/network/core/address.h b/src/network/core/address.h
index e0ef9889b..a2fac9845 100644
--- a/src/network/core/address.h
+++ b/src/network/core/address.h
@@ -122,9 +122,10 @@ public:
/**
* Get the address as a string, e.g. 127.0.0.1:12345.
+ * @param with_family whether to add the family (e.g. IPvX).
* @return the address
*/
- const char *GetAddressAsString();
+ const char *GetAddressAsString(bool with_family = true);
/**
* Get the address in it's internal representation.