Просмотр исходного кода

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

Jeremy T. Bouse 22 лет назад
Родитель
Сommit
825a7322b1
2 измененных файлов с 20 добавлено и 7 удалено
  1. 17 4
      plugins/check_ping.c
  2. 3 3
      plugins/netutils.c

+ 17 - 4
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) {

+ 3 - 3
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