[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/hostip.c: make NAT64 address synthesis on macOS working #7121

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,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)
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ CURL_CHECK_WIN32_LARGEFILE
CURL_CHECK_WIN32_CRYPTO

CURL_DARWIN_CFLAGS
CURL_DARWIN_SYSTEMCONFIGURATION
CURL_SUPPORTS_BUILTIN_AVAILABLE


Expand Down
4 changes: 4 additions & 0 deletions lib/curl_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions lib/hostip.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
#include "curl_memory.h"
#include "memdebug.h"

#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES)
#include <SystemConfiguration/SystemConfiguration.h>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure here if to wrap it with more conditions like the ones below - I need to check if it exists on targets like iOS. If not, the extra #if wrapping will be needed (or another, shared #define created elsewhere).

#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 */
Expand Down Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions m4/curl-sysconfig.m4
Original file line number Diff line number Diff line change
@@ -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
])