summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d77d183)
raw | patch | inline | side by side (parent: d77d183)
author | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | |
Sun, 29 Jun 2003 19:17:27 +0000 (19:17 +0000) | ||
committer | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | |
Sun, 29 Jun 2003 19:17:27 +0000 (19:17 +0000) |
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
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
plugins/check_ping.c | patch | blob | history | |
plugins/netutils.c | patch | blob | history |
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index 54402ae3a2202ccb9032836e728cfb7976b713ea..ffe7a7d5fc7ed5efaed52bf42fa510acfad547c6 100644 (file)
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
#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\
#include "config.h"
#include "common.h"
+#include "netutils.h"
#include "popen.h"
#include "utils.h"
/* 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);
{"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}
};
}
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;
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 dc679e2ab336bba80a67fb0e63833e69f1c66675..60410c64345f1759af7790efc23732928190d18c 100644 (file)
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
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
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