summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadek Zajic <radek.zajic@showmax.com>2021-05-24 16:38:40 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-05-25 12:45:56 +0200
commit31f631a142d855f069242f3e0c643beec25d1b51 (patch)
treeaef4a898796ddf11f4d48dc80c445465c3784e66
parenta63dae5d078b24dc441e421a37fa7daf09fc4768 (diff)
downloadcurl-31f631a142d855f069242f3e0c643beec25d1b51.tar.gz
lib/hostip6.c: make NAT64 address synthesis on macOS work
Closes #7121
-rw-r--r--CMakeLists.txt8
-rwxr-xr-xconfigure.ac1
-rw-r--r--lib/curl_setup.h4
-rw-r--r--lib/hostip.c17
-rw-r--r--m4/curl-sysconfig.m452
5 files changed, 82 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0e06f1bbb..f5f560292 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -386,6 +386,14 @@ if(CMAKE_USE_SECTRANSP)
list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
endif()
+if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+ find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration")
+ if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
+ message(FATAL_ERROR "SystemConfiguration framework not found")
+ endif()
+ list(APPEND CURL_LIBS "${SYSTEMCONFIGURATION_FRAMEWORK}")
+endif()
+
if(CMAKE_USE_OPENSSL)
find_package(OpenSSL REQUIRED)
set(SSL_ENABLED ON)
diff --git a/configure.ac b/configure.ac
index 4d2f4dcc6..e378e7efb 100755
--- a/configure.ac
+++ b/configure.ac
@@ -479,6 +479,7 @@ CURL_CHECK_WIN32_LARGEFILE
CURL_CHECK_WIN32_CRYPTO
CURL_DARWIN_CFLAGS
+CURL_DARWIN_SYSTEMCONFIGURATION
CURL_SUPPORTS_BUILTIN_AVAILABLE
diff --git a/lib/curl_setup.h b/lib/curl_setup.h
index b6ef53244..be4a58d4b 100644
--- a/lib/curl_setup.h
+++ b/lib/curl_setup.h
@@ -247,7 +247,11 @@
* performing this task will result in a synthesized IPv6 address.
*/
#if defined(__APPLE__) && !defined(USE_ARES)
+#include <TargetConditionals.h>
#define USE_RESOLVE_ON_IPS 1
+# if defined(TARGET_OS_OSX) && TARGET_OS_OSX
+# define CURL_OSX_CALL_COPYPROXIES 1
+# endif
#endif
#ifdef USE_LWIPSOCK
diff --git a/lib/hostip.c b/lib/hostip.c
index 45190a100..055c190d1 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -68,6 +68,10 @@
#include "curl_memory.h"
#include "memdebug.h"
+#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES)
+#include <SystemConfiguration/SystemConfiguration.h>
+#endif
+
#if defined(CURLRES_SYNCH) && \
defined(HAVE_ALARM) && defined(SIGALRM) && defined(HAVE_SIGSETJMP)
/* alarm-based timeouts can only be used with all the dependencies satisfied */
@@ -529,6 +533,19 @@ enum resolve_t Curl_resolv(struct Curl_easy *data,
return CURLRESOLV_ERROR;
}
+#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES)
+ /*
+ * The automagic conversion from IPv4 literals to IPv6 literals only works
+ * if the SCDynamicStoreCopyProxies system function gets called first. As
+ * Curl currently doesn't support system-wide HTTP proxies, we therefore
+ * don't use any value this function might return.
+ *
+ * This function is only available on a macOS and is not needed for
+ * IPv4-only builds, hence the conditions above.
+ */
+ SCDynamicStoreCopyProxies(NULL);
+#endif
+
#ifndef USE_RESOLVE_ON_IPS
/* First check if this is an IPv4 address string */
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
diff --git a/m4/curl-sysconfig.m4 b/m4/curl-sysconfig.m4
new file mode 100644
index 000000000..0f6462fab
--- /dev/null
+++ b/m4/curl-sysconfig.m4
@@ -0,0 +1,52 @@
+#***************************************************************************
+# _ _ ____ _
+# Project ___| | | | _ \| |
+# / __| | | | |_) | |
+# | (__| |_| | _ <| |___
+# \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at https://curl.se/docs/copyright.html.
+#
+# You may opt to use, copy, modify, merge, publish, distribute and/or sell
+# copies of the Software, and permit persons to whom the Software is
+# furnished to do so, under the terms of the COPYING file.
+#
+# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+# KIND, either express or implied.
+#
+#***************************************************************************
+
+AC_DEFUN([CURL_DARWIN_SYSTEMCONFIGURATION], [
+AC_MSG_CHECKING([whether to link macOS SystemConfiguration framework])
+case $host_os in
+ darwin*)
+ AC_COMPILE_IFELSE([
+ AC_LANG_PROGRAM([[
+#include <TargetConditionals.h>
+ ]],[[
+#if (TARGET_OS_OSX)
+ return 0;
+#else
+#error Not a macOS
+#endif
+ ]])
+ ],[
+ build_for_macos="yes"
+ ],[
+ build_for_macos="no"
+ ])
+ if test "x$build_for_macos" != xno; then
+ AC_MSG_RESULT(yes)
+ LDFLAGS="$LDFLAGS -framework SystemConfiguration"
+ else
+ AC_MSG_RESULT(no)
+ fi
+ ;;
+ *)
+ AC_MSG_RESULT(no)
+esac
+])