X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/3634fc257bd0667daef14d72005cd87c735bbb24..7390e768d82239b8dc6697379277c37c8c927b9d:/test/src/client.c diff --git a/test/src/client.c b/test/src/client.c index 6a083d055..58ab56d4c 100644 --- a/test/src/client.c +++ b/test/src/client.c @@ -361,13 +361,14 @@ return session; * Main Program * *************************************************/ -/* Usage: client - - - [] - [] - [] -*/ +const char * const HELP_MESSAGE = "\n\ +Usage: client\n\ + \n\ + \n\ + []\n\ + []\n\ + []\n\ +\n"; int main(int argc, char **argv) { @@ -377,12 +378,14 @@ char *interface = NULL; char *address = NULL; char *certfile = NULL; char *keyfile = NULL; +char *end = NULL; int argi = 1; int host_af, port, s_len, rc, sock, save_errno; int timeout = 1; int tls_active = 0; int sent_starttls = 0; int tls_on_connect = 0; +long tmplong; #if HAVE_IPV6 struct sockaddr_in6 s_in6; @@ -403,6 +406,13 @@ unsigned char *inptr = inbuffer; while (argc >= argi + 1 && argv[argi][0] == '-') { + if (strcmp(argv[argi], "-help") == 0 || + strcmp(argv[argi], "--help") == 0 || + strcmp(argv[argi], "-h") == 0) + { + printf(HELP_MESSAGE); + exit(0); + } if (strcmp(argv[argi], "-tls-on-connect") == 0) { tls_on_connect = 1; @@ -410,12 +420,30 @@ while (argc >= argi + 1 && argv[argi][0] == '-') } else if (argv[argi][1] == 't' && isdigit(argv[argi][2])) { - timeout = atoi(argv[argi]+1); + tmplong = strtol(argv[argi]+2, &end, 10); + if (end == argv[argi]+2 || *end) + { + fprintf(stderr, "Failed to parse seconds from option <%s>\n", + argv[argi]); + exit(1); + } + if (tmplong > 10000L) + { + fprintf(stderr, "Unreasonably long wait of %d seconds requested\n", + tmplong); + exit(1); + } + if (tmplong < 0L) + { + fprintf(stderr, "Timeout must not be negative (%d)\n", tmplong); + exit(1); + } + timeout = (int) tmplong; argi++; } else { - printf("Unrecognized option %s\n", argv[argi]); + fprintf(stderr, "Unrecognized option %s\n", argv[argi]); exit(1); } } @@ -424,7 +452,7 @@ while (argc >= argi + 1 && argv[argi][0] == '-') if (argc < argi+1) { - printf("No IP address given\n"); + fprintf(stderr, "No IP address given\n"); exit(1); } @@ -435,7 +463,7 @@ host_af = (strchr(address, ':') != NULL)? AF_INET6 : AF_INET; if (argc < argi+1) { - printf("No port number given\n"); + fprintf(stderr, "No port number given\n"); exit(1); }