diff --git a/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj b/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj index b3e3921..71005f5 100644 --- a/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj +++ b/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.pbxproj @@ -1492,6 +1492,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; OTHER_CFLAGS = ( "-DSDK", + "-DSDK_SERVICE", + "-DSDK_BUNDLED", "-DSDK_DEBUG", "-D__XCODE__", ); @@ -1520,6 +1522,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; OTHER_CFLAGS = ( "-DSDK", + "-DSDK_SERVICE", + "-DSDK_BUNDLED", "-DSDK_DEBUG", "-D__XCODE__", ); diff --git a/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate b/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate index 61649db..d06a689 100644 Binary files a/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate and b/integrations/apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.pbxproj b/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.pbxproj index 98a6af0..2c165e8 100644 --- a/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.pbxproj +++ b/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 7C3504EE1D2AD9D4007EBD64 /* Example_OSX-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Example_OSX-Bridging-Header.h"; sourceTree = ""; }; 7CA571031D1B0D9500720883 /* ZeroTierSDK_OSX.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ZeroTierSDK_OSX.framework; path = ../../../build/OSX_app_framework/Debug/ZeroTierSDK_OSX.framework; sourceTree = ""; }; 7CA571081D1B1DCB00720883 /* ZeroTierSDK_OSX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ZeroTierSDK_OSX.h; path = ../../ZeroTierSDK_Apple/ZeroTierSDK_OSX/ZeroTierSDK_OSX.h; sourceTree = ""; }; 7CFCB42D1D1AFEE800D3E66C /* Example_OSX_App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example_OSX_App.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -80,6 +81,7 @@ 7CFCB4341D1AFEE800D3E66C /* Assets.xcassets */, 7CFCB4361D1AFEE800D3E66C /* Main.storyboard */, 7CFCB4391D1AFEE800D3E66C /* Info.plist */, + 7C3504EE1D2AD9D4007EBD64 /* Example_OSX-Bridging-Header.h */, ); path = Example_OSX_App; sourceTree = ""; @@ -263,10 +265,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../src"; INFOPLIST_FILE = Example_OSX_App/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "zerotier.Example-OSX-App"; PRODUCT_NAME = "$(TARGET_NAME)"; + "SWIFT_OBJC_BRIDGING_HEADER[arch=*]" = "Example_OSX_App/Example_OSX-Bridging-Header.h"; }; name = Debug; }; @@ -275,6 +279,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; COMBINE_HIDPI_IMAGES = YES; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../src"; INFOPLIST_FILE = Example_OSX_App/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "zerotier.Example-OSX-App"; diff --git a/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate b/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate index 093efaf..3405433 100644 Binary files a/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate and b/integrations/apple/example_app/Example_OSX_App.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/integrations/apple/example_app/Example_OSX_App/Example_OSX-Bridging-Header.h b/integrations/apple/example_app/Example_OSX_App/Example_OSX-Bridging-Header.h new file mode 100644 index 0000000..811b2ff --- /dev/null +++ b/integrations/apple/example_app/Example_OSX_App/Example_OSX-Bridging-Header.h @@ -0,0 +1,35 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#ifndef Example_OSX_Bridging_Header_h +#define Example_OSX_Bridging_Header_h + +int start_intercept(); +int start_service(const char * path); +int join_network(const char * nwid); +void disable_intercept(); +void enable_intercept(); + +#include +#include "SDK_Signatures.h" + +void zt_join_network(const char *nwid); +void zt_leave_network(const char *nwid); + +// Direct Call ZT API +// These functions will provide direct access to ZT-enabled sockets with no hassle +int zts_connect(CONNECT_SIG); +int zt_bind(BIND_SIG); +int zt_accept(ACCEPT_SIG); +int zt_listen(LISTEN_SIG); +int zts_socket(SOCKET_SIG); +int zt_setsockopt(SETSOCKOPT_SIG); +int zt_getsockopt(GETSOCKOPT_SIG); +int zt_close(CLOSE_SIG); +int zt_getsockname(GETSOCKNAME_SIG); + + +#endif /* Example_OSX_Bridging_Header_h */ + + diff --git a/integrations/apple/example_app/Example_OSX_App/ViewController.swift b/integrations/apple/example_app/Example_OSX_App/ViewController.swift index edb4991..b951878 100644 --- a/integrations/apple/example_app/Example_OSX_App/ViewController.swift +++ b/integrations/apple/example_app/Example_OSX_App/ViewController.swift @@ -7,7 +7,6 @@ // import Cocoa -i class ViewController: NSViewController { diff --git a/make-linux.mk b/make-linux.mk index 125e77e..f836ed5 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -70,7 +70,7 @@ remove_only_intermediates: linux_shared_lib: remove_only_intermediates $(OBJS) mkdir -p build/linux_shared_lib - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEFS) -DZT_SDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEFS) -DSDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl # Build liblwip.so which must be placed in ZT home for zerotier-netcon-service to work make -f make-liblwip.mk $(LWIP_FLAGS) # Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility diff --git a/make-mac.mk b/make-mac.mk index 3940dd6..bcbc1e9 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -83,7 +83,7 @@ remove_only_intermediates: osx_shared_lib: remove_only_intermediates $(OBJS) mkdir -p build/osx_shared_lib # Need to selectively rebuild one.cpp and OneService.cpp with ZT_SERVICE_NETCON and ZT_ONE_NO_ROOT_CHECK defined, and also NetconEthernetTap - $(CXX) $(CXXFLAGS) $(LDFLAGS) -DZT_SDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) -DSDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl # Build liblwip.so which must be placed in ZT home for zerotier-sdk-service to work make -f make-liblwip.mk # Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility diff --git a/src/SDK.h b/src/SDK.h index cb86e82..f9d9ab7 100644 --- a/src/SDK.h +++ b/src/SDK.h @@ -40,8 +40,9 @@ extern "C" { #define INTERCEPT_DISABLED 222 extern void load_symbols(); -void zt_init_rpc(char *path, char *nwid); +extern void zt_init_rpc(const char *path, const char *nwid); extern char *api_netpath; +extern char *debug_logfile; #if defined(__linux__) extern int (*realaccept4)(ACCEPT4_SIG); diff --git a/src/SDK_Debug.c b/src/SDK_Debug.c index 5c97150..3701dfc 100644 --- a/src/SDK_Debug.c +++ b/src/SDK_Debug.c @@ -42,6 +42,9 @@ #include #include +#ifndef SDK_DEBUG_H +#define SDK_DEBUG_H + // Set during make (e.g. make SDK_DEBUG=2) #define DEBUG_LEVEL 5 @@ -51,7 +54,7 @@ #define MSG_DEBUG 4 // Information which is only useful to someone debugging #define MSG_DEBUG_EXTRA 5 // If nothing in your world makes sense -char *debug_logfile = (char*)0; +//char *debug_logfile = (char*)0; void dwr(int level, const char *fmt, ... ); void dwr(int level, const char *fmt, ... ) @@ -78,6 +81,7 @@ void dwr(int level, const char *fmt, ... ) if(!debug_logfile) { // Try to get logfile from env debug_logfile = getenv("ZT_SDK_LOGFILE"); } + /* if(debug_logfile) { FILE *file = fopen(debug_logfile,"a"); fprintf(file, "%s [tid=%7d] ", timestring, tid); @@ -85,6 +89,7 @@ void dwr(int level, const char *fmt, ... ) fclose(file); va_end(ap); } + */ #endif va_start(ap, fmt); fprintf(stderr, "%s [tid=%7d] ", timestring, tid); @@ -116,4 +121,6 @@ extern "C" { } // extern "C" #endif +#endif + #endif \ No newline at end of file diff --git a/src/SDK_ServiceSetup.cpp b/src/SDK_ServiceSetup.cpp index ad9dfa0..aa775aa 100644 --- a/src/SDK_ServiceSetup.cpp +++ b/src/SDK_ServiceSetup.cpp @@ -47,6 +47,8 @@ #include "OSUtils.hpp" #include "SDK.h" +void zt_init_rpc(const char * path, const char * nwid); + #include "SDK_Debug.h" #include "SDK_ServiceSetup.hpp" @@ -57,7 +59,6 @@ pthread_key_t thr_id_key; static ZeroTier::OneService *volatile zt1Service; std::string homeDir; std::string netDir; -char *api_netpath; #ifdef __cplusplus extern "C" { @@ -134,10 +135,8 @@ extern "C" { JNIEXPORT void JNICALL Java_ZeroTier_SDK_startOneService(JNIEnv *env, jobject thisObj, jstring path) { //char * path; homeDir = (*env)->GetStringUTFChars(env, path, NULL); - #else - void *startOneService(void *thread_id, string path) { - homeDir = path; + void *startOneService(void *thread_id) { #endif #if defined(SDK_BUNDLED) @@ -159,7 +158,6 @@ extern "C" { #if defined(__UNITY_3D__) && !defined(__ANDROID__) && !defined(__IOS__) // Unity3D on a non-mobile platform homeDir = "" + current_dir; // homeDir shall be current dir - // homeDir = "/Users/Joseph/utest2/"; #endif #if defined(__ANDROID__) @@ -177,7 +175,6 @@ extern "C" { } LOGV("homeDir = %s", homeDir.c_str()); - // Where network .conf files will be stored netDir = homeDir + "/networks.d"; diff --git a/src/SDK_Sockets.c b/src/SDK_Sockets.c index 8c0e327..1f835e2 100644 --- a/src/SDK_Sockets.c +++ b/src/SDK_Sockets.c @@ -83,7 +83,7 @@ int (*realclose)(CLOSE_SIG); // ------------------------------------------------------------------------------ // Assembles (and/or) sets the RPC path for communication with the ZeroTier service - void zt_init_rpc(char *path, char *nwid) + void zt_init_rpc(const char *path, const char *nwid) { dwr(MSG_DEBUG, "zt_init_rpc\n"); // Just double check we have