diff --git a/src/main.c b/src/main.c index 864ef80..50cbeec 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,7 @@ static struct { int chacha20; int version; int keygen; + int persist; struct { unsigned char *data; long size; @@ -193,6 +194,7 @@ gt_setup_option(int argc, char **argv) { "bind-backup", >.bind.backup, option_str }, { "bind-port", >.bind.port, option_long }, { "dev", >.dev, option_str }, + { "persist", NULL, option_option }, { "mtu", >.mtu, option_long }, { "mtu-auto", NULL, option_option }, { "keyfile", >.keyfile, option_str }, @@ -244,6 +246,7 @@ gt_setup_option(int argc, char **argv) gt.chacha20 = option_is_set(opts, "chacha20"); gt.version = option_is_set(opts, "version"); gt.keygen = option_is_set(opts, "keygen"); + gt.persist = option_is_set(opts, "persist"); gt.buf.data = malloc(gt.buf.size); @@ -327,7 +330,7 @@ main(int argc, char **argv) return 1; } - if (tun_set_persist(tun_fd, 0) == -1) + if (tun_set_persist(tun_fd, gt.persist) == -1) perror("tun_set_persist"); if (str_empty(gt.keyfile)) { diff --git a/src/tun.c b/src/tun.c index f2b8532..6afd6d1 100644 --- a/src/tun.c +++ b/src/tun.c @@ -245,6 +245,7 @@ tun_set_persist(int fd, int on) #ifdef TUNSETPERSIST return ioctl(fd, TUNSETPERSIST, on); #else - return 0; + errno = ENOSYS; + return -1; #endif }