Code

Removing CVS/SVN tags and replacing with git-based versioning
[nagiosplug.git] / plugins-root / check_icmp.c
index 5fb9c364a56c08892927db3370f026126cb06ac0..bbdfae75a1c81cb44a6a29a53566370252d1963d 100644 (file)
@@ -6,8 +6,6 @@
 * Copyright (c) 2005-2008 Nagios Plugins Development Team
 * Original Author : Andreas Ericsson <ae@op5.se>
 * 
-* Last Modified: $Date$
-* 
 * Description:
 * 
 * This file contains the check_icmp plugin
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
-* $Id$
 * 
 *****************************************************************************/
 
 /* progname may change */
 /* char *progname = "check_icmp"; */
 char *progname;
-const char *revision = "$Revision$";
 const char *copyright = "2005-2008";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
@@ -106,6 +102,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
 #endif
 
+#ifndef DBL_MAX
+# define DBL_MAX 9.9999999999e999
+#endif
 
 typedef unsigned short range_t;  /* type for get_range() -- unimplemented */
 
@@ -120,6 +119,8 @@ typedef struct rta_host {
        unsigned char icmp_type, icmp_code; /* type and code from errors */
        unsigned short flags;        /* control/status flags */
        double rta;                  /* measured RTA */
+       double rtmax;                /* max rtt */
+       double rtmin;                /* min rtt */
        unsigned char pl;            /* measured packet loss */
        struct rta_host *next;       /* linked list */
 } rta_host;
@@ -463,13 +464,13 @@ main(int argc, char **argv)
                        case 'b':
                                size = strtol(optarg,NULL,0);
                                if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) &&
-                                   size <= MAX_PING_DATA + ICMP_MINLEN) {
-                                       icmp_pkt_size = size;
-                                       icmp_data_size = icmp_pkt_size - ICMP_MINLEN;
+                                   size < MAX_PING_DATA) {
+                                       icmp_data_size = size;
+                                       icmp_pkt_size = size + ICMP_MINLEN;
                                } else
-                                       usage_va("ICMP packet size must be between: %d and %d",
+                                       usage_va("ICMP data length must be between: %d and %d",
                                                 sizeof(struct icmp) + sizeof(struct icmp_ping_data),
-                                                MAX_PING_DATA + ICMP_MINLEN);
+                                                MAX_PING_DATA - 1);
 
                                break;
                        case 'i':
@@ -511,7 +512,7 @@ main(int argc, char **argv)
                                set_source_ip(optarg);
                                break;
       case 'V':                 /* version */
-        /*print_revision (progname, revision);*/ /* FIXME: Why? */
+        print_revision (progname, NP_VERSION);
         exit (STATE_OK);
       case 'h':                 /* help */
         print_help ();
@@ -782,11 +783,15 @@ wait_for_reply(int sock, u_int t)
                host->time_waited += tdiff;
                host->icmp_recv++;
                icmp_recv++;
+               if (tdiff > host->rtmax)
+                       host->rtmax = tdiff;
+               if (tdiff < host->rtmin)
+                       host->rtmin = tdiff;
 
                if(debug) {
-                       printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u\n",
+                       printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n",
                                   (float)tdiff / 1000, inet_ntoa(resp_addr.sin_addr),
-                                  ttl, ip->ip_ttl);
+                                  ttl, ip->ip_ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000);
                }
 
                /* if we're in hostcheck mode, exit with limited printouts */
@@ -993,11 +998,12 @@ finish(int sig)
        host = list;
        while(host) {
                if(debug) puts("");
-               printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; ",
+               printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",
                           (targets > 1) ? host->name : "",
                           host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000,
-                          (targets > 1) ? host->name : "",
-                          host->pl, warn.pl, crit.pl);
+                          (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl,
+                          (targets > 1) ? host->name : "", (float)host->rtmax / 1000,
+                          (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0);
 
                host = host->next;
        }
@@ -1074,6 +1080,8 @@ add_target_ip(char *arg, struct in_addr *in)
        host->saddr_in.sin_family = AF_INET;
        host->saddr_in.sin_addr.s_addr = in->s_addr;
 
+       host->rtmin = DBL_MAX;
+
        if(!list) list = cursor = host;
        else cursor->next = host;
 
@@ -1260,7 +1268,7 @@ void
 print_help(void)
 {
 
-  /*print_revision (progname, revision);*/ /* FIXME: Why? */
+  /*print_revision (progname);*/ /* FIXME: Why? */
 
   printf ("Copyright (c) 2005 Andreas Ericsson <ae@op5.se>\n");
   printf (COPYRIGHT, copyright, email);
@@ -1296,13 +1304,13 @@ print_help(void)
   printf ("\n");
   printf (" %s\n", "-l");
   printf ("    %s", _("TTL on outgoing packets (currently "));
-  printf ("%u)", ttl);
+  printf ("%u)\n", ttl);
   printf (" %s\n", "-t");
   printf ("    %s",_("timeout value (seconds, currently  "));
   printf ("%u)\n", timeout);
   printf (" %s\n", "-b");
-  printf ("    %s", _("icmp packet size (bytes, currently "));
-  printf ("%u)\n", icmp_pkt_size);
+  printf ("    %s\n", _("Number of icmp data bytes to send"));
+  printf ("    %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN);
   printf (" %s\n", "-v");
   printf ("    %s\n", _("verbose"));