Code

pass timeout to ping if supported with -w parameter (linux)
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>
Wed, 25 Feb 2004 07:49:12 +0000 (07:49 +0000)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>
Wed, 25 Feb 2004 07:49:12 +0000 (07:49 +0000)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@824 f882894a-f735-0410-b71e-b25c423dba1c

configure.in
plugins/check_ping.c

index 5dc04f94a51a79f31da2f3e3e23ed560855eff61..3f909295d5b320cb95e01f1d10390fc83e892a78 100644 (file)
@@ -871,6 +871,7 @@ AC_ARG_WITH(ping_command,
 
 AC_MSG_CHECKING(for ICMP ping syntax)
 ac_cv_ping_packets_first=no
+ac_cv_ping_has_timeout=no
 if test -n "$with_ping_command"
 then
        AC_MSG_RESULT([(command-line) $with_ping_command])
@@ -887,6 +888,14 @@ then
        ac_cv_ping_packets_first=yes
        AC_MSG_RESULT([$with_ping_command])
 
+elif $PATH_TO_PING -n -U -w 10 -c 1 127.0.0.1 2>/dev/null | \
+       egrep -i "^round-trip|^rtt" >/dev/null
+then
+        with_ping_command="$PATH_TO_PING -n -U -w %d -c %d %s"
+       ac_cv_ping_packets_first=yes
+  ac_cv_ping_has_timeout=yes
+       AC_MSG_RESULT([$with_ping_command])
+
 elif $PATH_TO_PING -n -U -c 1 127.0.0.1 2>/dev/null | \
        egrep -i "^round-trip|^rtt" >/dev/null
 then
@@ -952,6 +961,12 @@ then
                [Define if packet count must precede host])
 fi
 
+if test "x$ac_cv_ping_has_timeout" != "xno"
+then
+       AC_DEFINE(PING_HAS_TIMEOUT,1,
+               [Define if ping has its own timeout option that should be set])
+fi
+
 AC_ARG_WITH(ping6_command,
        ACX_HELP_STRING([--with-ping6-command=SYNTAX],
                [sets syntax for ICMPv6 ping]),
index 1d34656cf6a79145f5d15d7317ac90c96cc919d4..26810f32eec15db1d35f1d39d3615f6588e1588a 100644 (file)
@@ -66,6 +66,7 @@ int
 main (int argc, char **argv)
 {
        char *cmd = NULL;
+       char *rawcmd = NULL;
        int result = STATE_UNKNOWN;
        int this_result = STATE_UNKNOWN;
        int i;
@@ -90,27 +91,26 @@ main (int argc, char **argv)
        alarm (timeout_interval);
 
        for (i = 0 ; i < n_addresses ; i++) {
+               
+#ifdef PING6_COMMAND
+               if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
+                       rawcmd = strdup(PING6_COMMAND);
+               else
+                       rawcmd = strdup(PING_COMMAND);
+#else
+               rawcmd = strdup(PING_COMMAND);
+#endif
 
                /* does the host address of number of packets argument come first? */
-#ifdef PING6_COMMAND
-# ifdef PING_PACKETS_FIRST
-       if (is_inet6_addr(addresses[i]) && address_family != AF_INET)
-               asprintf (&cmd, PING6_COMMAND, max_packets, addresses[i]);
-       else
-               asprintf (&cmd, PING_COMMAND, max_packets, addresses[i]);
+#ifdef PING_PACKETS_FIRST
+# ifdef PING_HAS_TIMEOUT
+               asprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]);
 # else
-       if (is_inet6_addr(addresses[i]) && address_family != AF_INET) 
-               asprintf (&cmd, PING6_COMMAND, addresses[i], max_packets);
-       else
-               asprintf (&cmd, PING_COMMAND, addresses[i], max_packets);
+               asprintf (&cmd, rawcmd, max_packets, addresses[i]);
 # endif
-#else /* USE_IPV6 */
-# ifdef PING_PACKETS_FIRST
-               asprintf (&cmd, PING_COMMAND, max_packets, addresses[i]);
-# else
-               asprintf (&cmd, PING_COMMAND, addresses[i], max_packets);
-# endif
-#endif /* USE_IPV6 */
+#else
+               asprintf (&cmd, rawcmd, addresses[i], max_packets);
+#endif
 
                if (verbose)
                        printf ("%s ==> ", cmd);
@@ -150,7 +150,8 @@ main (int argc, char **argv)
                        printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl);
 
                result = max_state (result, this_result);
-
+               free (rawcmd);
+               free (cmd);
        }
 
        return result;