2016-07-18 13:36:01 -07:00
|
|
|
/*
|
|
|
|
|
* ZeroTier One - Network Virtualization Everywhere
|
|
|
|
|
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* --
|
|
|
|
|
*
|
|
|
|
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
|
|
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
|
*
|
|
|
|
|
* If you would like to embed ZeroTier into a commercial application or
|
|
|
|
|
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
|
|
|
* LLC. Start here: http://www.zerotier.com/
|
|
|
|
|
*/
|
2016-07-05 14:47:14 -05:00
|
|
|
|
|
|
|
|
#include "SDK.h"
|
|
|
|
|
#include "SDK_XcodeWrapper.hpp"
|
|
|
|
|
#include "SDK_Signatures.h"
|
|
|
|
|
|
|
|
|
|
#define INTERCEPT_ENABLED 111
|
|
|
|
|
#define INTERCEPT_DISABLED 222
|
|
|
|
|
|
|
|
|
|
#include "SDK_ServiceSetup.hpp"
|
|
|
|
|
|
2016-07-05 15:52:23 -05:00
|
|
|
// Starts a ZeroTier service at the specified path
|
2016-07-17 20:56:42 -07:00
|
|
|
// This will only support SOCKS5 Proxy
|
2016-07-05 15:52:23 -05:00
|
|
|
extern "C" void start_service(const char * path) {
|
2016-07-05 14:47:14 -05:00
|
|
|
init_service(INTERCEPT_DISABLED, path);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 20:56:42 -07:00
|
|
|
// Starts a ZeroTier service at the specified path and initializes the RPC mechanism
|
|
|
|
|
// This will allow direct API calls
|
|
|
|
|
extern "C" void start_service_and_rpc(const char * path, const char * nwid) {
|
|
|
|
|
init_service_and_rpc(INTERCEPT_DISABLED, path, nwid);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 15:52:23 -05:00
|
|
|
// Joins a ZeroTier virtual network
|
2016-08-11 23:27:05 -07:00
|
|
|
extern "C" void zt_join_network(const char * nwid) {
|
2016-07-20 14:20:45 -07:00
|
|
|
zts_join_network(nwid);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
|
|
|
|
|
2016-07-05 15:52:23 -05:00
|
|
|
// Leaves a ZeroTier virtual network
|
2016-08-11 23:27:05 -07:00
|
|
|
extern "C" void zt_leave_network(const char * nwid) {
|
2016-07-20 14:20:45 -07:00
|
|
|
zts_leave_network(nwid);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
|
|
|
|
|
2016-08-11 23:27:05 -07:00
|
|
|
// Returns a list of addresses associated with this device on the given network
|
|
|
|
|
extern "C" void zt_get_addresses(const char * nwid, char * addrstr) {
|
|
|
|
|
zts_get_addresses(nwid, addrstr);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 14:47:14 -05:00
|
|
|
// Explicit ZT API wrappers
|
2016-07-17 20:56:42 -07:00
|
|
|
#if !defined(__IOS__)
|
|
|
|
|
// This isn't available for iOS since function interposition isn't as reliable
|
|
|
|
|
extern "C" void zts_init_rpc(const char *path, const char *nwid) {
|
|
|
|
|
zt_init_rpc(path, nwid);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_socket(SOCKET_SIG) {
|
|
|
|
|
return zts_socket(socket_family, socket_type, protocol);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_connect(CONNECT_SIG) {
|
|
|
|
|
return zts_connect(__fd, __addr, __len);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_bind(BIND_SIG){
|
|
|
|
|
return zts_bind(sockfd, addr, addrlen);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_accept(ACCEPT_SIG) {
|
|
|
|
|
return zts_accept(sockfd, addr, addrlen);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_listen(LISTEN_SIG) {
|
|
|
|
|
return zts_listen(sockfd, backlog);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_setsockopt(SETSOCKOPT_SIG) {
|
|
|
|
|
return zts_setsockopt(socket, level, option_name, option_value, option_len);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_getsockopt(GETSOCKOPT_SIG) {
|
|
|
|
|
return zts_getsockopt(sockfd, level, optname, optval, optlen);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_close(CLOSE_SIG) {
|
|
|
|
|
return zts_close(fd);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|
2016-07-20 14:20:45 -07:00
|
|
|
extern "C" int zt_getsockname(GETSOCKNAME_SIG) {
|
|
|
|
|
return zts_getsockname(sockfd, addr, addrlen);
|
2016-07-05 14:47:14 -05:00
|
|
|
}
|