mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-03-27 12:56:04 -04:00
Added address_family extern int variable to netutils to allow for -4 & -6
options for explicit connection protocol Added support for -4 & -6 options to check_ssh and check_tcp for testing git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@568 f882894a-f735-0410-b71e-b25c423dba1c
This commit is contained in:
parent
cb448eb1d5
commit
d77d183ddb
4 changed files with 30 additions and 5 deletions
|
|
@ -68,6 +68,8 @@ process_arguments (int argc, char **argv)
|
|||
static struct option long_options[] = {
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"host", required_argument, 0, 'H'},
|
||||
|
|
@ -82,7 +84,7 @@ process_arguments (int argc, char **argv)
|
|||
strcpy (argv[c], "-t");
|
||||
|
||||
while (1) {
|
||||
c = getopt_long (argc, argv, "+Vhvt:H:p:", long_options, &option_index);
|
||||
c = getopt_long (argc, argv, "+Vhv46t:H:p:", long_options, &option_index);
|
||||
|
||||
if (c == -1 || c == EOF)
|
||||
break;
|
||||
|
|
@ -104,6 +106,12 @@ process_arguments (int argc, char **argv)
|
|||
usage ("Timeout Interval must be an integer!\n\n");
|
||||
socket_timeout = atoi (optarg);
|
||||
break;
|
||||
case '4':
|
||||
address_family = AF_INET;
|
||||
break;
|
||||
case '6':
|
||||
address_family = AF_INET6;
|
||||
break;
|
||||
case 'H': /* host */
|
||||
if (is_host (optarg) == FALSE)
|
||||
usage ("Invalid hostname/address\n");
|
||||
|
|
@ -217,7 +225,10 @@ print_usage (void)
|
|||
("Usage:\n"
|
||||
" %s -t [timeout] -p [port] <host>\n"
|
||||
" %s -V prints version info\n"
|
||||
" %s -h prints more detailed help\n", progname, progname, progname);
|
||||
" %s -4 use IPv4 connection\n"
|
||||
" %s -6 use IPv6 connection\n"
|
||||
" %s -h prints more detailed help\n",
|
||||
progname, progname, progname, progname, progname);
|
||||
}
|
||||
|
||||
/* end of check_ssh.c */
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ This plugin tests %s connections with the specified host.\n";
|
|||
const char *option_summary = "\
|
||||
-H host -p port [-w warn_time] [-c crit_time] [-s send_string]\n\
|
||||
[-e expect_string] [-q quit_string] [-m maxbytes] [-d delay]\n\
|
||||
[-t to_sec] [-r refuse_state] [-v]\n";
|
||||
[-t to_sec] [-r refuse_state] [-v] [-4] [-6]\n";
|
||||
|
||||
const char *options = "\
|
||||
-H, --hostname=ADDRESS\n\
|
||||
|
|
@ -37,6 +37,10 @@ const char *options = "\
|
|||
address if possible to bypass DNS lookup).\n\
|
||||
-p, --port=INTEGER\n\
|
||||
Port number\n\
|
||||
-4, --use-ipv4\n\
|
||||
Use IPv4 connection\n\
|
||||
-6, --use-ipv6\n\
|
||||
Use IPv6 connection\n\
|
||||
-s, --send=STRING\n\
|
||||
String to send to the server\n\
|
||||
-e, --expect=STRING\n\
|
||||
|
|
@ -392,6 +396,8 @@ process_arguments (int argc, char **argv)
|
|||
{"quit", required_argument, 0, 'q'},
|
||||
{"delay", required_argument, 0, 'd'},
|
||||
{"refuse", required_argument, 0, 'r'},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
|
|
@ -419,7 +425,7 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
while (1) {
|
||||
c = getopt_long (argc, argv, "+hVvH:s:e:q:m:c:w:t:p:C:W:d:Sr:",
|
||||
c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:",
|
||||
long_options, &option_index);
|
||||
|
||||
if (c == -1 || c == EOF || c == 1)
|
||||
|
|
@ -439,6 +445,12 @@ process_arguments (int argc, char **argv)
|
|||
case 'v': /* verbose mode */
|
||||
verbose = TRUE;
|
||||
break;
|
||||
case '4':
|
||||
address_family = AF_INET;
|
||||
break;
|
||||
case '6':
|
||||
address_family = AF_INET6;
|
||||
break;
|
||||
case 'H': /* hostname */
|
||||
if (is_host (optarg) == FALSE)
|
||||
usage2 ("invalid host name or address", optarg);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
|
||||
int econn_refuse_state = STATE_CRITICAL;
|
||||
int was_refused = FALSE;
|
||||
int address_family = AF_UNSPEC;
|
||||
|
||||
/* handles socket timeouts */
|
||||
void
|
||||
|
|
@ -254,7 +255,7 @@ my_connect (char *host_name, int port, int *sd, int proto)
|
|||
int result;
|
||||
|
||||
memset (&hints, 0, sizeof (hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_family = address_family;
|
||||
hints.ai_protocol = proto;
|
||||
hints.ai_socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,3 +61,4 @@ int is_hostname (char *);
|
|||
extern int socket_timeout;
|
||||
extern int econn_refuse_state;
|
||||
extern int was_refused;
|
||||
extern int address_family;
|
||||
|
|
|
|||
Loading…
Reference in a new issue