diff --git a/plugins/check_udp.c b/plugins/check_udp.c
index f6b528dcaaa3ced63e5ac30d0d59f835ceb366a4..ac2210257d4f32d422fe2794b6a16063f89237f6 100644 (file)
--- a/plugins/check_udp.c
+++ b/plugins/check_udp.c
#include "netutils.h"
#include "utils.h"
-#define PROGNAME "check_udp"
+const char *progname = "check_udp";
int warning_time = 0;
int check_warning_time = FALSE;
{
int c;
-#ifdef HAVE_GETOPT_H
int option_index = 0;
static struct option long_options[] = {
{"hostname", required_argument, 0, 'H'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
-#endif
if (argc < 2)
usage ("\n");
}
while (1) {
-#ifdef HAVE_GETOPT_H
- c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", long_options, &option_index);
-#else
- c = getopt (argc, argv, "+hVvH:e:s:c:w:t:p:");
-#endif
+ c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", long_options, &option_index);
+
+ if (c == -1 || c == EOF || c == 1)
+ break;
switch (c) {
case '?': /* print short usage statement if args not parsable */
- printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg);
+ printf ("%s: Unknown argument: %s\n\n", progname, optarg);
print_usage ();
exit (STATE_UNKNOWN);
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 'v': /* verbose mode */
verbose = TRUE;
}
c = optind;
- if (server_address == NULL && argv[c]) {
+ if (server_address == NULL && c < argc && argv[c]) {
if (is_host (argv[c]) == FALSE)
usage ("Invalid host name/address\n");
server_address = argv[c++];
}
- else {
+
+ if (server_address == NULL)
usage ("Host name was not supplied\n");
- }
return c;
}
{
printf
("Usage: %s -H <host_address> [-p port] [-w warn_time] [-c crit_time]\n"
- " [-e expect] [-s send] [-t to_sec] [-v]\n", PROGNAME);
+ " [-e expect] [-s send] [-t to_sec] [-v]\n", progname);
}
void
print_help (void)
{
- print_revision (PROGNAME, "$Revision$");
+ print_revision (progname, "$Revision$");
printf
("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n"
"This plugin tests an UDP connection with the specified host.\n\n");