From 0cbc33781e33602f35a677bc6a9688d3d8cf3031 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 16 Oct 2020 23:42:24 +0200 Subject: add help option --- gre.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gre.c b/gre.c index 68f4a14..b6d7cdb 100644 --- a/gre.c +++ b/gre.c @@ -62,6 +62,13 @@ static int daemonize(void); static int inet_addr_storage(const char *cp, struct sockaddr_storage *sp, size_t *sp_len); static int is_any(const struct sockaddr_storage *ss); +static int usage(const char *arg0) +{ + printf("usage: %s [-n|--tun|-p|--tap] [remote] local\n", arg0); + exit(EXIT_FAILURE); +} + + int main(int argc, char **argv) { fd_set readset; @@ -71,6 +78,7 @@ int main(int argc, char **argv) int option_index = 0; static struct option long_options[] = { {"foreground", no_argument, 0, 'f' }, + {"help", no_argument, 0, 'h' }, {"tun", no_argument, 0, 'n' }, {"tap", no_argument, 0, 'p' }, {0, 0, 0, 0 } @@ -85,6 +93,11 @@ int main(int argc, char **argv) case 'f': foreground = 1; break; + + case 'h': + usage(argv[0]); + break; + case 'n': printf("tun\n"); type = IFF_TUN; @@ -107,8 +120,7 @@ int main(int argc, char **argv) if (optnum < 2 || optnum > 3) { - printf("usage: %s [-n|--tun|-p|--tap] [remote] local\n", argv[0]); - return EXIT_FAILURE; + usage(argv[0]); } const char *dev = argv[optind++]; -- cgit v1.2.3