From d77d183ddb8bdff5069ba5fa008406087162d117 Mon Sep 17 00:00:00 2001 From: "Jeremy T. Bouse" Date: Sun, 29 Jun 2003 06:36:55 +0000 Subject: 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 diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c index f3a351e..421fc01 100644 --- a/plugins/check_ssh.c +++ b/plugins/check_ssh.c @@ -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] \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 */ diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index f4fe5f4..0f19c01 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.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); diff --git a/plugins/netutils.c b/plugins/netutils.c index c567df5..dc679e2 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c @@ -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; diff --git a/plugins/netutils.h b/plugins/netutils.h index 2ad0dba..8f53497 100644 --- a/plugins/netutils.h +++ b/plugins/netutils.h @@ -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; -- cgit v0.10-9-g596f