This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangyang-libzt/docs/osx.md

78 lines
2.6 KiB
Markdown
Raw Normal View History

2016-06-14 17:00:44 -07:00
OSX + ZeroTier SDK
2016-06-14 16:01:19 -07:00
====
Welcome!
2016-07-14 08:40:40 -07:00
Imagine a flat, encrypted, no-configuration LAN for all of the instances of your OSX app.
2016-06-14 16:01:19 -07:00
***
2016-08-03 15:22:51 -07:00
2016-12-08 13:14:12 -08:00
## Via Traditional Linking (Service and Intercept)
2016-06-22 11:35:12 -07:00
2016-12-08 13:14:12 -08:00
- This will allow the interception of traditional socket API calls such as `socket()`, `connect()`, `bind()`, etc.
2016-12-08 13:14:12 -08:00
Build against our library:
2016-06-22 11:35:12 -07:00
gcc app.c -o app libztintercept.so
2016-07-14 08:40:40 -07:00
export ZT_NC_NETWORK=/tmp/sdk-test-home/nc_8056c2e21c000001
2016-06-22 11:35:12 -07:00
Start service
./zerotier-sdk-service -d -p8000 /tmp/sdk-test-home &
2016-06-22 11:35:12 -07:00
Run application
./app
2016-06-22 11:35:12 -07:00
## Via `DYLD_LIBRARY_PATH` (Injecting code dynamically at runtime)
As of the release of El Capitan, Apple requires one to turn off System Integrity Protection for code injection from external libraries. This method of intercepting network calls is now deprecated and we are investigating new methods for future releases of the SDK. If you still wish to use this method just `export DYLD_LIBRARY_PATH=./path/to/libztintercept.so:$DYLD_LIBRARY_PATH`. Also set `ZT_NC_NETWORK` appropriately.
2016-08-03 15:22:51 -07:00
## Via App Framework in XCode
2016-06-22 11:35:12 -07:00
2016-07-14 08:40:40 -07:00
***
**Step 1: Build OSX framework**
2016-06-22 11:35:12 -07:00
- `make osx_app_framework`
- This will output to `build/osx_app_framework/Release/ZeroTierSDK_OSX.framework`
2016-06-22 11:35:12 -07:00
2016-07-14 08:40:40 -07:00
**Step 2: Integrate SDK into project**
2016-06-22 11:43:29 -07:00
2016-07-14 08:40:40 -07:00
- Add the resultant framework package to your project
- Add `src` directory to *Build Settings -> Header Search Paths*
- Add `build/osx_app_framework/Release/` to *Build Settings -> Framework Search Paths*
- Add `ZeroTierSDK.frameworkOSX` to *General->Embedded Binaries*
- Add `src/wrappers/swift/ZTSDK.swift`, `src/wrappers/swift/XcodeWrapper.cpp`, and `src/wrappers/swift/XcodeWrapper.hpp` to your project:
- Set `src/wrappers/swift/Apple-Bridging-Header.h` as your bridging-header in *Build Settings -> Objective-C Bridging-header*
2016-06-22 11:35:12 -07:00
2016-07-14 08:40:40 -07:00
**Step 3: Start the ZeroTier service**
2016-06-22 11:48:10 -07:00
2016-09-09 12:02:27 -07:00
Start the service:
2016-07-14 08:40:40 -07:00
```
2016-09-09 12:17:42 -07:00
zt.start_service("."); // Where the ZeroTier config files for this app will be stored
2016-09-09 12:02:27 -07:00
zt.join_network(nwid);
2016-07-14 08:40:40 -07:00
```
2016-09-09 12:02:27 -07:00
Listen for incoming connections:
2016-07-14 08:40:40 -07:00
```
2016-09-09 12:02:27 -07:00
let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0)
let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort))
2016-09-09 12:17:42 -07:00
let bind_err: Int32 = zt.bind(sock, ztaddr)
2016-09-09 12:02:27 -07:00
zt_listen(sock, 1);
2016-09-09 12:17:42 -07:00
let accepted_sock: Int32 = zt.accept(sock, ztaddr)
2016-09-09 12:02:27 -07:00
```
Or, establish a connection:
```
let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0)
let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort))
2016-09-09 12:17:42 -07:00
let connect_err: Int32 = zt.connect(sock, ztaddr)
2016-07-14 08:40:40 -07:00
```
2016-09-09 12:17:42 -07:00
**Alternative APIs**
2016-06-22 11:48:10 -07:00
2016-12-08 13:14:12 -08:00
Click [here](../../../../docs/api_discussion.md) to learn more about alternative APIs such as the Intercept and SOCKS5 Proxy.