Update to JNI for both Java and Scala (removed ztjni from method prefixes)
This commit is contained in:
@@ -39,12 +39,12 @@ public class ExampleApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
final ZeroTier z = new ZeroTier();
|
||||
final ZeroTier libzt = new ZeroTier();
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
System.out.println("starting libzt");
|
||||
z.startjoin("/Users/joseph/op/zt/libzt/ztjni", "1212121212121212");
|
||||
libzt.startjoin("/Users/joseph/op/zt/libzt/ztjni", "1212121212121212");
|
||||
// start(path) will not block
|
||||
// startjoin(path, nwid) will block
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
|
||||
package zerotier;
|
||||
|
||||
//import zerotier.*;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -43,155 +41,35 @@ public class ZeroTier {
|
||||
// Socket families
|
||||
public static int AF_UNIX = 1;
|
||||
public static int AF_INET = 2;
|
||||
|
||||
// Socket types
|
||||
public static int SOCK_STREAM = 1;
|
||||
public static int SOCK_DGRAM = 2;
|
||||
|
||||
// fcntl flags
|
||||
public static int O_APPEND = 1024;
|
||||
public static int O_NONBLOCK = 2048;
|
||||
public static int O_ASYNC = 8192;
|
||||
public static int O_DIRECT = 65536;
|
||||
public static int O_NOATIME = 262144;
|
||||
|
||||
// fcntl cmds
|
||||
public static int F_GETFL = 3;
|
||||
public static int F_SETFL = 4;
|
||||
|
||||
// Loads JNI code
|
||||
//static { System.loadLibrary("zt"); }
|
||||
|
||||
// ZeroTier service controls
|
||||
public native void ztjni_start(String homeDir);
|
||||
public void start(String homeDir) { ztjni_start(homeDir); }
|
||||
|
||||
public native void ztjni_startjoin(String homeDir, String nwid);
|
||||
public void startjoin(String homeDir, String nwid) { ztjni_startjoin(homeDir, nwid); }
|
||||
|
||||
public native void ztjni_join(String nwid);
|
||||
public void join(String nwid) {
|
||||
ztjni_join(nwid);
|
||||
}
|
||||
|
||||
public native void ztjni_leave(String nwid);
|
||||
public void leave(String nwid) {
|
||||
ztjni_leave(nwid);
|
||||
}
|
||||
|
||||
public native ArrayList<String> ztjni_get_addresses(String nwid);
|
||||
public ArrayList<String> get_addresses(String nwid) {
|
||||
int err = -1;
|
||||
ArrayList<String> addresses;
|
||||
while (err < 0) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
addresses = ztjni_get_addresses(nwid);
|
||||
if (addresses.size() > 0) {
|
||||
return addresses;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public native boolean ztjni_running();
|
||||
public boolean running() { return ztjni_running(); }
|
||||
|
||||
public native int ztjni_socket(int family, int type, int protocol);
|
||||
public int socket(int family, int type, int protocol) { return ztjni_socket(family, type, protocol); }
|
||||
|
||||
public native int ztjni_connect(int fd, String addr, int port);
|
||||
public int connect(int sock, Address zaddr, String nwid) { return connect(sock, zaddr.Address(), zaddr.Port(), nwid); }
|
||||
|
||||
public int connect(int sock, String addr, int port, String nwid)
|
||||
{
|
||||
int err = -1;
|
||||
ArrayList<String> addresses;
|
||||
while (err < 0) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
addresses = ztjni_get_addresses(nwid);
|
||||
if (addresses.size() > 0) {
|
||||
if(!addresses.get(0).startsWith("-1.-1.-1.-1/-1")) {
|
||||
err = ztjni_connect(sock, addr, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
public native int ztjni_bind(int fd, String addr, int port);
|
||||
public int bind(int sock, Address zaddr, String nwid) { return bind(sock, zaddr.Address(), zaddr.Port(), nwid); }
|
||||
|
||||
public int bind(int sock, String addr, int port, String nwid) {
|
||||
int err = -1;
|
||||
ArrayList<String> addresses;
|
||||
while (err < 0) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
addresses = ztjni_get_addresses(nwid);
|
||||
if (addresses.size() > 0) {
|
||||
if(!addresses.get(0).startsWith("-1.-1.-1.-1/-1")) {
|
||||
err = ztjni_bind(sock, addr, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
public native int ztjni_accept4(int fd, String addr, int port);
|
||||
public int accept4(int fd, String addr, int port) {
|
||||
return ztjni_accept4(fd,addr,port);
|
||||
}
|
||||
|
||||
public native int ztjni_accept(int fd, Address addr);
|
||||
public int accept(int fd, Address addr) {
|
||||
return ztjni_accept(fd, addr);
|
||||
}
|
||||
|
||||
public native int ztjni_listen(int fd, int backlog);
|
||||
public int listen(int fd, int backlog) {
|
||||
return ztjni_listen(fd,backlog);
|
||||
}
|
||||
|
||||
public native int ztjni_close(int fd);
|
||||
public int close(int fd) {
|
||||
return ztjni_close(fd);
|
||||
}
|
||||
|
||||
public native int ztjni_read(int fd, byte[] buf, int len);
|
||||
public int read(int fd, byte[] buf, int len) {
|
||||
return ztjni_read(fd, buf, len);
|
||||
}
|
||||
|
||||
public native int ztjni_write(int fd, byte[] buf, int len);
|
||||
public int write(int fd, byte[] buf, int len) {
|
||||
return ztjni_write(fd, buf, len);
|
||||
}
|
||||
|
||||
public native int ztjni_sendto(int fd, byte[] buf, int len, int flags, Address addr);
|
||||
public int sendto(int fd, byte[] buf, int len, int flags, Address addr){
|
||||
return ztjni_sendto(fd,buf,len,flags,addr);
|
||||
}
|
||||
|
||||
public native int ztjni_send(int fd, byte[] buf, int len, int flags);
|
||||
public int send(int fd, byte[] buf, int len, int flags) {
|
||||
return ztjni_send(fd, buf, len, flags);
|
||||
}
|
||||
|
||||
public native int ztjni_recvfrom(int fd, byte[] buf, int len, int flags, Address addr);
|
||||
public int recvfrom(int fd, byte[] buf, int len, int flags, Address addr){
|
||||
return ztjni_recvfrom(fd,buf,len,flags,addr);
|
||||
}
|
||||
|
||||
public native int ztjni_fcntl(int sock, int cmd, int flag);
|
||||
public int fcntl(int sock, int cmd, int flag) {
|
||||
return ztjni_fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
}
|
||||
public native void start(String homeDir);
|
||||
public native void startjoin(String homeDir, String nwid);
|
||||
public native boolean running();
|
||||
public native void join(String nwid);
|
||||
public native void leave(String nwid);
|
||||
public native int socket(int family, int type, int protocol);
|
||||
public native int connect(int fd, String addr, int port);
|
||||
public native int bind(int fd, String addr, int port);
|
||||
public native int accept4(int fd, String addr, int port);
|
||||
public native int accept(int fd, Address addr);
|
||||
public native int listen(int fd, int backlog);
|
||||
public native int close(int fd);
|
||||
public native int read(int fd, byte[] buf, int len);
|
||||
public native int write(int fd, byte[] buf, int len);
|
||||
public native int sendto(int fd, byte[] buf, int len, int flags, Address addr);
|
||||
public native int send(int fd, byte[] buf, int len, int flags);
|
||||
public native int recvfrom(int fd, byte[] buf, int len, int flags, Address addr);
|
||||
public native int fcntl(int sock, int cmd, int flag);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ object ExampleApp extends App {
|
||||
System.loadLibrary("zt")
|
||||
|
||||
val libzt = new ZeroTier
|
||||
libzt.ztjni_startjoin("/Users/joseph/op/zt/libzt/ztjni", "1212121212121212")
|
||||
val fd = libzt.ztjni_socket(2, 1, 0)
|
||||
println(s"zts_socket(): $fd")
|
||||
libzt.startjoin("/Users/joseph/op/zt/libzt/ztjni", "1212121212121212")
|
||||
val fd = libzt.socket(2, 1, 0)
|
||||
println(s"libzt.socket(): $fd")
|
||||
}
|
||||
@@ -2,43 +2,43 @@ package zerotier;
|
||||
|
||||
class ZeroTier {
|
||||
|
||||
@native def ztjni_start(path: String): Int
|
||||
@native def ztjni_startjoin(path: String, nwid: String): Int
|
||||
@native def ztjni_stop(): Unit
|
||||
@native def ztjni_running(): Int
|
||||
@native def ztjni_join(nwid: String): Unit
|
||||
@native def ztjni_leave(nwid: String): Unit
|
||||
//@native def ztjni_path():
|
||||
//@native def ztjni_id(): Int
|
||||
//@native def ztjni_get_6plane_addr(): Unit
|
||||
//@native def ztjni_get_rfc4193_addr(): Unit
|
||||
@native def ztjni_socket(socket_family: Int, socket_type: Int, protocol: Int): Int
|
||||
@native def ztjni_connect(fd: Int, addr: Object, addrlen: Int): Int
|
||||
@native def ztjni_bind(fd: Int, addr: Object, addrlen: Int): Int
|
||||
@native def ztjni_listen(fd: Int, backlog: Int): Int
|
||||
@native def ztjni_accept(fd: Int, addr: Object, addrlen: Int): Int
|
||||
@native def ztjni_accept4(fd: Int, addr: Object, addrlen: Int, flags: Int): Int
|
||||
@native def ztjni_setsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int
|
||||
@native def ztjni_getsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int
|
||||
//@native def ztjni_getsockname(): Int
|
||||
//@native def ztjni_getpeername(): Int
|
||||
//@native def ztjni_gethostname(): Int
|
||||
//@native def ztjni_sethostname(): Int
|
||||
//@native def ztjni_gethostbyname(): Object
|
||||
@native def ztjni_close(fd: Int): Int
|
||||
//@native def ztjni_poll(): Int
|
||||
//@native def ztjni_select(): Int
|
||||
@native def ztjni_fcntl(fd: Int, cmd: Int, flags: Int): Int
|
||||
@native def ztjni_ioctl(fd: Int, request: Long, argp: Object): Int
|
||||
@native def ztjni_send(fd: Int, buf: Object, len: Int, flags: Int): Int
|
||||
@native def ztjni_sendto(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int
|
||||
@native def ztjni_sendmsg(fd: Int, msg: Object, flags: Int): Int
|
||||
@native def ztjni_recv(fd: Int, buf: Object, len: Int, flags: Int): Int
|
||||
@native def ztjni_recvfrom(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int
|
||||
@native def ztjni_recvmsg(fd: Int, msg: Object, flags: Int): Int
|
||||
@native def ztjni_read(fd: Int, buf: Object, len: Int): Int
|
||||
@native def ztjni_write(fd: Int, buf: Object, len: Int): Int
|
||||
@native def ztjni_shutdown(fd: Int, how: Int): Int
|
||||
//@native def ztjni_add_dns(): Int
|
||||
//@native def ztjni_del_dns(): Int
|
||||
@native def start(path: String): Int
|
||||
@native def startjoin(path: String, nwid: String): Int
|
||||
@native def stop(): Unit
|
||||
@native def running(): Int
|
||||
@native def join(nwid: String): Unit
|
||||
@native def leave(nwid: String): Unit
|
||||
//@native def path():
|
||||
//@native def id(): Int
|
||||
//@native def get_6plane_addr(): Unit
|
||||
//@native def get_rfc4193_addr(): Unit
|
||||
@native def socket(socket_family: Int, socket_type: Int, protocol: Int): Int
|
||||
@native def connect(fd: Int, addr: Object, addrlen: Int): Int
|
||||
@native def bind(fd: Int, addr: Object, addrlen: Int): Int
|
||||
@native def listen(fd: Int, backlog: Int): Int
|
||||
@native def accept(fd: Int, addr: Object, addrlen: Int): Int
|
||||
@native def accept4(fd: Int, addr: Object, addrlen: Int, flags: Int): Int
|
||||
@native def setsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int
|
||||
@native def getsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int
|
||||
//@native def getsockname(): Int
|
||||
//@native def getpeername(): Int
|
||||
//@native def gethostname(): Int
|
||||
//@native def sethostname(): Int
|
||||
//@native def gethostbyname(): Object
|
||||
@native def close(fd: Int): Int
|
||||
//@native def poll(): Int
|
||||
//@native def select(): Int
|
||||
@native def fcntl(fd: Int, cmd: Int, flags: Int): Int
|
||||
@native def ioctl(fd: Int, request: Long, argp: Object): Int
|
||||
@native def send(fd: Int, buf: Object, len: Int, flags: Int): Int
|
||||
@native def sendto(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int
|
||||
@native def sendmsg(fd: Int, msg: Object, flags: Int): Int
|
||||
@native def recv(fd: Int, buf: Object, len: Int, flags: Int): Int
|
||||
@native def recvfrom(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int
|
||||
@native def recvmsg(fd: Int, msg: Object, flags: Int): Int
|
||||
@native def read(fd: Int, buf: Object, len: Int): Int
|
||||
@native def write(fd: Int, buf: Object, len: Int): Int
|
||||
@native def shutdown(fd: Int, how: Int): Int
|
||||
//@native def add_dns(): Int
|
||||
//@native def del_dns(): Int
|
||||
}
|
||||
|
||||
178
src/libztJNI.cpp
178
src/libztJNI.cpp
@@ -50,7 +50,76 @@ namespace ZeroTier {
|
||||
/* ZeroTier Socket API (for JNI wrapper) */
|
||||
/****************************************************************************/
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1sendto(
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_socket(JNIEnv *env, jobject thisObj,
|
||||
jint family, jint type, jint protocol)
|
||||
{
|
||||
return zts_socket(family, type, protocol);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_connect(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
const char *str = (*env).GetStringUTFChars( addrstr, 0);
|
||||
addr.sin_addr.s_addr = inet_addr(str);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
(*env).ReleaseStringUTFChars( addrstr, str);
|
||||
return zts_connect(fd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_bind(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
const char *str = (*env).GetStringUTFChars( addrstr, 0);
|
||||
DEBUG_INFO("fd=%d, addr=%s, port=%d", fd, str, port);
|
||||
addr.sin_addr.s_addr = inet_addr(str);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
(*env).ReleaseStringUTFChars( addrstr, str);
|
||||
return zts_bind(fd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_accept4(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port, jint flags)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
char *str;
|
||||
// = env->GetStringUTFChars(addrstr, NULL);
|
||||
(*env).ReleaseStringUTFChars( addrstr, str);
|
||||
addr.sin_addr.s_addr = inet_addr(str);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
return zts_accept4(fd, (struct sockaddr *)&addr, sizeof(addr), flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_accept(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
// TODO: Send addr info back to Javaland
|
||||
addr.sin_addr.s_addr = inet_addr("");
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
return zts_accept(fd, (struct sockaddr *)&addr, (socklen_t *)sizeof(addr));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_listen(JNIEnv *env, jobject thisObj,
|
||||
jint fd, int backlog)
|
||||
{
|
||||
return zts_listen(fd, backlog);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_close(JNIEnv *env, jobject thisObj,
|
||||
jint fd)
|
||||
{
|
||||
return zts_close(fd);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_sendto(
|
||||
JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, jint flags, jobject ztaddr)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
@@ -71,7 +140,7 @@ namespace ZeroTier {
|
||||
return sent_bytes;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1recvfrom(
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_recvfrom(
|
||||
JNIEnv *env, jobject thisObj, jint fd, jbyteArray buf, jint len, jint flags, jobject ztaddr)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
@@ -92,7 +161,7 @@ namespace ZeroTier {
|
||||
return rxbytes;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1send(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, int flags)
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_send(JNIEnv *env, jobject thisObj, jint fd, jarray buf, jint len, int flags)
|
||||
{
|
||||
jbyte *body = (*env).GetByteArrayElements((_jbyteArray *)buf, 0);
|
||||
char * bufp = (char *)malloc(sizeof(char)*len);
|
||||
@@ -102,7 +171,7 @@ namespace ZeroTier {
|
||||
return written_bytes;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1write(JNIEnv *env, jobject thisObj,
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_write(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jarray buf, jint len)
|
||||
{
|
||||
jbyte *body = (*env).GetByteArrayElements((_jbyteArray *)buf, 0);
|
||||
@@ -113,7 +182,7 @@ namespace ZeroTier {
|
||||
return written_bytes;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1read(JNIEnv *env, jobject thisObj,
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_read(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jarray buf, jint len)
|
||||
{
|
||||
jbyte *body = (*env).GetByteArrayElements((_jbyteArray *)buf, 0);
|
||||
@@ -122,89 +191,20 @@ namespace ZeroTier {
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1socket(JNIEnv *env, jobject thisObj,
|
||||
jint family, jint type, jint protocol)
|
||||
{
|
||||
return zts_socket(family, type, protocol);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1connect(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
const char *str = (*env).GetStringUTFChars( addrstr, 0);
|
||||
addr.sin_addr.s_addr = inet_addr(str);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
(*env).ReleaseStringUTFChars( addrstr, str);
|
||||
return zts_connect(fd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1bind(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
const char *str = (*env).GetStringUTFChars( addrstr, 0);
|
||||
DEBUG_INFO("fd=%d, addr=%s, port=%d", fd, str, port);
|
||||
addr.sin_addr.s_addr = inet_addr(str);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
(*env).ReleaseStringUTFChars( addrstr, str);
|
||||
return zts_bind(fd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1accept4(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port, jint flags)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
char *str;
|
||||
// = env->GetStringUTFChars(addrstr, NULL);
|
||||
(*env).ReleaseStringUTFChars( addrstr, str);
|
||||
addr.sin_addr.s_addr = inet_addr(str);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
return zts_accept4(fd, (struct sockaddr *)&addr, sizeof(addr), flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1accept(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jstring addrstr, jint port)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
// TODO: Send addr info back to Javaland
|
||||
addr.sin_addr.s_addr = inet_addr("");
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons( port );
|
||||
return zts_accept(fd, (struct sockaddr *)&addr, (socklen_t *)sizeof(addr));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1listen(JNIEnv *env, jobject thisObj,
|
||||
jint fd, int backlog)
|
||||
{
|
||||
return zts_listen(fd, backlog);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1close(JNIEnv *env, jobject thisObj,
|
||||
jint fd)
|
||||
{
|
||||
return zts_close(fd);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1setsockopt(
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_setsockopt(
|
||||
JNIEnv *env, jobject thisObj,
|
||||
jint fd, jint level, jint optname, jint optval, jint optlen)
|
||||
{
|
||||
return zts_setsockopt(fd, level, optname, (const void*)optval, optlen);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1getsockopt(JNIEnv *env, jobject thisObj,
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_getsockopt(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jint level, jint optname, jint optval, jint optlen)
|
||||
{
|
||||
return zts_getsockopt(fd, level, optname, (void*)optval, (socklen_t *)optlen);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1getsockname(JNIEnv *env, jobject thisObj,
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_getsockname(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jobject ztaddr)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
@@ -218,7 +218,7 @@ namespace ZeroTier {
|
||||
return err;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1getpeername(JNIEnv *env, jobject thisObj,
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_getpeername(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jobject ztaddr)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
@@ -232,7 +232,7 @@ namespace ZeroTier {
|
||||
return err;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_ztjni_1fcntl(JNIEnv *env, jobject thisObj,
|
||||
JNIEXPORT jint JNICALL Java_zerotier_ZeroTier_fcntl(JNIEnv *env, jobject thisObj,
|
||||
jint fd, jint cmd, jint flags)
|
||||
{
|
||||
return zts_fcntl(fd,cmd,flags);
|
||||
@@ -242,46 +242,46 @@ namespace ZeroTier {
|
||||
/* ZeroTier service controls (for JNI wrapper) */
|
||||
/****************************************************************************/
|
||||
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_ztjni_1start(JNIEnv *env, jobject thisObj, jstring path)
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_start(JNIEnv *env, jobject thisObj, jstring path)
|
||||
{
|
||||
if (path) {
|
||||
zts_start(env->GetStringUTFChars(path, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_ztjni_1startjoin(JNIEnv *env, jobject thisObj, jstring path, jstring nwid)
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_startjoin(JNIEnv *env, jobject thisObj, jstring path, jstring nwid)
|
||||
{
|
||||
if (path && nwid) {
|
||||
zts_startjoin(env->GetStringUTFChars(path, NULL), env->GetStringUTFChars(nwid, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_ztjni_1stop(JNIEnv *env, jobject thisObj)
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_stop(JNIEnv *env, jobject thisObj)
|
||||
{
|
||||
zts_stop();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_zerotier_ZeroTier_ztjni_1running(
|
||||
JNIEXPORT jboolean JNICALL Java_zerotier_ZeroTier_running(
|
||||
JNIEnv *env, jobject thisObj)
|
||||
{
|
||||
return zts_running();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_ztjni_1join(JNIEnv *env, jobject thisObj, jstring nwid)
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_join(JNIEnv *env, jobject thisObj, jstring nwid)
|
||||
{
|
||||
if (nwid) {
|
||||
zts_join(env->GetStringUTFChars(nwid, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_ztjni_1leave(JNIEnv *env, jobject thisObj, jstring nwid)
|
||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_leave(JNIEnv *env, jobject thisObj, jstring nwid)
|
||||
{
|
||||
if (nwid) {
|
||||
zts_leave(env->GetStringUTFChars(nwid, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_zerotier_ZeroTier_ztjni_1homepath(
|
||||
JNIEXPORT jstring JNICALL Java_zerotier_ZeroTier_homepath(
|
||||
JNIEnv *env, jobject thisObj)
|
||||
{
|
||||
// TODO: fix, should copy into given arg
|
||||
@@ -289,7 +289,7 @@ namespace ZeroTier {
|
||||
return (*env).NewStringUTF("");
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_zerotier_ZeroTier_ztjni_1get_1ipv4_1address(
|
||||
JNIEXPORT jobject JNICALL Java_zerotier_ZeroTier_get_ipv4_address(
|
||||
JNIEnv *env, jobject thisObj, jstring nwid)
|
||||
{
|
||||
const char *nwid_str = env->GetStringUTFChars(nwid, NULL);
|
||||
@@ -303,7 +303,7 @@ namespace ZeroTier {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_zerotier_ZeroTier_ztjni_1get_1ipv6_1address(
|
||||
JNIEXPORT jobject JNICALL Java_zerotier_ZeroTier_get_ipv6_address(
|
||||
JNIEnv *env, jobject thisObj, jstring nwid)
|
||||
{
|
||||
const char *nwid_str = env->GetStringUTFChars(nwid, NULL);
|
||||
@@ -317,7 +317,7 @@ namespace ZeroTier {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
JNIEXPORT jint Java_zerotier_ZeroTier_ztjni_1get_1id()
|
||||
JNIEXPORT jint Java_zerotier_ZeroTier_get_id()
|
||||
{
|
||||
return zts_get_id(NULL); // TODO
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user