aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/check_ping.c21
-rw-r--r--plugins/netutils.c6
2 files changed, 20 insertions, 7 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 54402ae3..ffe7a7d5 100644
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
@@ -19,11 +19,15 @@ const char *progname = "check_ping";
#define OPTIONS "\
-H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n\
- [-p packets] [-t timeout] [-L]\n"
+ [-p packets] [-t timeout] [-L] [-4] [-6]\n"
#define LONGOPTIONS "\
-H, --hostname=HOST\n\
host to ping\n\
+-4, --use-ipv4\n\
+ Use IPv4 ICMP PING\n\
+-6, --use-ipv6\n\
+ Use IPv6 ICMP PING\n\
-w, --warning=THRESHOLD\n\
warning threshold pair\n\
-c, --critical=THRESHOLD\n\
@@ -46,6 +50,7 @@ the contrib area of the downloads section at http://www.nagios.org\n\n"
#include "config.h"
#include "common.h"
+#include "netutils.h"
#include "popen.h"
#include "utils.h"
@@ -106,12 +111,12 @@ main (int argc, char **argv)
/* does the host address of number of packets argument come first? */
#ifdef PING6_COMMAND
# ifdef PING_PACKETS_FIRST
- if (is_inet6_addr(addresses[i]))
+ if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
asprintf (&command_line, PING6_COMMAND, max_packets, addresses[i]);
else
asprintf (&command_line, PING_COMMAND, max_packets, addresses[i]);
# else
- if (is_inet6_addr(addresses[i]))
+ if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
asprintf (&command_line, PING6_COMMAND, addresses[i], max_packets);
else
asprintf (&command_line, PING_COMMAND, addresses[i], max_packets);
@@ -182,6 +187,8 @@ process_arguments (int argc, char **argv)
{"packets", required_argument, 0, 'p'},
{"nohtml", no_argument, 0, 'n'},
{"link", no_argument, 0, 'L'},
+ {"use-ipv4", no_argument, 0, '4'},
+ {"use-ipv6", no_argument, 0, '6'},
{0, 0, 0, 0}
};
@@ -196,7 +203,7 @@ process_arguments (int argc, char **argv)
}
while (1) {
- c = getopt_long (argc, argv, "VvhnLt:c:w:H:p:", long_options, &option_index);
+ c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", long_options, &option_index);
if (c == -1 || c == EOF)
break;
@@ -216,6 +223,12 @@ process_arguments (int argc, char **argv)
case 'v': /* verbose mode */
verbose = TRUE;
break;
+ case '4': /* IPv4 only */
+ address_family = AF_INET;
+ break;
+ case '6': /* IPv6 only */
+ address_family = AF_INET6;
+ break;
case 'H': /* hostname */
ptr=optarg;
while (1) {
diff --git a/plugins/netutils.c b/plugins/netutils.c
index dc679e2a..60410c64 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -326,11 +326,11 @@ is_host (char *address)
int
is_addr (char *address)
{
- if (is_inet_addr (address))
+ if (is_inet_addr (address) && address_family != AF_INET6)
return (TRUE);
#ifdef USE_IPV6
- if (is_inet6_addr (address))
+ if (is_inet6_addr (address) && address_family != AF_INET)
return (TRUE);
#endif
@@ -374,7 +374,7 @@ int
is_hostname (char *s1)
{
#ifdef USE_IPV6
- return resolve_host_or_addr (s1, AF_UNSPEC);
+ return resolve_host_or_addr (s1, address_family);
#else
return resolve_host_or_addr (s1, AF_INET);
#endif