Fix local network discovery

ipv6
Lukas Werling 2017-01-07 17:52:54 +01:00
parent 65d8c11450
commit 60560125dc
2 changed files with 8 additions and 4 deletions

View File

@ -64,7 +64,7 @@ bool C4Network2IODiscover::Init(uint16_t iPort)
bool C4Network2IODiscover::Announce()
{
// Announce our presence
C4Network2IODiscoverReply Reply = { 4, htons(iRefServerPort) };
C4Network2IODiscoverReply Reply = { 4, iRefServerPort };
return Send(C4NetIOPacket(&Reply, sizeof(Reply), false, DiscoveryAddr));
}

View File

@ -571,9 +571,13 @@ bool C4Network2HTTPClient::SetServer(const char *szServerAddress)
ServerAddr.SetPort(GetDefaultPort());
}
// Remove port
const char *pColon = strchr(Server.getData(), ':');
if (pColon)
Server.SetLength(pColon - Server.getData());
const char *firstColon = strchr(Server.getData(), ':');
const char *lastColon = strrchr(Server.getData(), ':');
if (firstColon)
// hostname/IPv4 address or IPv6 address with port (e.g. [::1]:1234)
if (firstColon == lastColon || (Server[0] == '[' && *(lastColon - 1) == ']'))
Server.SetLength(lastColon - Server.getData());
// Done
ResetError();
return true;