libfreerdp-core: add usage of TargetNetAddresses in ip-based redirection when hostname resolution fails

This commit is contained in:
Marc-André Moreau 2014-12-26 13:49:25 -05:00
parent 5e6b3de74e
commit 9dd77ae14a

View File

@ -531,11 +531,32 @@ int uds_connect(const char* path)
#endif
}
BOOL freerdp_tcp_resolve_hostname(const char* hostname)
{
int status;
struct addrinfo hints;
struct addrinfo* result = NULL;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
status = getaddrinfo(hostname, NULL, &hints, &result);
if (status)
return FALSE;
freeaddrinfo(result);
return TRUE;
}
BOOL freerdp_tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout)
{
int status;
UINT32 option_value;
socklen_t option_len;
rdpSettings* settings = tcp->settings;
if (!hostname)
return FALSE;
@ -587,14 +608,26 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeou
if (tcp->sockfd < 0)
return FALSE;
#else /* NO_IPV6 */
struct addrinfo hints = {0};
struct addrinfo hints;
struct addrinfo *result;
struct addrinfo *tmp;
char port_str[11];
//ZeroMemory(&hints, sizeof(struct addrinfo));
if (!settings->GatewayEnabled)
{
if (!freerdp_tcp_resolve_hostname(hostname))
{
if (settings->TargetNetAddressCount > 0)
{
hostname = settings->TargetNetAddresses[0];
}
}
}
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM;
/*
* FIXME: the following is a nasty workaround. Find a cleaner way:
* Either set port manually afterwards or get it passed as string?