diff options
author | rubidium <rubidium@openttd.org> | 2009-04-08 23:41:48 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-08 23:41:48 +0000 |
commit | 882e495f5c93512b39764273a61ead8f2954d6b6 (patch) | |
tree | 44a7e1a0333681858dd0d92d658d7151c5b7ea3e /src/network | |
parent | c2dbc8270be5b423019ea64e68e6b212d713c123 (diff) | |
download | openttd-882e495f5c93512b39764273a61ead8f2954d6b6.tar.xz |
(svn r15993) -Codechange: clean up/generalise the handling of the server list
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/address.h | 15 | ||||
-rw-r--r-- | src/network/core/os_abstraction.h | 4 | ||||
-rw-r--r-- | src/network/network_udp.cpp | 26 |
3 files changed, 26 insertions, 19 deletions
diff --git a/src/network/core/address.h b/src/network/core/address.h index a51339085..4c025b584 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -47,21 +47,6 @@ private: public: /** * Create a network address based on a resolved IP and port - * @param ip the resolved ip - * @param port the port - */ - NetworkAddress(in_addr_t ip, uint16 port) : - address_length(sizeof(sockaddr)) - { - *this->hostname = '\0'; - memset(&this->address, 0, sizeof(this->address)); - this->address.ss_family = AF_INET; - ((struct sockaddr_in*)&this->address)->sin_addr.s_addr = ip; - this->SetPort(port); - } - - /** - * Create a network address based on a resolved IP and port * @param address the IP address with port */ NetworkAddress(struct sockaddr_storage &address, size_t address_length) : diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index 28c53d91c..1a4bc1691 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -289,6 +289,10 @@ static inline bool SetNoDelay(SOCKET d) #endif } +/* Make sure these structures have the size we expect them to be */ +assert_compile(sizeof(in_addr) == 4); +assert_compile(sizeof(in6_addr) == 16); + #endif /* ENABLE_NETWORK */ #endif /* NETWORK_CORE_OS_ABSTRACTION_H */ diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp index 003900802..a087297e7 100644 --- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -270,8 +270,13 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE) } } - if (item->info.hostname[0] == '\0') + if (item->info.hostname[0] == '\0') { snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", client_addr->GetHostname()); + } + + if (client_addr->GetAddress()->ss_family == AF_INET6) { + strecat(item->info.server_name, " (IPv6)", lastof(item->info.server_name)); + } /* Check if we are allowed on this server based on the revision-match */ item->info.version_compatible = IsNetworkCompatibleVersion(item->info.server_revision); @@ -294,12 +299,25 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_MASTER_RESPONSE_LIST) if (type < SLT_END) { for (int i = p->Recv_uint16(); i != 0 ; i--) { - uint32 ip = TO_LE32(p->Recv_uint32()); - uint16 port = p->Recv_uint16(); + sockaddr_storage addr_storage; + memset(&addr_storage, 0, sizeof(addr_storage)); + + if (type == SLT_IPv4) { + addr_storage.ss_family = AF_INET; + ((sockaddr_in*)&addr_storage)->sin_addr.s_addr = TO_LE32(p->Recv_uint32()); + } else { + assert(type == SLT_IPv6); + addr_storage.ss_family = AF_INET6; + byte *addr = (byte*)&((sockaddr_in6*)&addr_storage)->sin6_addr; + for (uint i = 0; i < sizeof(in6_addr); i++) *addr++ = p->Recv_uint8(); + } + NetworkAddress addr(addr_storage, type == SLT_IPv4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6)); + addr.SetPort(p->Recv_uint16()); /* Somehow we reached the end of the packet */ if (this->HasClientQuit()) return; - NetworkUDPQueryServer(NetworkAddress(ip, port)); + + NetworkUDPQueryServer(addr); } } } |