Implemented SOCKS proxy port file: networks.d/nwid.port
This commit is contained in:
@@ -22,7 +22,7 @@ In this example we aim to set up a minimal XCode project which contains all of t
|
||||
- Add `build/ios_app_framework/Release-iphoneos/` to *Build Settings -> Framework Search Paths*
|
||||
- Add `ZeroTierSDK.frameworkiOS` to *General->Embedded Binaries*
|
||||
- Add `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project:
|
||||
- Add contents of `src/SDK_Apple-Bridging-Header.h` to your project’s bridging header.
|
||||
- Set `src/SDK_Apple-Bridging-Header.h` as your bridging-header in `Build Settings -> Objective-C Bridging-header`
|
||||
|
||||
**Step 3: Start the ZeroTier service**
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ Run application
|
||||
- Add `build/osx_app_framework/Release-iphoneos/` to *Build Settings -> Framework Search Paths*
|
||||
- Add `ZeroTierSDK.frameworkiOS` to *General->Embedded Binaries*
|
||||
- Add `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project:
|
||||
- Add contents of `src/SDK_Apple-Bridging-Header.h` to your project’s bridging header.
|
||||
- Set `src/SDK_Apple-Bridging-Header.h` as your bridging-header in `Build Settings -> Objective-C Bridging-header`
|
||||
|
||||
**Step 3: Start the ZeroTier service**
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ APP_CFLAGS := -g -DSDK_BUNDLED
|
||||
APP_PLATFORM := android-14
|
||||
|
||||
# Architectures
|
||||
APP_ABI := all
|
||||
# APP_ABI := all
|
||||
|
||||
#APP_ABI += arm64-v8a
|
||||
#APP_ABI += armeabi
|
||||
APP_ABI += armeabi
|
||||
#APP_ABI += armeabi-v7a
|
||||
#APP_ABI += mips
|
||||
#APP_ABI += mips64
|
||||
|
||||
@@ -44,14 +44,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}, 10000);
|
||||
*/
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch(java.lang.InterruptedException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create ZeroTier socket
|
||||
@@ -65,10 +58,19 @@ public class MainActivity extends AppCompatActivity {
|
||||
//int port = 8080;
|
||||
//SocketAddress sockaddr = new InetSocketAddress(addr, port);
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(15000);
|
||||
}
|
||||
catch(java.lang.InterruptedException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Connect to remote host
|
||||
//Log.d("","ztjniConnect()\n");
|
||||
//int err = zt.ztjniConnect(sock, "10.144.211.245", 8080);
|
||||
//Log.d("", "ztjniConnect() = " + err + "\n");
|
||||
Log.d("","ztjniConnect()\n");
|
||||
int err = zt.ztjniConnect(sock, "10.9.9.203", 8080);
|
||||
Log.d("", "ztjniConnect() = " + err + "\n");
|
||||
|
||||
// Set up example proxy connection to SDK proxy server
|
||||
/*
|
||||
|
||||
@@ -9,7 +9,7 @@ This short tutorial will show you how to enable ZeroTier functionality for your
|
||||
|
||||
In this example we aim to set up a minimal [Android Studio](https://developer.android.com/studio/index.html) project which contains all of the components necessary to enable ZeroTier for your app. If you'd rather skip all of these steps and grab the code, look in the [sdk/android](https://github.com/zerotier/ZeroTierOne/tree/dev/sdk/integrations/android/example_app) folder in the source tree. Otherwise, let's get started!
|
||||
|
||||
*NOTE: For Android JNI libraries to build you'll need to install [Android Studio](https://developer.android.com/studio/index.html) the [Android NDK](https://developer.android.com/ndk/index.html), and you'll need to tell our project where you put it by putting the path in [this file](Android/proj/local.properties), you'll need to install the Android Build-Tools (this can typically be done through the editor the first time you start it up), and finally you should probably upgrade your Gradle plugin if it asks you to. If you don't have these things installed and configured we will detect that and just skip those builds automatically.*
|
||||
*NOTE: For Android JNI libraries to build you'll need to install [Android Studio](https://developer.android.com/studio/index.html) the [Android NDK](https://developer.android.com/ndk/index.html). Currently only Android NDK r10e is supported and can be found [here for OSX](http://dl.google.com/android/repository/android-ndk-r10e-darwin-x86_64.zip) and [here for Linux](http://dl.google.com/android/repository/android-ndk-r10e-linux-x86_64.zip). You'll need to tell our project where you put it by putting the path in [this file](Android/proj/local.properties), you'll need to install the Android Build-Tools (this can typically be done through the editor the first time you start it up), and finally you should probably upgrade your Gradle plugin if it asks you to. If you don't have these things installed and configured we will detect that and just skip those builds automatically.*
|
||||
|
||||
**Step 1: Select build targets**
|
||||
- Specify the target architectures you want to build in [Application.mk](android/java/jni/Application.mk). By default it will build `arm64-v8a`, `armeabi`, `armeabi-v7a`, `mips`, `mips64`, `x86`, and `x86_64`.
|
||||
|
||||
@@ -1436,6 +1436,7 @@
|
||||
"-D__IOS__",
|
||||
"-DLWIP_DEBUG",
|
||||
"-DSDK_BUNDLED",
|
||||
"-DUSE_SOCKS_PROXY",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-iOS";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -1469,6 +1470,7 @@
|
||||
"-DSDK",
|
||||
"-D__IOS__",
|
||||
"-DSDK_BUNDLED",
|
||||
"-DUSE_SOCKS_PROXY",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-iOS";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -1504,6 +1506,7 @@
|
||||
"-DSDK_DEBUG",
|
||||
"-D__XCODE__",
|
||||
"-DLWIP_DEBUG",
|
||||
"-DUSE_SOCKS_PROXY",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-OSX";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -1534,6 +1537,7 @@
|
||||
"-DSDK_SERVICE",
|
||||
"-DSDK_BUNDLED",
|
||||
"-D__XCODE__",
|
||||
"-DUSE_SOCKS_PROXY",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-OSX";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
|
||||
@@ -23,7 +23,7 @@ class ViewController: NSViewController {
|
||||
@IBOutlet weak var txtTX: NSTextField!
|
||||
@IBOutlet weak var txtRX: NSTextField!
|
||||
|
||||
var serverPort:Int32 = 5658
|
||||
var serverPort:Int32 = 8081
|
||||
var serverAddr:String = "10.9.9.203"
|
||||
|
||||
var sock:Int32 = -1
|
||||
@@ -150,11 +150,10 @@ class ViewController: NSViewController {
|
||||
@IBOutlet weak var btnSend: NSButton!
|
||||
@IBAction func UI_SendData(sender: AnyObject) {
|
||||
// Use ordinary read/write calls on ZeroTier socket
|
||||
|
||||
// TCP
|
||||
if(selectedProtocol == SOCK_STREAM)
|
||||
{
|
||||
write(sock, txtTX.description, 4);
|
||||
write(sock, txtTX.description, txtTX.description.characters.count);
|
||||
}
|
||||
// UDP
|
||||
if(selectedProtocol == SOCK_DGRAM)
|
||||
@@ -228,7 +227,7 @@ class ViewController: NSViewController {
|
||||
var service_thread : NSThread!
|
||||
func ztnc_start_service() {
|
||||
|
||||
// If you plan on using SOCKS Proxy
|
||||
// If you plan on using SOCKS Proxy, you don't need to initialize the RPC
|
||||
//start_service("/Users/Joseph/utest3")
|
||||
|
||||
// If you plan on using direct calls via RPC
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
@@ -15,7 +16,6 @@
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<animations/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sM5-GM-4R8">
|
||||
<rect key="frame" x="183" y="314" width="59" height="30"/>
|
||||
<state key="normal" title="Connect"/>
|
||||
<connections>
|
||||
<action selector="UI_Connect:" destination="BYZ-38-t0r" eventType="touchUpInside" id="5bz-xp-hzT"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9Qv-V2-VnT">
|
||||
<rect key="frame" x="157" y="264" width="46" height="30"/>
|
||||
@@ -28,6 +31,10 @@
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dwn-d8-Ki3">
|
||||
<rect key="frame" x="183" y="352" width="31" height="30"/>
|
||||
<state key="normal" title="Bind"/>
|
||||
<connections>
|
||||
<action selector="UI_Bind:" destination="BYZ-38-t0r" eventType="touchUpInside" id="03t-PZ-jaE"/>
|
||||
<action selector="btnBind:" destination="BYZ-38-t0r" eventType="touchUpInside" id="L5k-Rt-Lwm"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="ip address" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="6id-4C-E8W">
|
||||
<rect key="frame" x="20" y="275" width="147" height="30"/>
|
||||
@@ -40,7 +47,7 @@
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Protocol" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fn2-mn-MjK">
|
||||
<rect key="frame" x="20" y="171" width="64" height="21"/>
|
||||
<rect key="frame" x="20" y="149" width="64" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
@@ -62,28 +69,18 @@
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="mgD-Qw-uwg">
|
||||
<rect key="frame" x="38" y="133" width="121" height="29"/>
|
||||
<segments>
|
||||
<segment title="First"/>
|
||||
<segment title="Second"/>
|
||||
</segments>
|
||||
</segmentedControl>
|
||||
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="vwT-sy-CRY">
|
||||
<rect key="frame" x="38" y="200" width="121" height="29"/>
|
||||
<rect key="frame" x="38" y="178" width="121" height="29"/>
|
||||
<segments>
|
||||
<segment title="First"/>
|
||||
<segment title="Second"/>
|
||||
<segment title="TCP"/>
|
||||
<segment title="UDP"/>
|
||||
</segments>
|
||||
<connections>
|
||||
<action selector="protocolSelected:" destination="BYZ-38-t0r" eventType="valueChanged" id="PpI-tQ-h4C"/>
|
||||
</connections>
|
||||
</segmentedControl>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="API" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bOi-uD-nTW">
|
||||
<rect key="frame" x="20" y="104" width="26" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="ZeroTier iOS Example App" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h4F-YA-Rsh">
|
||||
<rect key="frame" x="20" y="20" width="200" height="21"/>
|
||||
<rect key="frame" x="20" y="42" width="200" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
@@ -91,6 +88,10 @@
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dp1-qj-Mq8">
|
||||
<rect key="frame" x="160" y="491" width="41" height="30"/>
|
||||
<state key="normal" title="read()"/>
|
||||
<connections>
|
||||
<action selector="UI_RX:" destination="BYZ-38-t0r" eventType="touchUpInside" id="JJJ-KW-5rF"/>
|
||||
<action selector="UI_TX:" destination="BYZ-38-t0r" eventType="touchUpInside" id="4h0-8L-CI3"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="EBa-HV-MZ5">
|
||||
<rect key="frame" x="20" y="453" width="132" height="30"/>
|
||||
@@ -117,23 +118,26 @@
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BfY-Te-yWV">
|
||||
<rect key="frame" x="20" y="492" width="45" height="30"/>
|
||||
<state key="normal" title="write()"/>
|
||||
<connections>
|
||||
<action selector="UI_TX:" destination="BYZ-38-t0r" eventType="touchUpInside" id="1ZJ-oI-a98"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IXS-rJ-KKM">
|
||||
<rect key="frame" x="141" y="55" width="90" height="30"/>
|
||||
<state key="normal" title="Join Network"/>
|
||||
<rect key="frame" x="208" y="77" width="30" height="30"/>
|
||||
<state key="normal" title="Join"/>
|
||||
<connections>
|
||||
<action selector="UI_JoinNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="kem-tf-1h1"/>
|
||||
<action selector="btnJoinNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="LSj-sJ-YEs"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="nwid" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="TvY-qZ-Zjm">
|
||||
<rect key="frame" x="20" y="55" width="97" height="30"/>
|
||||
<rect key="frame" x="20" y="77" width="167" height="30"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fU2-IH-aMf">
|
||||
<rect key="frame" x="141" y="83" width="102" height="30"/>
|
||||
<state key="normal" title="Leave Network"/>
|
||||
<rect key="frame" x="208" y="105" width="40" height="30"/>
|
||||
<state key="normal" title="Leave"/>
|
||||
<connections>
|
||||
<action selector="UI_LeaveNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="7Pg-IK-dMo"/>
|
||||
<action selector="btnLeaveNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="hmg-2Y-GCl"/>
|
||||
@@ -150,14 +154,23 @@
|
||||
</variation>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="btnBind" destination="dwn-d8-Ki3" id="FHu-Jd-wFh"/>
|
||||
<outlet property="btnConnect" destination="sM5-GM-4R8" id="Qun-r4-1OF"/>
|
||||
<outlet property="btnJoinNetwork" destination="IXS-rJ-KKM" id="C88-pL-2CT"/>
|
||||
<outlet property="btnLeaveNetwork" destination="fU2-IH-aMf" id="YwN-GB-2tc"/>
|
||||
<outlet property="btnRX" destination="dp1-qj-Mq8" id="vVr-s4-AX9"/>
|
||||
<outlet property="btnTX" destination="BfY-Te-yWV" id="KTA-eE-Rhy"/>
|
||||
<outlet property="segmentProtocol" destination="vwT-sy-CRY" id="BcU-8W-7kX"/>
|
||||
<outlet property="txtAddr" destination="6id-4C-E8W" id="q3w-zX-ZFf"/>
|
||||
<outlet property="txtNWID" destination="TvY-qZ-Zjm" id="1Jc-3U-PIE"/>
|
||||
<outlet property="txtPort" destination="uiQ-EM-gfq" id="CXT-Ed-idq"/>
|
||||
<outlet property="txtRX" destination="ZjP-35-mln" id="tOT-GE-wq8"/>
|
||||
<outlet property="txtTX" destination="EBa-HV-MZ5" id="WWI-4O-1iT"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="211" y="464"/>
|
||||
<point key="canvasLocation" x="-12" y="326"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
|
||||
@@ -10,27 +10,176 @@ import UIKit
|
||||
|
||||
class ViewController: UIViewController {
|
||||
|
||||
var serverPort:UInt16 = 8080
|
||||
var serverAddr:String = "10.9.9.203"
|
||||
var selectedProtocol:Int32 = 0
|
||||
var sock:Int32 = -1
|
||||
var accepted_sock:Int32 = -1
|
||||
|
||||
@IBOutlet weak var txtAddr: UITextField!
|
||||
@IBOutlet weak var txtPort: UITextField!
|
||||
|
||||
@IBOutlet weak var txtTX: UITextField!
|
||||
@IBOutlet weak var txtRX: UITextField!
|
||||
|
||||
@IBOutlet weak var btnTX: UIButton!
|
||||
|
||||
|
||||
@IBOutlet weak var btnRX: UIButton!
|
||||
@IBAction func UI_RX(sender: AnyObject) {
|
||||
// Use ordinary read/write calls on ZeroTier socket
|
||||
|
||||
// TCP
|
||||
if(selectedProtocol == SOCK_STREAM)
|
||||
{
|
||||
var buffer = [UInt8](count: 100, repeatedValue: 0)
|
||||
let str = "GET / HTTP/1.0\r\n\r\n"
|
||||
//let str = "Welcome to the machine"
|
||||
print("strlen = %d\n", str.characters.count)
|
||||
let encodedDataArray = [UInt8](str.utf8)
|
||||
|
||||
// read(accepted_sock, UnsafeMutablePointer<Void>([txtTX.stringValue]), 128);
|
||||
read(accepted_sock, &buffer, 100);
|
||||
print(buffer)
|
||||
|
||||
}
|
||||
// UDP
|
||||
if(selectedProtocol == SOCK_DGRAM)
|
||||
{
|
||||
// recvfrom
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@IBAction func UI_TX(sender: AnyObject) {
|
||||
// Use ordinary read/write calls on ZeroTier socket
|
||||
|
||||
// TCP
|
||||
if(selectedProtocol == SOCK_STREAM)
|
||||
{
|
||||
print("writing...")
|
||||
write(sock, txtTX.description, txtTX.description.characters.count);
|
||||
}
|
||||
// UDP
|
||||
if(selectedProtocol == SOCK_DGRAM)
|
||||
{
|
||||
// sendto
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBOutlet weak var txtNWID: UITextField!
|
||||
|
||||
@IBOutlet weak var btnJoinNetwork: UIButton!
|
||||
@IBAction func UI_JoinNetwork(sender: AnyObject) {
|
||||
zt_join_network("565799d8f65063e5")
|
||||
zt_join_network(txtNWID.text!)
|
||||
}
|
||||
|
||||
@IBOutlet weak var btnLeaveNetwork: UIButton!
|
||||
@IBAction func UI_LeaveNetwork(sender: AnyObject) {
|
||||
zt_leave_network("565799d8f65063e5")
|
||||
zt_leave_network(txtNWID.text!)
|
||||
}
|
||||
|
||||
@IBOutlet weak var segmentProtocol: UISegmentedControl!
|
||||
@IBAction func protocolSelected(sender: AnyObject) {
|
||||
switch sender.selectedSegmentIndex
|
||||
{
|
||||
case 0:
|
||||
selectedProtocol = SOCK_STREAM
|
||||
case 1:
|
||||
selectedProtocol = SOCK_DGRAM
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@IBOutlet weak var btnConnect: UIButton!
|
||||
@IBAction func UI_Connect(sender: AnyObject) {
|
||||
// TCP
|
||||
if(selectedProtocol == SOCK_STREAM)
|
||||
{
|
||||
sock = zts_socket(AF_INET, SOCK_STREAM, 0)
|
||||
var addr = sockaddr_in(sin_len: UInt8(sizeof(sockaddr_in)),
|
||||
sin_family: UInt8(AF_INET),
|
||||
sin_port: UInt16(serverPort).bigEndian,
|
||||
sin_addr: in_addr(s_addr: 0),
|
||||
sin_zero: (0,0,0,0,0,0,0,0))
|
||||
|
||||
inet_pton(AF_INET, serverAddr, &(addr.sin_addr));
|
||||
|
||||
let connect_err = zts_connect(sock, UnsafePointer<sockaddr>([addr]), UInt32(addr.sin_len))
|
||||
print("connect_err = \(connect_err),\(errno)")
|
||||
|
||||
if connect_err < 0 {
|
||||
let err = errno
|
||||
print("Error connecting IPv4 socket \(err)")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// UDP
|
||||
if(selectedProtocol == SOCK_DGRAM)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@IBOutlet weak var btnBind: UIButton!
|
||||
@IBAction func UI_Bind(sender: AnyObject) {
|
||||
// TCP
|
||||
if(selectedProtocol == SOCK_STREAM)
|
||||
{
|
||||
sock = zts_socket(AF_INET, SOCK_STREAM, 0)
|
||||
var addr = sockaddr_in(sin_len: UInt8(sizeof(sockaddr_in)),
|
||||
sin_family: UInt8(AF_INET),
|
||||
sin_port: UInt16(serverPort).bigEndian,
|
||||
sin_addr: in_addr(s_addr: 0),
|
||||
sin_zero: (0,0,0,0,0,0,0,0))
|
||||
|
||||
inet_pton(AF_INET, serverAddr, &(addr.sin_addr));
|
||||
|
||||
let bind_err = zts_bind(sock, UnsafePointer<sockaddr>([addr]), UInt32(addr.sin_len))
|
||||
|
||||
print("bind_err = \(bind_err),\(errno)")
|
||||
|
||||
if bind_err < 0 {
|
||||
let err = errno
|
||||
print("Error binding IPv4 socket \(err)")
|
||||
return
|
||||
}
|
||||
|
||||
// Put socket into listening state
|
||||
zts_listen(sock, 1);
|
||||
|
||||
// Accept connection
|
||||
var len:socklen_t = 0;
|
||||
var legIntPtr = withUnsafeMutablePointer(&len, { $0 })
|
||||
while(accepted_sock < 0) {
|
||||
accepted_sock = zts_accept(sock, UnsafeMutablePointer<sockaddr>([addr]), legIntPtr)
|
||||
}
|
||||
print("accepted connection")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ZeroTier service thread
|
||||
var service_thread : NSThread!
|
||||
func ztnc_start_service() {
|
||||
let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
|
||||
start_service(path[0])
|
||||
start_service_and_rpc(path[0],"565799d8f65063e5")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
txtNWID.text = "565799d8f65063e5"
|
||||
txtTX.text = "welcome to the machine"
|
||||
txtAddr.text = "10.9.9.203"
|
||||
txtPort.text = "8080"
|
||||
selectedProtocol = SOCK_STREAM
|
||||
|
||||
// ZeroTier Service thread
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
|
||||
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
|
||||
|
||||
@@ -153,6 +153,4 @@ clean:
|
||||
-find . -type f \( -name '*.o' -o -name '*.so' -o -name '*.o.d' -o -name '*.out' -o -name '*.log' \) -delete
|
||||
# Remove junk generated by Android builds
|
||||
-cd $(INT)/android/android_jni_lib/proj; ./gradlew clean
|
||||
-rm -rf $(INT)/android/android_jni_lib/proj/.gradle
|
||||
-rm -rf $(INT)/android/android_jni_lib/proj/.idea
|
||||
-rm -rf $(INT)/android/android_jni_lib/proj/build
|
||||
|
||||
@@ -156,11 +156,7 @@ clean:
|
||||
test -s /usr/bin/javac || { echo "Javac not found"; exit 1; }
|
||||
|
||||
-cd $(INT)/android/android_jni_lib/proj; ./gradlew clean
|
||||
-rm -rf $(INT)/android/android_jni_lib/proj/.gradle
|
||||
-rm -rf $(INT)/android/android_jni_lib/proj/.idea
|
||||
-rm -rf $(INT)/android/android_jni_lib/proj/build
|
||||
|
||||
# example android app project
|
||||
-cd $(INT)/android/example_app; ./gradlew clean
|
||||
-rm -rf $(INT)/android/example_app/.idea
|
||||
-rm -rf $(INT)/android/example_app/.gradle
|
||||
|
||||
@@ -135,8 +135,8 @@ NetconEthernetTap::NetconEthernetTap(
|
||||
|
||||
// Start SOCKS5 Proxy server
|
||||
// For use when traditional syscall hooking isn't available (ex. some APIs on iOS and Android)
|
||||
#if defined(USE_SOCKS_PROXY) || defined(__ANDROID__)
|
||||
StartProxy(sockPath);
|
||||
#if defined(USE_SOCKS_PROXY)
|
||||
StartProxy(sockPath, _homePath.c_str(), _nwid);
|
||||
#endif
|
||||
|
||||
Utils::snprintf(lwipPath,sizeof(lwipPath),"%s%sliblwip.so",homePath,ZT_PATH_SEPARATOR_S);
|
||||
@@ -1222,6 +1222,7 @@ void NetconEthernetTap::handleConnect(PhySocket *sock, PhySocket *rpcSock, Conne
|
||||
d[1] = (ip >> 8) & 0xFF;
|
||||
d[2] = (ip >> 16) & 0xFF;
|
||||
d[3] = (ip >> 24) & 0xFF;
|
||||
|
||||
dwr(MSG_DEBUG," handleConnect(): %d.%d.%d.%d: %d\n", d[0],d[1],d[2],d[3], port);
|
||||
dwr(MSG_DEBUG," handleConnect(): pcb->state = %x\n", conn->TCP_pcb->state);
|
||||
if(conn->TCP_pcb->state != CLOSED) {
|
||||
|
||||
@@ -461,7 +461,7 @@ namespace ZeroTier {
|
||||
int proxyListenSocket;
|
||||
PhySocket *proxyListenPhySocket;
|
||||
|
||||
void StartProxy(const char *nwid);
|
||||
void StartProxy(const char *sockpath, const char *homepath, uint64_t nwid);
|
||||
|
||||
void phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable);
|
||||
|
||||
|
||||
@@ -29,10 +29,13 @@
|
||||
#include "SDK_EthernetTap.hpp"
|
||||
#include "Phy.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "OSUtils.hpp"
|
||||
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#define SOCKS_OPEN 0
|
||||
#define SOCKS_CONNECT_INIT 1
|
||||
@@ -59,7 +62,7 @@
|
||||
|
||||
namespace ZeroTier
|
||||
{
|
||||
void NetconEthernetTap::StartProxy(const char *nwid)
|
||||
void NetconEthernetTap::StartProxy(const char *sockpath, const char *homepath, uint64_t nwid)
|
||||
{
|
||||
#if defined (__ANDROID__)
|
||||
LOGV("StartProxy()\n");
|
||||
@@ -67,9 +70,31 @@ namespace ZeroTier
|
||||
printf("StartProxy()\n");
|
||||
#endif
|
||||
|
||||
// Look for a port file for this network's proxy server instance
|
||||
char portFile[4096];
|
||||
Utils::snprintf(portFile,sizeof(portFile),"%s/networks.d/%.16llx.port",homepath,nwid);
|
||||
std::string portStr;
|
||||
printf("Proxy(): Reading port from: %s\n", portFile);
|
||||
if(ZeroTier::OSUtils::fileExists(portFile,true))
|
||||
{
|
||||
if(ZeroTier::OSUtils::readFile(portFile, portStr)) {
|
||||
proxyListenPort = atoi(portStr.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int randp = 0;
|
||||
Utils::getSecureRandom(&randp,sizeof(randp));
|
||||
proxyListenPort = 1000 + (randp % 1000);
|
||||
printf("Proxy(): No port specified in networks.d/%.16llx.port, randomly picking port\n", nwid);
|
||||
std::stringstream ss;
|
||||
ss << proxyListenPort;
|
||||
portStr = ss.str();
|
||||
if(!ZeroTier::OSUtils::writeFile(portFile, portStr)) {
|
||||
LOGV("unable to write proxy port file: %s\n", portFile);
|
||||
}
|
||||
}
|
||||
|
||||
struct sockaddr_in in4;
|
||||
memset(&in4,0,sizeof(in4));
|
||||
in4.sin_family = AF_INET;
|
||||
@@ -77,7 +102,7 @@ namespace ZeroTier
|
||||
in4.sin_port = Utils::hton((uint16_t)proxyListenPort);
|
||||
proxyListenPhySocket = _phy.tcpListen((const struct sockaddr*)&in4,(void *)this);
|
||||
sockstate = SOCKS_OPEN;
|
||||
printf("SOCKS5 proxy server address for <%s> is: <0.0.0.0:%d> (sock=%p)\n", nwid, proxyListenPort, (void*)&proxyListenPhySocket);
|
||||
printf("SOCKS5 proxy server address for <%.16llx> is: <0.0.0.0:%d> (sock=%p)\n", nwid, proxyListenPort, (void*)&proxyListenPhySocket);
|
||||
}
|
||||
|
||||
void ExtractAddress(int addr_type, unsigned char *buf, struct sockaddr_in * addr)
|
||||
@@ -384,28 +409,5 @@ namespace ZeroTier
|
||||
void NetconEthernetTap::phyOnFileDescriptorActivity(PhySocket *sock,void **uptr,bool readable,bool writable)
|
||||
{
|
||||
printf("phyOnFileDescriptorActivity(): sock=%p\n", (void*&)sock);
|
||||
/*
|
||||
if(readable)
|
||||
{
|
||||
//ProxyConn *conn = (ProxyConn*)*uptr;
|
||||
//if(!conn){
|
||||
// printf("\t!conn");
|
||||
// return;
|
||||
//}
|
||||
//char buf[50];
|
||||
//memset(buf, 0, sizeof(buf));
|
||||
//printf("Activity(R)->socket() = %d\n", _phy.getDescriptor(sock));
|
||||
//printf("Activity(W)->socket() = %d\n", conn->fd);
|
||||
//int n_read = read(_phy.getDescriptor(sock), buf, sizeof(buf));
|
||||
//printf(" read = %d\n", n_read);
|
||||
//int n_sent = write(conn->fd, buf, n_read);
|
||||
//printf("buf = %s\n", buf);
|
||||
//printf(" sent = %d\n", n_sent);
|
||||
}
|
||||
if(writable)
|
||||
{
|
||||
printf(" writable\n");
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,9 @@ std::string givenHomeDir; // What the user/application provides as a suggestion
|
||||
std::string homeDir; // The resultant platform-specific dir we *must* use internally
|
||||
std::string netDir;
|
||||
|
||||
bool rpcEnabled;
|
||||
std::string rpcNWID;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -92,10 +95,6 @@ void zt_init_rpc(const char * path, const char * nwid);
|
||||
if(!ZeroTier::OSUtils::writeFile(confFile.c_str(), "")) {
|
||||
LOGV("unable to write network conf file: %s\n", confFile.c_str());
|
||||
}
|
||||
LOGV("zt1Service = %x\n", (void*)zt1Service);
|
||||
|
||||
//zt1Service->join(nwid);
|
||||
LOGV("started up\n");
|
||||
// This provides the shim API with the RPC information
|
||||
zt_init_rpc(homeDir.c_str(), nwid);
|
||||
}
|
||||
@@ -155,10 +154,10 @@ void zt_init_rpc(const char * path, const char * nwid);
|
||||
pthread_create(&intercept_thread, NULL, startOneService, (void *)(intercept_thread_id));
|
||||
}
|
||||
|
||||
void init_service_and_rpc(int key, const char * path, const char * nwid)
|
||||
{
|
||||
void init_service_and_rpc(int key, const char * path, const char * nwid) {
|
||||
rpcEnabled = true;
|
||||
rpcNWID = nwid;
|
||||
init_service(key, path);
|
||||
zt_init_rpc(path, nwid);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -233,6 +232,7 @@ void zt_init_rpc(const char * path, const char * nwid);
|
||||
|
||||
#if defined(__APPLE__) && !defined(__IOS__)
|
||||
homeDir = givenHomeDir;
|
||||
localHomeDir = givenHomeDir; // Used for RPC and *can* differ from homeDir on some platforms
|
||||
#endif
|
||||
|
||||
LOGV("homeDir = %s", givenHomeDir.c_str());
|
||||
@@ -265,8 +265,6 @@ void zt_init_rpc(const char * path, const char * nwid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(__IOS__)
|
||||
// Go to the app's data directory so we can shorten the sun_path we bind to
|
||||
int MAX_DIR_SZ = 256;
|
||||
@@ -280,6 +278,11 @@ void zt_init_rpc(const char * path, const char * nwid);
|
||||
//chdir(current_dir); // Return to previous current working directory (at the request of Unity3D)
|
||||
//Debug(homeDir.c_str());
|
||||
|
||||
// Initialize RPC
|
||||
if(rpcEnabled) {
|
||||
zt_init_rpc(localHomeDir.c_str(), rpcNWID.c_str());
|
||||
}
|
||||
|
||||
// Generate random port for new service instance
|
||||
unsigned int randp = 0;
|
||||
ZeroTier::Utils::getSecureRandom(&randp,sizeof(randp));
|
||||
|
||||
@@ -109,7 +109,6 @@ int (*realclose)(CLOSE_SIG);
|
||||
strcat(fullpath, "/nc_");
|
||||
strcat(fullpath, nwid);
|
||||
api_netpath = fullpath;
|
||||
//api_netpath = "/data/data/com.example.joseph.example_app/files/zerotier/nc_565799d8f65063e5";
|
||||
}
|
||||
#else
|
||||
// Get path/nwid from environment variables
|
||||
@@ -371,8 +370,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
#endif
|
||||
#endif
|
||||
/* -1 is passed since we we're generating the new socket in this call */
|
||||
printf("path = %s\n", api_netpath);
|
||||
LOGV("path = %s\n", api_netpath);
|
||||
printf("api_netpath = %s\n", api_netpath);
|
||||
int err = rpc_send_command(api_netpath, RPC_SOCKET, -1, &rpc_st, sizeof(struct socket_st));
|
||||
//LOGV("socket() = %d\n", err);
|
||||
dwr(MSG_DEBUG," socket() = %d\n", err);
|
||||
@@ -388,7 +386,6 @@ int (*realclose)(CLOSE_SIG);
|
||||
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_ztjniConnect(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port) {
|
||||
struct sockaddr_in addr;
|
||||
char *str;
|
||||
// = env->GetStringUTFChars(addrstr, NULL);
|
||||
(*env)->ReleaseStringUTFChars(env, addrstr, str);
|
||||
addr.sin_addr.s_addr = inet_addr(str);
|
||||
addr.sin_family = AF_INET;
|
||||
|
||||
Reference in New Issue
Block a user