aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/set.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2015-06-05 15:58:00 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2016-06-25 16:48:39 +0200
commit8132305e54d45dbad65bf9ef6f6c5805c841d1da (patch)
treed0d9aae746ac41e2cf231d0c01b5f8aa62a04ce2 /src/set.c
downloadwireguard-tools-8132305e54d45dbad65bf9ef6f6c5805c841d1da.tar.xz
wireguard-tools-8132305e54d45dbad65bf9ef6f6c5805c841d1da.zip
Initial commit
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/set.c')
-rw-r--r--src/set.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/set.c b/src/set.c
new file mode 100644
index 0000000..f85162d
--- /dev/null
+++ b/src/set.c
@@ -0,0 +1,35 @@
+/* Copyright 2015-2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "subcommands.h"
+#include "config.h"
+#include "kernel.h"
+
+int set_main(int argc, char *argv[])
+{
+ struct wgdevice *device = NULL;
+ int ret = 1;
+
+ if (argc < 3) {
+ fprintf(stderr, "Usage: %s %s <interface> [listen-port <port>] [private-key <file path>] [peer <base64 public key> [remove] [endpoint <ip>:<port>] [allowed-ips <ip1>/<cidr1>[,<ip2>/<cidr2>]...] ]...\n", PROG_NAME, argv[0]);
+ return 1;
+ }
+
+ if (!config_read_cmd(&device, argv + 2, argc - 2))
+ goto cleanup;
+ strncpy(device->interface, argv[1], IFNAMSIZ - 1);
+ device->interface[IFNAMSIZ - 1] = 0;
+
+ if (kernel_set_device(device) != 0) {
+ perror("Unable to set device");
+ goto cleanup;
+ }
+
+ ret = 0;
+
+cleanup:
+ free(device);
+ return ret;
+}