From ac6db12ddbda16a37613cbf306ef645b24448b77 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Sat, 11 Mar 2017 02:32:14 -0800 Subject: [PATCH] iodine, iodined: print intentional help to stdout Like other unix tools: don't print application output, if the user asks intentionally for help. Signed-off-by: Ralf Ramsauer --- src/iodine.c | 14 +++++++------- src/iodined.c | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/iodine.c b/src/iodine.c index 766a168..71f73cc 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -65,12 +65,12 @@ sighandler(int sig) /* mark as no return to help some compilers to avoid warnings * about use of uninitialized variables */ static inline void usage(void) __attribute__((noreturn)); -static inline void help(bool verbose) __attribute__((noreturn)); +static inline void help(FILE * stream, bool verbose) __attribute__((noreturn)); #endif -static void -help(bool verbose) { - fprintf(stderr, "iodine IP over DNS tunneling client\n\n" +static void help(FILE *stream, bool verbose) +{ + fprintf(stream, "iodine IP over DNS tunneling client\n\n" "Usage: %s [-46fhrv] [-u user] [-t chrootdir] [-d device] [-P password]\n" " [-m maxfragsize] [-M maxlen] [-T type] [-O enc] [-L 0|1] [-I sec]\n" " [-z context] [-F pidfile] [nameserver] topdomain\n", __progname); @@ -78,7 +78,7 @@ help(bool verbose) { if (!verbose) exit(2); - fprintf(stderr, "\nOptions to try if connection doesn't work:\n" + fprintf(stream, "\nOptions to try if connection doesn't work:\n" " -4 to connect only to IPv4\n" " -6 to connect only to IPv6\n" " -T force dns type: NULL, PRIVATE, TXT, SRV, MX, CNAME, A (default: autodetect)\n" @@ -108,7 +108,7 @@ help(bool verbose) { static inline void usage(void) { - help(false); + help(stderr, false); } static void @@ -208,7 +208,7 @@ main(int argc, char **argv) foreground = 1; break; case 'h': - help(true); + help(stdout, true); /* NOTREACHED */ break; case 'r': diff --git a/src/iodined.c b/src/iodined.c index 63d3b62..ed24c38 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -2288,26 +2288,26 @@ write_dns(int fd, struct query *q, char *data, int datalen, char downenc) sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen); } -static void -print_usage() { - fprintf(stderr, "Usage: %s [-46cDfsv] [-u user] [-t chrootdir] [-d device] [-m mtu]\n" +static void print_usage(FILE *stream) +{ + fprintf(stream, "Usage: %s [-46cDfsv] [-u user] [-t chrootdir] [-d device] [-m mtu]\n" " [-z context] [-l ipv4 listen address] [-L ipv6 listen address]\n" " [-p port] [-n external ip] [-b dnsport] [-P password]\n" " [-F pidfile] [-i max idle time] tunnel_ip[/netmask] topdomain\n", __progname); } -static void -usage() { - print_usage(); +static void usage(void) +{ + print_usage(stderr); exit(2); } -static void -help() { - fprintf(stderr, "iodine IP over DNS tunneling server\n\n"); - print_usage(); - fprintf(stderr, "\nAvailable options:\n" +static void help(FILE *stream) +{ + fprintf(stream, "iodine IP over DNS tunneling server\n\n"); + print_usage(stream); + fprintf(stream, "\nAvailable options:\n" " -v to print version info and exit\n" " -h to print this help and exit\n" " -4 to listen only on IPv4\n" @@ -2475,7 +2475,7 @@ main(int argc, char **argv) foreground = 1; break; case 'h': - help(); + help(stdout); break; case 'D': debug++;