From f6b6eba0ab042515f6fa8d8c51bd958e7e4fa8fb Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 8 Aug 2018 10:25:09 +0200 Subject: [PATCH] Try redirection FQDN first, but check if it is resolvable. --- libfreerdp/core/connection.c | 53 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 5f029b3..4cdfaed 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -412,29 +412,48 @@ BOOL rdp_client_redirect(rdpRdp* rdp) } else { - if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS) - { - free(settings->ServerHostname); - settings->ServerHostname = _strdup(settings->TargetNetAddress); + BOOL useFQDN = FALSE; - if (!settings->ServerHostname) - return FALSE; - } - else if (settings->RedirectionFlags & LB_TARGET_FQDN) + if (settings->RedirectionFlags & LB_TARGET_FQDN) { - free(settings->ServerHostname); - settings->ServerHostname = _strdup(settings->RedirectionTargetFQDN); + int status; + struct addrinfo hints = { 0 }; + struct addrinfo* result = NULL; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + status = getaddrinfo(settings->RedirectionTargetFQDN, NULL, &hints, &result); + + if (status == 0) + { + freeaddrinfo(result); + free(settings->ServerHostname); + settings->ServerHostname = _strdup(settings->RedirectionTargetFQDN); - if (!settings->ServerHostname) - return FALSE; + if (!settings->ServerHostname) + return FALSE; + + useFQDN = TRUE; + } } - else if (settings->RedirectionFlags & LB_TARGET_NETBIOS_NAME) + + if (!useFQDN) { - free(settings->ServerHostname); - settings->ServerHostname = _strdup(settings->RedirectionTargetNetBiosName); + if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS) + { + free(settings->ServerHostname); + settings->ServerHostname = _strdup(settings->TargetNetAddress); - if (!settings->ServerHostname) - return FALSE; + if (!settings->ServerHostname) + return FALSE; + } + else if (settings->RedirectionFlags & LB_TARGET_NETBIOS_NAME) + { + free(settings->ServerHostname); + settings->ServerHostname = _strdup(settings->RedirectionTargetNetBiosName); + + if (!settings->ServerHostname) + return FALSE; + } } } -- 2.7.4