X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_time.c;h=e4bd26d7f7fc24c5cb34eb5836d08e300dbcc07f;hb=7ceff0d5a95f5c5f34235ef6682595f169864d2f;hp=86c414e2c413853210e7670121f13fb183df4fb4;hpb=44a321cb8a42d6c0ea2d96a1086a17f2134c89cc;p=nagiosplug.git diff --git a/plugins/check_time.c b/plugins/check_time.c index 86c414e..e4bd26d 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c @@ -39,7 +39,12 @@ #include "netutils.h" #include "utils.h" -#define PROGNAME "check_time" +const char *progname = "check_time"; +#define REVISION "$Revision$" +#define COPYRIGHT "1999-2002" +#define AUTHOR "Ethan Galstad" +#define EMAIL "nagios@nagios.org" +#define SUMMARY "Check time on the specified host.\n" #define TIME_PORT 37 #define UNIX_EPOCH 2208988800UL @@ -59,7 +64,6 @@ char *server_address = NULL; int process_arguments (int, char **); -int call_getopt (int, char **); void print_usage (void); void print_help (void); @@ -89,12 +93,12 @@ main (int argc, char **argv) else result = STATE_UNKNOWN; terminate (result, - "TIME UNKNOWN - could not connect to server %s, port %d\n", - server_address, server_port); + "TIME UNKNOWN - could not connect to server %s, port %d\n", + server_address, server_port); } - /* watch for the FTP connection string */ - result = recv (sd, &raw_server_time, sizeof (raw_server_time), 0); + /* watch for the connection string */ + result = recv (sd, (void *)&raw_server_time, sizeof (raw_server_time), 0); /* close the connection */ close (sd); @@ -154,52 +158,6 @@ process_arguments (int argc, char **argv) { int c; - if (argc < 2) - usage ("\n"); - - for (c = 1; c < argc; c++) { - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - else if (strcmp ("-wd", argv[c]) == 0) - strcpy (argv[c], "-w"); - else if (strcmp ("-cd", argv[c]) == 0) - strcpy (argv[c], "-c"); - else if (strcmp ("-wt", argv[c]) == 0) - strcpy (argv[c], "-W"); - else if (strcmp ("-ct", argv[c]) == 0) - strcpy (argv[c], "-C"); - } - - c = 0; - while ((c += call_getopt (argc - c, &argv[c])) < argc) { - - if (is_option (argv[c])) - continue; - - if (server_address == NULL) { - if (argc > c) { - if (is_host (argv[c]) == FALSE) - usage ("Invalid host name/address\n"); - server_address = argv[c]; - } - else { - usage ("Host name was not supplied\n"); - } - } - } - - return OK; -} - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - #ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { @@ -216,41 +174,42 @@ call_getopt (int argc, char **argv) }; #endif + if (argc < 2) + usage ("\n"); + + for (c = 1; c < argc; c++) { + if (strcmp ("-to", argv[c]) == 0) + strcpy (argv[c], "-t"); + else if (strcmp ("-wd", argv[c]) == 0) + strcpy (argv[c], "-w"); + else if (strcmp ("-cd", argv[c]) == 0) + strcpy (argv[c], "-c"); + else if (strcmp ("-wt", argv[c]) == 0) + strcpy (argv[c], "-W"); + else if (strcmp ("-ct", argv[c]) == 0) + strcpy (argv[c], "-C"); + } + while (1) { #ifdef HAVE_GETOPT_H c = - getopt_long (argc, argv, "+hVH:w:c:W:C:p:t:", long_options, + getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", long_options, &option_index); #else - c = getopt (argc, argv, "+hVH:w:c:W:C:p:t:"); + c = getopt (argc, argv, "hVH:w:c:W:C:p:t:"); #endif - i++; - - if (c == -1 || c == EOF || c == 1) + if (c == -1 || c == EOF) break; - switch (c) { - case 'H': - case 'w': - case 'c': - case 'W': - case 'C': - case 'p': - case 't': - i++; - } - switch (c) { case '?': /* print short usage statement if args not parsable */ - printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); - print_usage (); - exit (STATE_UNKNOWN); + usage3 ("Unknown argument", optopt); case 'h': /* help */ print_help (); exit (STATE_OK); case 'V': /* version */ - print_revision (my_basename (argv[0]), "$Revision$"); + print_revision (progname, REVISION); exit (STATE_OK); case 'H': /* hostname */ if (is_host (optarg) == FALSE) @@ -318,7 +277,20 @@ call_getopt (int argc, char **argv) break; } } - return i; + + c = optind; + if (server_address == NULL) { + if (argc > c) { + if (is_host (argv[c]) == FALSE) + usage ("Invalid host name/address\n"); + server_address = argv[c]; + } + else { + usage ("Host name was not supplied\n"); + } + } + + return OK; } @@ -329,8 +301,12 @@ void print_usage (void) { printf - ("Usage: check_time -H [-p port] [-w variance] [-c variance]\n" - " [-W connect_time] [-C connect_time] [-t timeout]\n"); + ("Usage:\n" + " %s -H [-p port] [-w variance] [-c variance]\n" + " [-W connect_time] [-C connect_time] [-t timeout]\n" + " %s (-h | --help) for detailed help\n" + " %s (-V | --version) for version information\n", + progname, progname, progname); } @@ -340,10 +316,10 @@ print_usage (void) void print_help (void) { - print_revision (PROGNAME, "$Revision$"); + print_revision (progname, REVISION); printf - ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" - "This plugin connects to a time port on the specified host.\n\n"); + ("Copyright (c) %s %s <%s>\n\n%s\n", + COPYRIGHT, AUTHOR, EMAIL, SUMMARY); print_usage (); printf ("Options:\n"