From 849a8075c586418645072e99693ba1245fadb4b3 Mon Sep 17 00:00:00 2001 From: Koichiro IWAO Date: Fri, 28 Oct 2016 17:07:39 +0900 Subject: [PATCH] common: If IPv6 not supported, fall back to IPv4 The system to run xrdp does not necessarily support IPv6 even though it is compiled with IPv6. Fixes #432. --- common/os_calls.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/common/os_calls.c b/common/os_calls.c index df08b9e3b4..d8e711b887 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -416,11 +416,27 @@ g_tcp_socket(void) #if defined(XRDP_ENABLE_IPV6) rv = (int)socket(AF_INET6, SOCK_STREAM, 0); + if (rv < 0) + { + log_message(LOG_LEVEL_ERROR, "g_tcp_socket: %s", g_get_strerror()); + + switch (errno) + { + case EAFNOSUPPORT: /* if IPv6 not supported, retry IPv4 */ + log_message(LOG_LEVEL_INFO, "IPv6 not supported, falling back to IPv4"); + rv = (int)socket(AF_INET, SOCK_STREAM, 0); + break; + + default: + return -1; + } + } #else rv = (int)socket(AF_INET, SOCK_STREAM, 0); #endif if (rv < 0) { + log_message(LOG_LEVEL_ERROR, "g_tcp_socket: %s", g_get_strerror()); return -1; } #if defined(XRDP_ENABLE_IPV6)