1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
From 413af1955538b06803458c628099f1ba9da1966b Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 4 Nov 2022 16:51:32 +0100
Subject: [PATCH 1/5] Remove trailing whitespaces
---
plugins-root/check_icmp.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index f8f153512..abd88c4e7 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1,39 +1,39 @@
/*****************************************************************************
-*
+*
* Monitoring check_icmp plugin
-*
+*
* License: GPL
* Copyright (c) 2005-2008 Monitoring Plugins Development Team
* Original Author : Andreas Ericsson <ae@op5.se>
-*
+*
* Description:
-*
+*
* This file contains the check_icmp plugin
-*
+*
* Relevant RFC's: 792 (ICMP), 791 (IP)
-*
+*
* This program was modeled somewhat after the check_icmp program,
* which was in turn a hack of fping (www.fping.org) but has been
* completely rewritten since to generate higher precision rta values,
* and support several different modes as well as setting ttl to control.
* redundant routes. The only remainders of fping is currently a few
* function names.
-*
-*
+*
+*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-*
+*
+*
*****************************************************************************/
/* progname may change */
From 7d074091dba8c1d4081971bf62e694d0b1a03d41 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 4 Nov 2022 16:53:57 +0100
Subject: [PATCH 2/5] Remove hardcoded DBL_MAX definition
---
plugins-root/check_icmp.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index abd88c4e7..0d10d22db 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -95,10 +95,6 @@ const char *email = "devel@monitoring-plugins.org";
# 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 */
typedef struct rta_host {
From 9a73a94258689cd9337fe7a7937fe85e4670aaeb Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 4 Nov 2022 17:08:36 +0100
Subject: [PATCH 3/5] Replace DBL_MAX with INFITY to check if value was set
---
plugins-root/check_icmp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 0d10d22db..7f3c4b5ba 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -55,6 +55,7 @@ const char *email = "devel@monitoring-plugins.org";
#include <errno.h>
#include <signal.h>
#include <ctype.h>
+#include <float.h>
#include <net/if.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
@@ -1220,7 +1221,7 @@ finish(int sig)
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 : "", (float)host->rtmax / 1000,
- (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0);
+ (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0);
host = host->next;
}
@@ -1323,7 +1324,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in)
memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, sizeof host_sin6->sin6_addr.s6_addr);
}
- host->rtmin = DBL_MAX;
+ host->rtmin = INFINITY;
if(!list) list = cursor = host;
else cursor->next = host;
From d3a4bad51d72a3c5bcc06ceb5e0a823dcc24bf49 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 19 Feb 2023 14:31:21 +0100
Subject: [PATCH 4/5] check_icmp: Fix compiler warning
This fixes a compiler warning with no real world impact.
The compiler complains about a missing return, which is correct, but
in that scenario the program would crash anyways, so this has no impact.
---
plugins-root/check_icmp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 7f3c4b5ba..317cd5357 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1430,20 +1430,21 @@ set_source_ip(char *arg)
static in_addr_t
get_ip_address(const char *ifname)
{
+ // TODO: Rewrite this so the function return an error and we exit somewhere else
+ struct sockaddr_in ip;
#if defined(SIOCGIFADDR)
struct ifreq ifr;
- struct sockaddr_in ip;
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1)
crash("Cannot determine IP address of interface %s", ifname);
memcpy(&ip, &ifr.ifr_addr, sizeof(ip));
- return ip.sin_addr.s_addr;
#else
errno = 0;
crash("Cannot get interface IP address on this platform.");
#endif
+ return ip.sin_addr.s_addr;
}
/*
From 423284edfa980fc3fdb51ab20af96685a988ba97 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 19 Feb 2023 14:34:29 +0100
Subject: [PATCH 5/5] check_icmp: Fix compiler warning
This fixes a compiler warning which complains about an uninitialized
value for a variable which is then returned.
This had no real world impact, since the program would crash in the
branch where result is not set.
The variable is initialized to "-1" which would be the error for
inet_pton.
---
plugins-root/check_icmp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 317cd5357..e59e92d33 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1339,7 +1339,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in)
static int
add_target(char *arg)
{
- int error, result;
+ int error, result = -1;
struct sockaddr_storage ip;
struct addrinfo hints, *res, *p;
struct sockaddr_in *sin;
|