Code

Don't use the plain char type for data buffers
[nagiosplug.git] / plugins-root / check_icmp.c
index ff6c73b3e3ebbfef2b2238ba59c3e076607ea03d..ecf3d08bd139dd0505eee5d85ad9d6bd80a63712 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";
 
@@ -74,6 +70,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #include <netinet/ip_icmp.h>
 #include <arpa/inet.h>
 #include <signal.h>
+#include <float.h>
 
 
 /** sometimes undefined system macros (quite a few, actually) **/
@@ -187,14 +184,14 @@ static u_int get_timevar(const char *);
 static u_int get_timevaldiff(struct timeval *, struct timeval *);
 static in_addr_t get_ip_address(const char *);
 static int wait_for_reply(int, u_int);
-static int recvfrom_wto(int, char *, unsigned int, struct sockaddr *, u_int *);
+static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *);
 static int send_icmp_ping(int, struct rta_host *);
 static int get_threshold(char *str, threshold *th);
 static void run_checks(void);
 static void set_source_ip(char *);
 static int add_target(char *);
 static int add_target_ip(char *, struct in_addr *);
-static int handle_random_icmp(char *, struct sockaddr_in *);
+static int handle_random_icmp(unsigned char *, struct sockaddr_in *);
 static unsigned short icmp_checksum(unsigned short *, int);
 static void finish(int);
 static void crash(const char *, ...);
@@ -303,7 +300,7 @@ get_icmp_error_msg(unsigned char icmp_type, unsigned char icmp_code)
 }
 
 static int
-handle_random_icmp(char *packet, struct sockaddr_in *addr)
+handle_random_icmp(unsigned char *packet, struct sockaddr_in *addr)
 {
        struct icmp p, sent_icmp;
        struct rta_host *host = NULL;
@@ -516,7 +513,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 ();
@@ -697,7 +694,7 @@ static int
 wait_for_reply(int sock, u_int t)
 {
        int n, hlen;
-       static char buf[4096];
+       static unsigned char buf[4096];
        struct sockaddr_in resp_addr;
        struct ip *ip;
        struct icmp icp;
@@ -817,7 +814,7 @@ static int
 send_icmp_ping(int sock, struct rta_host *host)
 {
        static union {
-               char *buf; /* re-use so we prevent leaks */
+               void *buf; /* re-use so we prevent leaks */
                struct icmp *icp;
                u_short *cksum_in;
        } packet = { NULL };
@@ -870,7 +867,7 @@ send_icmp_ping(int sock, struct rta_host *host)
 }
 
 static int
-recvfrom_wto(int sock, char *buf, unsigned int len, struct sockaddr *saddr,
+recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr,
                         u_int *timo)
 {
        u_int slen;
@@ -1272,7 +1269,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);
@@ -1288,10 +1285,10 @@ print_help(void)
   printf ("    %s\n", _("specify a target"));
   printf (" %s\n", "-w");
   printf ("    %s", _("warning threshold (currently "));
-  printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000 , warn.pl / 1000);
+  printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl);
   printf (" %s\n", "-c");
   printf ("    %s", _("critical threshold (currently "));
-  printf ("%0.3fms,%u%%)\n", (float)crit.rta, crit.pl);
+  printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl);
   printf (" %s\n", "-s");
   printf ("    %s\n", _("specify a source IP address or device name"));
   printf (" %s\n", "-n");
@@ -1313,7 +1310,7 @@ print_help(void)
   printf ("    %s",_("timeout value (seconds, currently  "));
   printf ("%u)\n", timeout);
   printf (" %s\n", "-b");
-  printf ("    %s\n", _("Number of icmp data bytes to send")); 
+  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"));