* Main Program *
*************************************************/
-/* Usage: client
- <IP address>
- <port>
- [<outgoing interface>]
- [<cert file>]
- [<key file>]
-*/
+const char * const HELP_MESSAGE = "\n\
+Usage: client\n\
+ <IP address>\n\
+ <port>\n\
+ [<outgoing interface>]\n\
+ [<cert file>]\n\
+ [<key file>]\n\
+\n";
int main(int argc, char **argv)
{
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;
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;
}
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);
}
}
if (argc < argi+1)
{
- printf("No IP address given\n");
+ fprintf(stderr, "No IP address given\n");
exit(1);
}
if (argc < argi+1)
{
- printf("No port number given\n");
+ fprintf(stderr, "No port number given\n");
exit(1);
}