diff options
Diffstat (limited to 'app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c')
-rw-r--r-- | app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c index a0f3d0ba..acb2d728 100644 --- a/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c +++ b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c @@ -4,12 +4,15 @@ */ #include <jni.h> +#include <stdlib.h> +#include <string.h> struct go_string { const char *str; long n; }; extern int wgTurnOn(struct go_string ifname, int tun_fd, struct go_string settings); extern void wgTurnOff(int handle); extern int wgGetSocketV4(int handle); extern int wgGetSocketV6(int handle); +extern struct go_string wgVersion(); JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgTurnOn(JNIEnv *env, jclass c, jstring ifname, jint tun_fd, jstring settings) { @@ -43,3 +46,17 @@ JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetSocketV { return wgGetSocketV6(handle); } + +JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_GoBackend_wgVersion(JNIEnv *env, jclass c) +{ + struct go_string s = wgVersion(); + char *cstr = malloc(s.n + 1); + if (!cstr) + return NULL; + jstring ret; + memcpy(cstr, s.str, s.n); + cstr[s.n] = '\0'; + ret = (*env)->NewStringUTF(env, cstr); + free(cstr); + return ret; +} |