2016-06-14 15:48:48 -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/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _ZT_SDK_H
|
|
|
|
|
#define _ZT_SDK_H 1
|
|
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2016-06-27 10:54:13 -07:00
|
|
|
#include <stdbool.h>
|
2016-06-14 15:48:48 -07:00
|
|
|
#include "SDK_Signatures.h"
|
|
|
|
|
|
2016-07-15 14:52:02 -07:00
|
|
|
#if defined(__ANDROID__)
|
2016-07-20 14:20:45 -07:00
|
|
|
// For defining the Android direct-call API
|
2016-07-15 14:52:02 -07:00
|
|
|
#include <jni.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-06-14 15:48:48 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define INTERCEPT_ENABLED 111
|
|
|
|
|
#define INTERCEPT_DISABLED 222
|
|
|
|
|
|
2016-07-03 12:01:30 -05:00
|
|
|
extern void load_symbols();
|
2016-07-04 13:42:44 -05:00
|
|
|
extern void zt_init_rpc(const char *path, const char *nwid);
|
2016-06-29 01:35:58 -07:00
|
|
|
extern char *api_netpath;
|
2016-07-04 13:42:44 -05:00
|
|
|
extern char *debug_logfile;
|
2016-06-14 15:48:48 -07:00
|
|
|
|
2016-07-20 14:20:45 -07:00
|
|
|
// Function pointers to original system calls
|
|
|
|
|
// - These are used when we detect that either the intercept is not
|
|
|
|
|
// available or that ZeroTier hasn't administered the given socket
|
2016-06-14 15:48:48 -07:00
|
|
|
#if defined(__linux__)
|
2016-06-29 11:57:05 -07:00
|
|
|
extern int (*realaccept4)(ACCEPT4_SIG);
|
2016-06-14 15:48:48 -07:00
|
|
|
#if !defined(__ANDROID__)
|
2016-06-29 11:57:05 -07:00
|
|
|
extern int (*realsyscall)(SYSCALL_SIG);
|
2016-06-14 15:48:48 -07:00
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if !defined(__ANDROID__)
|
2016-07-03 12:01:30 -05:00
|
|
|
bool check_intercept_enabled();
|
2016-06-29 11:57:05 -07:00
|
|
|
extern int (*realbind)(BIND_SIG);
|
|
|
|
|
extern int (*realsendmsg)(SENDMSG_SIG);
|
|
|
|
|
extern ssize_t (*realsendto)(SENDTO_SIG);
|
|
|
|
|
extern int (*realrecvmsg)(RECVMSG_SIG);
|
|
|
|
|
extern int (*realrecvfrom)(RECVFROM_SIG);
|
2016-06-14 15:48:48 -07:00
|
|
|
#endif
|
2016-06-29 11:57:05 -07:00
|
|
|
extern int (*realconnect)(CONNECT_SIG);
|
|
|
|
|
extern int (*realaccept)(ACCEPT_SIG);
|
|
|
|
|
extern int (*reallisten)(LISTEN_SIG);
|
|
|
|
|
extern int (*realsocket)(SOCKET_SIG);
|
|
|
|
|
extern int (*realsetsockopt)(SETSOCKOPT_SIG);
|
|
|
|
|
extern int (*realgetsockopt)(GETSOCKOPT_SIG);
|
|
|
|
|
extern int (*realclose)(CLOSE_SIG);
|
2016-07-20 14:20:45 -07:00
|
|
|
extern int (*realgetsockname)(GETSOCKNAME_SIG);
|
|
|
|
|
|
|
|
|
|
// Direct call
|
|
|
|
|
// - Skips intercept
|
|
|
|
|
// - Uses RPC
|
|
|
|
|
// - Depending on the target, the API will be exposed as zt_* in
|
|
|
|
|
// the specific way needed for that platform, but will be implemented
|
|
|
|
|
// in terms of zts_*
|
|
|
|
|
int zts_socket(SOCKET_SIG);
|
|
|
|
|
int zts_connect(CONNECT_SIG);
|
|
|
|
|
int zts_bind(BIND_SIG);
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
int zts_accept4(ACCEPT4_SIG);
|
|
|
|
|
#endif
|
|
|
|
|
int zts_accept(ACCEPT_SIG);
|
|
|
|
|
int zts_listen(LISTEN_SIG);
|
|
|
|
|
int zts_setsockopt(SETSOCKOPT_SIG);
|
|
|
|
|
int zts_getsockopt(GETSOCKOPT_SIG);
|
|
|
|
|
int zts_getsockname(GETSOCKNAME_SIG);
|
2016-08-14 22:20:55 -07:00
|
|
|
int zts_getpeername(GETPEERNAME_SIG);
|
2016-07-20 14:20:45 -07:00
|
|
|
int zts_close(CLOSE_SIG);
|
2016-06-14 15:48:48 -07:00
|
|
|
|
2016-07-20 14:20:45 -07:00
|
|
|
ssize_t zts_sendto(SENDTO_SIG);
|
|
|
|
|
ssize_t zts_sendmsg(SENDMSG_SIG);
|
|
|
|
|
ssize_t zts_recvfrom(RECVFROM_SIG);
|
|
|
|
|
ssize_t zts_recvmsg(RECVMSG_SIG);
|
2016-06-14 15:48:48 -07:00
|
|
|
|
|
|
|
|
#if defined(__UNITY_3D__)
|
2016-07-20 14:20:45 -07:00
|
|
|
ssize_t zts_recv(int fd, void *buf, int len);
|
|
|
|
|
ssize_t zts_send(int fd, void *buf, int len);
|
|
|
|
|
int zts_set_nonblock(int fd);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2016-07-15 14:52:02 -07:00
|
|
|
// Android JNI Direct-call API
|
2016-07-20 14:20:45 -07:00
|
|
|
// - Implemented in terms of zt_* direct calls
|
2016-07-15 14:52:02 -07:00
|
|
|
#if defined(__ANDROID__)
|
2016-07-20 14:20:45 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1socket(JNIEnv *env, jobject thisObj, jint family, jint type, jint protocol);
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1connect(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port);
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1bind(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port);
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1accept4(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port, jint flags);
|
2016-08-01 12:33:19 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1accept(JNIEnv *env, jobject thisObj, jint fd, jstring addrstr, jint port);
|
2016-07-20 14:20:45 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1listen(JNIEnv *env, jobject thisObj, jint fd, int backlog);
|
|
|
|
|
//JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1setsockopt(JNIEnv *env, jobject thisObj);
|
|
|
|
|
//JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1getsockopt(JNIEnv *env, jobject thisObj);
|
|
|
|
|
//JNIEXPORT void JNICALL Java_ZeroTier_SDK_zt_1getsockname(JNIEnv *env, jobject thisObj);
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1close(JNIEnv *env, jobject thisObj, jint fd);
|
2016-08-11 23:34:40 -07:00
|
|
|
// TCP
|
2016-08-03 11:11:12 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1write(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len);
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1read(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len);
|
2016-08-14 22:20:55 -07:00
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1send(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, int flags);
|
|
|
|
|
|
2016-08-11 23:34:40 -07:00
|
|
|
// UDP
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1sendto(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr);
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1recvfrom(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr);
|
2016-08-14 22:20:55 -07:00
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_ZeroTier_SDK_zt_1fcntl(JNIEnv *env, jobject thisObj, jint socket, jint cmd, jint flags);
|
|
|
|
|
|
2016-07-29 09:41:09 -07:00
|
|
|
// Takes a given numerical file descriptor and manufactures a java FileDescriptor object for use in javaland
|
|
|
|
|
JNIEXPORT jobject JNICALL Java_ZeroTier_SDK_zt_1getFileDescriptor(JNIEnv *env, jobject thisObj, jint fd);
|
2016-06-14 15:48:48 -07:00
|
|
|
#endif
|
|
|
|
|
|
2016-06-27 15:14:00 -07:00
|
|
|
|
2016-07-20 14:20:45 -07:00
|
|
|
// Prototypes for redefinition of syscalls
|
|
|
|
|
// - Implemented in SDK_Intercept.c
|
2016-06-27 15:14:00 -07:00
|
|
|
#if defined(SDK_INTERCEPT)
|
|
|
|
|
int socket(SOCKET_SIG);
|
|
|
|
|
int connect(CONNECT_SIG);
|
|
|
|
|
int bind(BIND_SIG);
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
int accept4(ACCEPT4_SIG);
|
|
|
|
|
#endif
|
|
|
|
|
int accept(ACCEPT_SIG);
|
|
|
|
|
int listen(LISTEN_SIG);
|
|
|
|
|
int setsockopt(SETSOCKOPT_SIG);
|
|
|
|
|
int getsockopt(GETSOCKOPT_SIG);
|
|
|
|
|
int getsockname(GETSOCKNAME_SIG);
|
|
|
|
|
int close(CLOSE_SIG);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-06-14 15:48:48 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif // _ZT_SDK_H
|