From 0a01d20171a2c39f0d1fb8455e9b2f6252471efc Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sun, 16 Aug 2020 01:08:55 +0200 Subject: add foreground option --- gre.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gre.c b/gre.c index 7ec4acd..d66fd36 100644 --- a/gre.c +++ b/gre.c @@ -45,6 +45,7 @@ static struct sockaddr_storage remote; static size_t remote_len; static short type = IFF_TUN; static uint8_t mac[6]; +static int foreground; uint8_t buf[65536]; @@ -67,17 +68,21 @@ int main(int argc, char **argv) { int option_index = 0; static struct option long_options[] = { + {"foreground", no_argument, 0, 'f' }, {"tun", no_argument, 0, 'n' }, {"tap", no_argument, 0, 'p' }, {0, 0, 0, 0 } }; - char c = getopt_long(argc, argv, "np", + char c = getopt_long(argc, argv, "fnp", long_options, &option_index); if (c == -1) break; switch (c) { + case 'f': + foreground = 1; + break; case 'n': printf("tun\n"); type = IFF_TUN; @@ -143,7 +148,9 @@ int main(int argc, char **argv) setnonblock(sock); setnonblock(tun); runas("nobody"); - daemonize(); + + if (!foreground) + daemonize(); int maxfd = (tun > sock ? tun : sock) + 1; while (1) -- cgit v1.2.3