Skip to content

Commit

Permalink
Fixed compilation errors when targeting IOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Jul 20, 2023
1 parent 521f1e9 commit a110c15
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.12)

include(CheckIncludeFile)

option(PROXYRES_CURL "Enable support for downloading PAC scripts using curl." OFF)
option(PROXYRES_EXECUTE "Enable support for PAC script execution." ON)

Expand Down Expand Up @@ -187,6 +189,13 @@ target_include_directories(proxyres PRIVATE
target_include_directories(proxyres PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)

if(NOT WIN32)
check_include_file("net/if_arp.h" HAVE_NET_IF_ARP_H)
if(HAVE_NET_IF_ARP_H)
target_compile_definitions(proxyres PRIVATE HAVE_NET_IF_ARP_H)
endif()
endif()

if(PROXYRES_CURL AND (PROXYRES_EXECUTE OR PROXYRES_BUILD_CLI))
if(NOT TARGET CURL::libcurl)
include(FetchContent)
Expand Down
19 changes: 15 additions & 4 deletions config_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <CoreFoundation/CoreFoundation.h>
#include <CFNetwork/CFNetwork.h>
#include <TargetConditionals.h>

#include "config.h"
#include "config_i.h"
Expand All @@ -20,8 +21,8 @@ static bool get_cf_dictionary_bool(CFDictionaryRef dictionary, CFStringRef key)
}

bool proxy_config_mac_get_auto_discover(void) {
#if !TARGET_OS_IPHONE
bool auto_discover = false;

CFDictionaryRef proxy_settings = CFNetworkCopySystemProxySettings();
if (!proxy_settings)
return false;
Expand All @@ -32,6 +33,9 @@ bool proxy_config_mac_get_auto_discover(void) {

CFRelease(proxy_settings);
return auto_discover;
#else
return false;
#endif
}

char *proxy_config_mac_get_auto_config_url(void) {
Expand Down Expand Up @@ -76,6 +80,7 @@ char *proxy_config_mac_get_proxy(const char *scheme) {
CFStringRef host_index = kCFNetworkProxiesHTTPProxy;
CFStringRef port_index = kCFNetworkProxiesHTTPPort;

#if !TARGET_OS_IPHONE
if (strncasecmp(scheme, "https", 5) == 0) {
enable_index = kCFNetworkProxiesHTTPSEnable;
host_index = kCFNetworkProxiesHTTPSProxy;
Expand All @@ -93,6 +98,7 @@ char *proxy_config_mac_get_proxy(const char *scheme) {
host_index = kCFNetworkProxiesRTSPProxy;
port_index = kCFNetworkProxiesRTSPPort;
}
#endif

CFDictionaryRef proxy_settings = CFNetworkCopySystemProxySettings();
if (!proxy_settings)
Expand Down Expand Up @@ -147,16 +153,21 @@ char *proxy_config_mac_get_bypass_list(void) {
return NULL;

// Get whether to exclude simple hostnames
bool exclude_simple_hostnames = get_cf_dictionary_bool(proxy_settings, kCFNetworkProxiesExcludeSimpleHostnames);
bool exclude_simple_hostnames = false;
#if !TARGET_OS_IPHONE
exclude_simple_hostnames = get_cf_dictionary_bool(proxy_settings, kCFNetworkProxiesExcludeSimpleHostnames);
if (exclude_simple_hostnames)
bypass_list_count++;

#endif
// Get exception list
CFArrayRef exceptions_list = CFDictionaryGetValue(proxy_settings, kCFNetworkProxiesExceptionsList);
CFArrayRef exceptions_list = NULL;
#if !TARGET_OS_IPHONE
exceptions_list = CFDictionaryGetValue(proxy_settings, kCFNetworkProxiesExceptionsList);
if (exceptions_list) {
exception_count = CFArrayGetCount(exceptions_list);
bypass_list_count += exception_count;
}
#endif

if (!bypass_list_count)
goto bypass_list_error;
Expand Down
7 changes: 6 additions & 1 deletion net_adapter_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#include <unistd.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <net/if_arp.h>
#ifdef HAVE_NET_IF_ARP_H
# include <net/if_arp.h>
#else
# define ARPHRD_ETHER 1 // Ethernet hardware format
# define ARPHRD_IEEE802 6 // IEEE 802.2 Ethernet/TR/TB
#endif
#include <sys/ioctl.h>

#include "log.h"
Expand Down
6 changes: 5 additions & 1 deletion net_adapter_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <net/if_arp.h>
#ifdef HAVE_NET_IF_ARP_H
# include <net/if_arp.h>
#else
# define ARPHRD_ETHER 1 // Ethernet hardware format
#endif
#include <net/if_dl.h>
#include <sys/sysctl.h>

Expand Down
8 changes: 8 additions & 0 deletions wpad_dhcp_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCDynamicStoreCopyDHCPInfo.h>
#include <TargetConditionals.h>

#include "net_adapter.h"

char *wpad_dhcp_adapter_mac(uint8_t bind_ip[4], net_adapter_s *adapter, int32_t timeout_sec) {
#if !TARGET_OS_IPHONE
CFDictionaryRef dhcp_info = NULL;
CFDataRef dhcp_wpad_url = NULL;
char *wpad = NULL;
Expand All @@ -24,4 +26,10 @@ char *wpad_dhcp_adapter_mac(uint8_t bind_ip[4], net_adapter_s *adapter, int32_t
wpad = strdup((const char *)CFDataGetBytePtr(dhcp_wpad_url));
CFRelease(dhcp_info);
return wpad;
#else
UNUSED(bind_ip);
UNUSED(adapter);
UNUSED(timeout_sec);
return NULL;
#endif
}

0 comments on commit a110c15

Please sign in to comment.