]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib/hostip6.c: make NAT64 address synthesis on macOS work
authorRadek Zajic <radek.zajic@showmax.com>
Mon, 24 May 2021 14:38:40 +0000 (16:38 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 25 May 2021 10:45:56 +0000 (12:45 +0200)
Closes #7121

CMakeLists.txt
configure.ac
lib/curl_setup.h
lib/hostip.c
m4/curl-sysconfig.m4 [new file with mode: 0644]

index 0e06f1bbb56216a00f8901fbba45d73c5139bba1..f5f560292f8efafe4990d39f2cadb54677a66200 100644 (file)
@@ -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)
index 4d2f4dcc6dcf5c5dfd6fdd35405d8eb4e1539f0c..e378e7efb3ab3fb895ee0d7e4bd2fd3fb3f3c778 100755 (executable)
@@ -479,6 +479,7 @@ CURL_CHECK_WIN32_LARGEFILE
 CURL_CHECK_WIN32_CRYPTO
 
 CURL_DARWIN_CFLAGS
+CURL_DARWIN_SYSTEMCONFIGURATION
 CURL_SUPPORTS_BUILTIN_AVAILABLE
 
 
index b6ef532448719aff0f0c22b5216959c12ff4f48b..be4a58d4b624989129a670f5ac15aed750218cc1 100644 (file)
  * 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
index 45190a100b9f8163699e266147c42ca9bfec5846..055c190d1cdc430c2fd8610e5b961a0bf2215865 100644 (file)
 #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 (file)
index 0000000..0f6462f
--- /dev/null
@@ -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
+])