diff options
author | rubidium <rubidium@openttd.org> | 2009-04-03 17:20:57 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-03 17:20:57 +0000 |
commit | ce06df313d8ed2eedcf6ed662efd4086c9a95d46 (patch) | |
tree | 522f72027447cc1277e5a8ad71db21238d667ef1 /src/network/core | |
parent | 1463b00b48a67bdbd8ad0ebdd327d38f42466248 (diff) | |
download | openttd-ce06df313d8ed2eedcf6ed662efd4086c9a95d46.tar.xz |
(svn r15941) -Codechange: jonty-comp's wish partly implemented (content server) ;)
Diffstat (limited to 'src/network/core')
-rw-r--r-- | src/network/core/address.cpp | 9 | ||||
-rw-r--r-- | src/network/core/address.h | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp index 0498c793f..aa18418f9 100644 --- a/src/network/core/address.cpp +++ b/src/network/core/address.cpp @@ -27,9 +27,13 @@ const char *NetworkAddress::GetHostname() uint16 NetworkAddress::GetPort() const { switch (this->address.ss_family) { + case AF_UNSPEC: case AF_INET: return ntohs(((struct sockaddr_in *)&this->address)->sin_port); + case AF_INET6: + return ntohs(((struct sockaddr_in6 *)&this->address)->sin6_port); + default: NOT_REACHED(); } @@ -38,10 +42,15 @@ uint16 NetworkAddress::GetPort() const void NetworkAddress::SetPort(uint16 port) { switch (this->address.ss_family) { + case AF_UNSPEC: case AF_INET: ((struct sockaddr_in*)&this->address)->sin_port = htons(port); break; + case AF_INET6: + ((struct sockaddr_in6*)&this->address)->sin6_port = htons(port); + break; + default: NOT_REACHED(); } diff --git a/src/network/core/address.h b/src/network/core/address.h index 9515de976..2b5f7444f 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -79,13 +79,14 @@ public: * Create a network address based on a unresolved host and port * @param ip the unresolved hostname * @param port the port + * @param family the address family */ - NetworkAddress(const char *hostname = "0.0.0.0", uint16 port = 0) : + NetworkAddress(const char *hostname = "0.0.0.0", uint16 port = 0, int family = AF_INET) : hostname(strdup(hostname)), address_length(0) { memset(&this->address, 0, sizeof(this->address)); - this->address.ss_family = AF_INET; + this->address.ss_family = family; this->SetPort(port); } |