aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_ping.c
diff options
context:
space:
mode:
authorGravatar Jeremy T. Bouse <undrgrid@users.sourceforge.net> 2003-06-29 19:17:27 +0000
committerGravatar Jeremy T. Bouse <undrgrid@users.sourceforge.net> 2003-06-29 19:17:27 +0000
commit825a7322b131a16819b0cacccc186b86fffc57eb (patch)
tree94311e40058eb5e25321575bd9dd9f9b0c863952 /plugins/check_ping.c
parentd77d183ddb8bdff5069ba5fa008406087162d117 (diff)
downloadmonitoring-plugins-825a7322b131a16819b0cacccc186b86fffc57eb.tar.gz
check_ping is now coded with -4 & -6 options to call PING or PING6 command
netutils modified to verify hosts based on address_family setting when used with -4 or -6 options. is_inet_addr() will not be tested if -6 is used and is_inet6_addr() will not be tested if -4 is used. Also the is_hostname() will use the address_family value to resolve hostnames only if IPv6 support is available otherwise defaults to AF_INET. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@569 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_ping.c')
-rw-r--r--plugins/check_ping.c21
1 files changed, 17 insertions, 4 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) {