summaryrefslogtreecommitdiffhomepage
path: root/tunnel/tools/libwg-go/jni.c
diff options
context:
space:
mode:
Diffstat (limited to 'tunnel/tools/libwg-go/jni.c')
-rw-r--r--tunnel/tools/libwg-go/jni.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tunnel/tools/libwg-go/jni.c b/tunnel/tools/libwg-go/jni.c
index 3f877d47..1cc69343 100644
--- a/tunnel/tools/libwg-go/jni.c
+++ b/tunnel/tools/libwg-go/jni.c
@@ -10,6 +10,8 @@
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 char *wgGetOperation(int handle);
+extern int wgSetOperation(int handle, struct go_string settings);
extern int wgGetSocketV4(int handle);
extern int wgGetSocketV6(int handle);
extern char *wgGetConfig(int handle);
@@ -38,6 +40,29 @@ JNIEXPORT void JNICALL Java_com_wireguard_android_backend_GoBackend_wgTurnOff(JN
wgTurnOff(handle);
}
+JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetOperation(JNIEnv *env, jclass c, jint handle)
+{
+ jstring ret;
+ char *settings = wgGetOperation(handle);
+ if (!settings)
+ return NULL;
+ ret = (*env)->NewStringUTF(env, settings);
+ free(settings);
+ return ret;
+}
+
+JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgSetOperation(JNIEnv *env, jclass c, jint handle, jstring settings)
+{
+ const char *settings_str = (*env)->GetStringUTFChars(env, settings, 0);
+ size_t settings_len = (*env)->GetStringUTFLength(env, settings);
+ int ret = wgSetOperation(handle, (struct go_string){
+ .str = settings_str,
+ .n = settings_len
+ });
+ (*env)->ReleaseStringUTFChars(env, settings, settings_str);
+ return ret;
+}
+
JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetSocketV4(JNIEnv *env, jclass c, jint handle)
{
return wgGetSocketV4(handle);