aboutsummaryrefslogtreecommitdiffstats
path: root/wireguard-go-bridge/example.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-06-09 03:14:34 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-06-09 04:22:11 +0200
commit831640312c7cd0305e47c6292f9494a9e779b769 (patch)
tree28d0ac0f4add5a3d2d8685e3122c3bcda4a564ef /wireguard-go-bridge/example.c
parentAllow adding and deleting peers. (diff)
downloadwireguard-apple-831640312c7cd0305e47c6292f9494a9e779b769.tar.xz
wireguard-apple-831640312c7cd0305e47c6292f9494a9e779b769.zip
First stab at Go bridge
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'wireguard-go-bridge/example.c')
-rw-r--r--wireguard-go-bridge/example.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/wireguard-go-bridge/example.c b/wireguard-go-bridge/example.c
new file mode 100644
index 0000000..912d181
--- /dev/null
+++ b/wireguard-go-bridge/example.c
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ */
+
+#include "wireguard.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+static struct {
+ int something;
+} ctx;
+
+static bool is_closed = false;
+
+ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len)
+{
+ printf("Reading from instance with ctx %p into buffer %p of length %zu\n", ctx, buf, len);
+ sleep(1);
+ return is_closed ? -1 : 0;
+}
+
+ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len)
+{
+ printf("Writing from instance with ctx %p into buffer %p of length %zu\n", ctx, buf, len);
+ return len;
+}
+
+void do_log(int level, const char *tag, const char *msg)
+{
+ printf("Log level %d for %s: %s", level, tag, msg);
+}
+
+int main(int argc, char *argv[])
+{
+ int handle;
+
+ printf("WireGuard Go Version %s\n", wgVersion());
+ wgSetLogger(do_log);
+ handle = wgTurnOn((gostring_t){ .p = "test", .n = 4 }, (gostring_t){ .p = "", .n = 0 }, do_read, do_write, &ctx);
+ sleep(5);
+ is_closed = true;
+ wgTurnOff(handle);
+ return 0;
+}