Implemented SOCKS proxy port file: networks.d/nwid.port
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user