Fix local network discovery

alut-include-path
Lukas Werling 2017-01-07 17:52:54 +01:00
parent 97be97c94c
commit 85f5b3cb75
2 changed files with 8 additions and 4 deletions

View File

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

View File

@ -571,9 +571,13 @@ bool C4Network2HTTPClient::SetServer(const char *szServerAddress)
ServerAddr.SetPort(GetDefaultPort()); ServerAddr.SetPort(GetDefaultPort());
} }
// Remove port // Remove port
const char *pColon = strchr(Server.getData(), ':'); const char *firstColon = strchr(Server.getData(), ':');
if (pColon) const char *lastColon = strrchr(Server.getData(), ':');
Server.SetLength(pColon - 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 // Done
ResetError(); ResetError();
return true; return true;