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 <ralf@ramses-pyramidenbau.de>
This commit is contained in:
Ralf Ramsauer 2017-03-11 02:32:14 -08:00
parent f8f87e3a54
commit ac6db12ddb
2 changed files with 19 additions and 19 deletions

View File

@ -65,12 +65,12 @@ sighandler(int sig)
/* mark as no return to help some compilers to avoid warnings /* mark as no return to help some compilers to avoid warnings
* about use of uninitialized variables */ * about use of uninitialized variables */
static inline void usage(void) __attribute__((noreturn)); 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 #endif
static void static void help(FILE *stream, bool verbose)
help(bool verbose) { {
fprintf(stderr, "iodine IP over DNS tunneling client\n\n" fprintf(stream, "iodine IP over DNS tunneling client\n\n"
"Usage: %s [-46fhrv] [-u user] [-t chrootdir] [-d device] [-P password]\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" " [-m maxfragsize] [-M maxlen] [-T type] [-O enc] [-L 0|1] [-I sec]\n"
" [-z context] [-F pidfile] [nameserver] topdomain\n", __progname); " [-z context] [-F pidfile] [nameserver] topdomain\n", __progname);
@ -78,7 +78,7 @@ help(bool verbose) {
if (!verbose) if (!verbose)
exit(2); 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" " -4 to connect only to IPv4\n"
" -6 to connect only to IPv6\n" " -6 to connect only to IPv6\n"
" -T force dns type: NULL, PRIVATE, TXT, SRV, MX, CNAME, A (default: autodetect)\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) static inline void usage(void)
{ {
help(false); help(stderr, false);
} }
static void static void
@ -208,7 +208,7 @@ main(int argc, char **argv)
foreground = 1; foreground = 1;
break; break;
case 'h': case 'h':
help(true); help(stdout, true);
/* NOTREACHED */ /* NOTREACHED */
break; break;
case 'r': case 'r':

View File

@ -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); sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen);
} }
static void static void print_usage(FILE *stream)
print_usage() { {
fprintf(stderr, "Usage: %s [-46cDfsv] [-u user] [-t chrootdir] [-d device] [-m mtu]\n" 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" " [-z context] [-l ipv4 listen address] [-L ipv6 listen address]\n"
" [-p port] [-n external ip] [-b dnsport] [-P password]\n" " [-p port] [-n external ip] [-b dnsport] [-P password]\n"
" [-F pidfile] [-i max idle time] tunnel_ip[/netmask] topdomain\n", " [-F pidfile] [-i max idle time] tunnel_ip[/netmask] topdomain\n",
__progname); __progname);
} }
static void static void usage(void)
usage() { {
print_usage(); print_usage(stderr);
exit(2); exit(2);
} }
static void static void help(FILE *stream)
help() { {
fprintf(stderr, "iodine IP over DNS tunneling server\n\n"); fprintf(stream, "iodine IP over DNS tunneling server\n\n");
print_usage(); print_usage(stream);
fprintf(stderr, "\nAvailable options:\n" fprintf(stream, "\nAvailable options:\n"
" -v to print version info and exit\n" " -v to print version info and exit\n"
" -h to print this help and exit\n" " -h to print this help and exit\n"
" -4 to listen only on IPv4\n" " -4 to listen only on IPv4\n"
@ -2475,7 +2475,7 @@ main(int argc, char **argv)
foreground = 1; foreground = 1;
break; break;
case 'h': case 'h':
help(); help(stdout);
break; break;
case 'D': case 'D':
debug++; debug++;