osx demo app tweaks
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Example_OSX_App/ViewController.swift"
|
||||
timestampString = "489521728.968073"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "74"
|
||||
endingLineNumber = "74"
|
||||
landmarkName = "UI_Connect(_:)"
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
@@ -767,6 +767,9 @@
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<action selector="txtAddrChanged:" target="XfG-lQ-9wD" id="vpp-Wo-rj8"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="imQ-Xu-9iD">
|
||||
<rect key="frame" x="175" y="44" width="50" height="22"/>
|
||||
@@ -775,6 +778,9 @@
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<action selector="txtPortChanged:" target="XfG-lQ-9wD" id="3zi-Z0-7cx"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ORq-6n-fZV">
|
||||
<rect key="frame" x="9" y="24" width="104" height="17"/>
|
||||
@@ -950,6 +956,7 @@
|
||||
<outlet property="txtAddr" destination="imQ-Xu-9iD" id="FQu-fG-Pg2"/>
|
||||
<outlet property="txtNWID" destination="7LM-Q0-D7l" id="3QF-tw-Hws"/>
|
||||
<outlet property="txtPort" destination="imQ-Xu-9iD" id="UrQ-84-slh"/>
|
||||
<outlet property="txtPortChanged" destination="imQ-Xu-9iD" id="NqB-2s-Og3"/>
|
||||
<outlet property="txtR" destination="f93-eE-nJ9" id="Sbh-vb-Ycb"/>
|
||||
<outlet property="txtRX" destination="f93-eE-nJ9" id="aTL-JM-evI"/>
|
||||
<outlet property="txtRx" destination="f93-eE-nJ9" id="yPZ-sv-Ctq"/>
|
||||
|
||||
@@ -19,15 +19,16 @@ 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_init_rpc(const char *path, const char *nwid);
|
||||
int zts_connect(CONNECT_SIG);
|
||||
int zt_bind(BIND_SIG);
|
||||
int zt_accept(ACCEPT_SIG);
|
||||
int zt_listen(LISTEN_SIG);
|
||||
int zts_bind(BIND_SIG);
|
||||
int zts_accept(ACCEPT_SIG);
|
||||
int zts_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);
|
||||
int zts_setsockopt(SETSOCKOPT_SIG);
|
||||
int zts_getsockopt(GETSOCKOPT_SIG);
|
||||
int zts_close(CLOSE_SIG);
|
||||
int zts_getsockname(GETSOCKNAME_SIG);
|
||||
|
||||
|
||||
#endif /* Example_OSX_Bridging_Header_h */
|
||||
|
||||
@@ -23,30 +23,108 @@ class ViewController: NSViewController {
|
||||
@IBOutlet weak var txtRX: NSScrollView!
|
||||
@IBOutlet weak var btnSend: NSButton!
|
||||
|
||||
var serverPort:Int32 = 4545
|
||||
var serverAddr:String = "10.147.18.5"
|
||||
|
||||
@IBAction func txtAddrChanged(sender: AnyObject) {
|
||||
if(sender.value != nil) {
|
||||
serverAddr = sender.value
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func txtPortChanged(sender: AnyObject) {
|
||||
serverPort = sender.intValue!
|
||||
}
|
||||
|
||||
// Join a ZeroTier network
|
||||
@IBAction func UI_JoinNetwork(sender: AnyObject) {
|
||||
zt_join_network(txtNWID.stringValue);
|
||||
}
|
||||
|
||||
// Leave a ZeroTier network
|
||||
@IBAction func UI_LeaveNetwork(sender: AnyObject) {
|
||||
zt_leave_network(txtNWID.stringValue);
|
||||
}
|
||||
|
||||
// Select an API
|
||||
var selectedShim:Int32 = 0
|
||||
@IBAction func UI_SelectAPI(sender: AnyObject) {
|
||||
selectedShim = sender.intValue // 0 = BSD-style, 1 = SOCKS5 Proxy, etc
|
||||
}
|
||||
|
||||
// Select a protocol
|
||||
// Protocol { TCP / UDP }
|
||||
var selectedProtocol:Int32 = 0
|
||||
@IBAction func UI_SelectProtocol(sender: AnyObject) {
|
||||
switch sender.intValue
|
||||
{
|
||||
case 0:
|
||||
print("Selected TCP (SOCK_STREAM)\n");
|
||||
selectedProtocol = SOCK_STREAM
|
||||
case 1:
|
||||
print("Selected UDP (SOCK_DGRAM)\n");
|
||||
selectedProtocol = SOCK_DGRAM
|
||||
default:
|
||||
break;
|
||||
} }
|
||||
|
||||
// Connect to remote host on ZeroTier virtual network
|
||||
@IBAction func UI_Connect(sender: AnyObject) {
|
||||
// TCP
|
||||
if(selectedProtocol == SOCK_STREAM)
|
||||
{
|
||||
let sd = 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_fd = zts_connect(sd, UnsafePointer<sockaddr>([addr]), UInt32(addr.sin_len))
|
||||
print("connect_fd = \(connect_fd),\(errno)")
|
||||
|
||||
if connect_fd < 0 {
|
||||
let err = errno
|
||||
print("Error connecting IPv4 socket \(err)")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func UI_Connect(sender: AnyObject) {
|
||||
// UDP
|
||||
if(selectedProtocol == SOCK_DGRAM)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func UI_Bind(sender: AnyObject) {
|
||||
}
|
||||
|
||||
@IBAction func UI_SendData(sender: AnyObject) {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
// Mode { Client / Server }
|
||||
@IBOutlet weak var ModeControl: UISegmentedControl!
|
||||
var selectedMode:UInt16 = 0
|
||||
@IBAction func ModeControlSelected(sender: AnyObject) {
|
||||
switch sender.selectedSegmentIndex
|
||||
{
|
||||
case 0:
|
||||
print("Selected client\n");
|
||||
selectedMode = 0
|
||||
case 1:
|
||||
print("Selected server\n");
|
||||
selectedMode = 1
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
var service_thread : NSThread!
|
||||
@@ -67,7 +145,9 @@ class ViewController: NSViewController {
|
||||
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
|
||||
self.service_thread.start()
|
||||
});
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
// Set RPC path for this thread
|
||||
zts_init_rpc("/Users/Joseph/utest3/nc_","e5cd7a9e1c2e194f");
|
||||
}
|
||||
|
||||
override var representedObject: AnyObject? {
|
||||
|
||||
@@ -107,7 +107,7 @@ int get_retval(int rpc_sock)
|
||||
|
||||
int load_symbols_rpc()
|
||||
{
|
||||
#if defined(SDK_INTERCEPT) || defined(__IOS__) || defined(__UNITY_3D__)
|
||||
#if defined(SDK_BUNDLED) || defined(__IOS__) || defined(__UNITY_3D__)
|
||||
realsocket = dlsym(RTLD_NEXT, "socket");
|
||||
realconnect = dlsym(RTLD_NEXT, "connect");
|
||||
if(!realconnect || !realsocket)
|
||||
@@ -157,7 +157,9 @@ int rpc_send_command(char *path, int cmd, int forfd, void *data, int len)
|
||||
memcpy(CANARY+CANARY_SZ, padding, sizeof(padding));
|
||||
uint64_t canary_num;
|
||||
// ephemeral RPC socket used only for this command
|
||||
printf("calling rpc_join");
|
||||
int rpc_sock = rpc_join(path);
|
||||
printf("fin\n");
|
||||
// Generate token
|
||||
int fdrand = open("/dev/urandom", O_RDONLY);
|
||||
if(read(fdrand, &CANARY, CANARY_SZ) < 0) {
|
||||
|
||||
@@ -88,7 +88,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
dwr(MSG_DEBUG, "zt_init_rpc\n");
|
||||
// Just double check we have
|
||||
if(!realconnect) {
|
||||
//load_symbols();
|
||||
load_symbols_rpc();
|
||||
}
|
||||
|
||||
if(!api_netpath) {
|
||||
@@ -353,6 +353,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);
|
||||
int err = rpc_send_command(api_netpath, RPC_SOCKET, -1, &rpc_st, sizeof(struct socket_st));
|
||||
dwr(MSG_DEBUG," socket() = %d\n", err);
|
||||
return err;
|
||||
|
||||
@@ -32,30 +32,33 @@ extern "C" void zt_leave_network(const char * nwid){
|
||||
}
|
||||
|
||||
// Explicit ZT API wrappers
|
||||
extern "C" int zt_socket(SOCKET_SIG) {
|
||||
extern "C" void zts_init_rpc(const char *path, const char *nwid) {
|
||||
zt_init_rpc(path, nwid);
|
||||
}
|
||||
extern "C" int zts_socket(SOCKET_SIG) {
|
||||
return zt_socket(socket_family, socket_type, protocol);
|
||||
}
|
||||
extern "C" int zts_connect(CONNECT_SIG) {
|
||||
return zt_connect(__fd, __addr, __len);
|
||||
}
|
||||
extern "C" int zt_bind(BIND_SIG){
|
||||
extern "C" int zts_bind(BIND_SIG){
|
||||
return zt_bind(sockfd, addr, addrlen);
|
||||
}
|
||||
extern "C" int zt_accept(ACCEPT_SIG) {
|
||||
extern "C" int zts_accept(ACCEPT_SIG) {
|
||||
return zt_accept(sockfd, addr, addrlen);
|
||||
}
|
||||
extern "C" int zt_listen(LISTEN_SIG) {
|
||||
extern "C" int zts_listen(LISTEN_SIG) {
|
||||
return zt_listen(sockfd, backlog);
|
||||
}
|
||||
extern "C" int zt_setsockopt(SETSOCKOPT_SIG) {
|
||||
extern "C" int zts_setsockopt(SETSOCKOPT_SIG) {
|
||||
return zt_setsockopt(socket, level, option_name, option_value, option_len);
|
||||
}
|
||||
extern "C" int zt_getsockopt(GETSOCKOPT_SIG) {
|
||||
extern "C" int zts_getsockopt(GETSOCKOPT_SIG) {
|
||||
return zt_getsockopt(sockfd, level, optname, optval, optlen);
|
||||
}
|
||||
extern "C" int zt_close(CLOSE_SIG) {
|
||||
extern "C" int zts_close(CLOSE_SIG) {
|
||||
return zt_close(fd);
|
||||
}
|
||||
extern "C" int zt_getsockname(GETSOCKNAME_SIG) {
|
||||
extern "C" int zts_getsockname(GETSOCKNAME_SIG) {
|
||||
return zt_getsockname(sockfd, addr, addrlen);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user