Skip to content

Commit

Permalink
Do not resolve HostName if HostName is already a valid IPv4 address.
Browse files Browse the repository at this point in the history
Do not resolve HostName if HostName is already a valid IPv4 address.
  • Loading branch information
Cyx69 committed Jan 17, 2017
1 parent 0e6c177 commit 3ecbaf8
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,34 @@ bool APerceptionNeuronController::Connect(FString HostName, int32 Port)
if (ReceiverSocket == NULL)
return false;

auto ResolveInfo = SocketSubSystem->GetHostByName(TCHAR_TO_ANSI(*HostName));
while (!ResolveInfo->IsComplete());
// Is HostName already a valid IPv4 address?
bool bValidAddress = false;
uint32 IP = 0;
FIPv4Address IPv4Address;
if (true == FIPv4Address::Parse(HostName, IPv4Address))
{
IP = IPv4Address.Value;
bValidAddress = true;
}
else
{ // Resolve HostName
auto ResolveInfo = SocketSubSystem->GetHostByName(TCHAR_TO_ANSI(*HostName));
while (!ResolveInfo->IsComplete());

if (ResolveInfo->GetErrorCode() == 0)
{
const FInternetAddr* Addr = &ResolveInfo->GetResolvedAddress();
Addr->GetIp(IP);
bValidAddress = true;
}
}

if (ResolveInfo->GetErrorCode() == 0)
// Connect
if (bValidAddress)
{
const FInternetAddr* Addr = &ResolveInfo->GetResolvedAddress();
uint32 IP;
Addr->GetIp(IP);

TSharedRef<FInternetAddr> InetAddr = SocketSubSystem->CreateInternetAddr();
InetAddr->SetIp(IP);
InetAddr->SetPort(Port);

bConnected = ReceiverSocket->Connect(*InetAddr);
}
}
Expand Down

0 comments on commit 3ecbaf8

Please sign in to comment.