diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ping.c | 21 | ||||
-rw-r--r-- | plugins/netutils.c | 6 |
2 files changed, 20 insertions, 7 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 54402ae..ffe7a7d 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -19,11 +19,15 @@ const char *progname = "check_ping"; | |||
19 | 19 | ||
20 | #define OPTIONS "\ | 20 | #define OPTIONS "\ |
21 | -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n\ | 21 | -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%%\n\ |
22 | [-p packets] [-t timeout] [-L]\n" | 22 | [-p packets] [-t timeout] [-L] [-4] [-6]\n" |
23 | 23 | ||
24 | #define LONGOPTIONS "\ | 24 | #define LONGOPTIONS "\ |
25 | -H, --hostname=HOST\n\ | 25 | -H, --hostname=HOST\n\ |
26 | host to ping\n\ | 26 | host to ping\n\ |
27 | -4, --use-ipv4\n\ | ||
28 | Use IPv4 ICMP PING\n\ | ||
29 | -6, --use-ipv6\n\ | ||
30 | Use IPv6 ICMP PING\n\ | ||
27 | -w, --warning=THRESHOLD\n\ | 31 | -w, --warning=THRESHOLD\n\ |
28 | warning threshold pair\n\ | 32 | warning threshold pair\n\ |
29 | -c, --critical=THRESHOLD\n\ | 33 | -c, --critical=THRESHOLD\n\ |
@@ -46,6 +50,7 @@ the contrib area of the downloads section at http://www.nagios.org\n\n" | |||
46 | 50 | ||
47 | #include "config.h" | 51 | #include "config.h" |
48 | #include "common.h" | 52 | #include "common.h" |
53 | #include "netutils.h" | ||
49 | #include "popen.h" | 54 | #include "popen.h" |
50 | #include "utils.h" | 55 | #include "utils.h" |
51 | 56 | ||
@@ -106,12 +111,12 @@ main (int argc, char **argv) | |||
106 | /* does the host address of number of packets argument come first? */ | 111 | /* does the host address of number of packets argument come first? */ |
107 | #ifdef PING6_COMMAND | 112 | #ifdef PING6_COMMAND |
108 | # ifdef PING_PACKETS_FIRST | 113 | # ifdef PING_PACKETS_FIRST |
109 | if (is_inet6_addr(addresses[i])) | 114 | if (is_inet6_addr(addresses[i]) && address_family != AF_INET) |
110 | asprintf (&command_line, PING6_COMMAND, max_packets, addresses[i]); | 115 | asprintf (&command_line, PING6_COMMAND, max_packets, addresses[i]); |
111 | else | 116 | else |
112 | asprintf (&command_line, PING_COMMAND, max_packets, addresses[i]); | 117 | asprintf (&command_line, PING_COMMAND, max_packets, addresses[i]); |
113 | # else | 118 | # else |
114 | if (is_inet6_addr(addresses[i])) | 119 | if (is_inet6_addr(addresses[i]) && address_family != AF_INET) |
115 | asprintf (&command_line, PING6_COMMAND, addresses[i], max_packets); | 120 | asprintf (&command_line, PING6_COMMAND, addresses[i], max_packets); |
116 | else | 121 | else |
117 | asprintf (&command_line, PING_COMMAND, addresses[i], max_packets); | 122 | asprintf (&command_line, PING_COMMAND, addresses[i], max_packets); |
@@ -182,6 +187,8 @@ process_arguments (int argc, char **argv) | |||
182 | {"packets", required_argument, 0, 'p'}, | 187 | {"packets", required_argument, 0, 'p'}, |
183 | {"nohtml", no_argument, 0, 'n'}, | 188 | {"nohtml", no_argument, 0, 'n'}, |
184 | {"link", no_argument, 0, 'L'}, | 189 | {"link", no_argument, 0, 'L'}, |
190 | {"use-ipv4", no_argument, 0, '4'}, | ||
191 | {"use-ipv6", no_argument, 0, '6'}, | ||
185 | {0, 0, 0, 0} | 192 | {0, 0, 0, 0} |
186 | }; | 193 | }; |
187 | 194 | ||
@@ -196,7 +203,7 @@ process_arguments (int argc, char **argv) | |||
196 | } | 203 | } |
197 | 204 | ||
198 | while (1) { | 205 | while (1) { |
199 | c = getopt_long (argc, argv, "VvhnLt:c:w:H:p:", long_options, &option_index); | 206 | c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", long_options, &option_index); |
200 | 207 | ||
201 | if (c == -1 || c == EOF) | 208 | if (c == -1 || c == EOF) |
202 | break; | 209 | break; |
@@ -216,6 +223,12 @@ process_arguments (int argc, char **argv) | |||
216 | case 'v': /* verbose mode */ | 223 | case 'v': /* verbose mode */ |
217 | verbose = TRUE; | 224 | verbose = TRUE; |
218 | break; | 225 | break; |
226 | case '4': /* IPv4 only */ | ||
227 | address_family = AF_INET; | ||
228 | break; | ||
229 | case '6': /* IPv6 only */ | ||
230 | address_family = AF_INET6; | ||
231 | break; | ||
219 | case 'H': /* hostname */ | 232 | case 'H': /* hostname */ |
220 | ptr=optarg; | 233 | ptr=optarg; |
221 | while (1) { | 234 | while (1) { |
diff --git a/plugins/netutils.c b/plugins/netutils.c index dc679e2..60410c6 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c | |||
@@ -326,11 +326,11 @@ is_host (char *address) | |||
326 | int | 326 | int |
327 | is_addr (char *address) | 327 | is_addr (char *address) |
328 | { | 328 | { |
329 | if (is_inet_addr (address)) | 329 | if (is_inet_addr (address) && address_family != AF_INET6) |
330 | return (TRUE); | 330 | return (TRUE); |
331 | 331 | ||
332 | #ifdef USE_IPV6 | 332 | #ifdef USE_IPV6 |
333 | if (is_inet6_addr (address)) | 333 | if (is_inet6_addr (address) && address_family != AF_INET) |
334 | return (TRUE); | 334 | return (TRUE); |
335 | #endif | 335 | #endif |
336 | 336 | ||
@@ -374,7 +374,7 @@ int | |||
374 | is_hostname (char *s1) | 374 | is_hostname (char *s1) |
375 | { | 375 | { |
376 | #ifdef USE_IPV6 | 376 | #ifdef USE_IPV6 |
377 | return resolve_host_or_addr (s1, AF_UNSPEC); | 377 | return resolve_host_or_addr (s1, address_family); |
378 | #else | 378 | #else |
379 | return resolve_host_or_addr (s1, AF_INET); | 379 | return resolve_host_or_addr (s1, AF_INET); |
380 | #endif | 380 | #endif |