diff options
-rw-r--r-- | plugins-root/check_icmp.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 1f87b75f..c3be2efd 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -1,39 +1,39 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_icmp plugin | 3 | * Monitoring check_icmp plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2005-2008 Monitoring Plugins Development Team | 6 | * Copyright (c) 2005-2008 Monitoring Plugins Development Team |
7 | * Original Author : Andreas Ericsson <ae@op5.se> | 7 | * Original Author : Andreas Ericsson <ae@op5.se> |
8 | * | 8 | * |
9 | * Description: | 9 | * Description: |
10 | * | 10 | * |
11 | * This file contains the check_icmp plugin | 11 | * This file contains the check_icmp plugin |
12 | * | 12 | * |
13 | * Relevant RFC's: 792 (ICMP), 791 (IP) | 13 | * Relevant RFC's: 792 (ICMP), 791 (IP) |
14 | * | 14 | * |
15 | * This program was modeled somewhat after the check_icmp program, | 15 | * This program was modeled somewhat after the check_icmp program, |
16 | * which was in turn a hack of fping (www.fping.org) but has been | 16 | * which was in turn a hack of fping (www.fping.org) but has been |
17 | * completely rewritten since to generate higher precision rta values, | 17 | * completely rewritten since to generate higher precision rta values, |
18 | * and support several different modes as well as setting ttl to control. | 18 | * and support several different modes as well as setting ttl to control. |
19 | * redundant routes. The only remainders of fping is currently a few | 19 | * redundant routes. The only remainders of fping is currently a few |
20 | * function names. | 20 | * function names. |
21 | * | 21 | * |
22 | * | 22 | * |
23 | * This program is free software: you can redistribute it and/or modify | 23 | * This program is free software: you can redistribute it and/or modify |
24 | * it under the terms of the GNU General Public License as published by | 24 | * it under the terms of the GNU General Public License as published by |
25 | * the Free Software Foundation, either version 3 of the License, or | 25 | * the Free Software Foundation, either version 3 of the License, or |
26 | * (at your option) any later version. | 26 | * (at your option) any later version. |
27 | * | 27 | * |
28 | * This program is distributed in the hope that it will be useful, | 28 | * This program is distributed in the hope that it will be useful, |
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31 | * GNU General Public License for more details. | 31 | * GNU General Public License for more details. |
32 | * | 32 | * |
33 | * You should have received a copy of the GNU General Public License | 33 | * You should have received a copy of the GNU General Public License |
34 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 34 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | * | 35 | * |
36 | * | 36 | * |
37 | *****************************************************************************/ | 37 | *****************************************************************************/ |
38 | 38 | ||
39 | /* progname may change */ | 39 | /* progname may change */ |
@@ -55,6 +55,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
55 | #include <errno.h> | 55 | #include <errno.h> |
56 | #include <signal.h> | 56 | #include <signal.h> |
57 | #include <ctype.h> | 57 | #include <ctype.h> |
58 | #include <float.h> | ||
58 | #include <net/if.h> | 59 | #include <net/if.h> |
59 | #include <netinet/in_systm.h> | 60 | #include <netinet/in_systm.h> |
60 | #include <netinet/in.h> | 61 | #include <netinet/in.h> |
@@ -95,10 +96,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
95 | # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 | 96 | # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 |
96 | #endif | 97 | #endif |
97 | 98 | ||
98 | #ifndef DBL_MAX | ||
99 | # define DBL_MAX 9.9999999999e999 | ||
100 | #endif | ||
101 | |||
102 | typedef unsigned short range_t; /* type for get_range() -- unimplemented */ | 99 | typedef unsigned short range_t; /* type for get_range() -- unimplemented */ |
103 | 100 | ||
104 | typedef struct rta_host { | 101 | typedef struct rta_host { |
@@ -1224,7 +1221,7 @@ finish(int sig) | |||
1224 | host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, | 1221 | host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, |
1225 | (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl, | 1222 | (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl, |
1226 | (targets > 1) ? host->name : "", (float)host->rtmax / 1000, | 1223 | (targets > 1) ? host->name : "", (float)host->rtmax / 1000, |
1227 | (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0); | 1224 | (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); |
1228 | 1225 | ||
1229 | host = host->next; | 1226 | host = host->next; |
1230 | } | 1227 | } |
@@ -1327,7 +1324,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in) | |||
1327 | memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, sizeof host_sin6->sin6_addr.s6_addr); | 1324 | memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, sizeof host_sin6->sin6_addr.s6_addr); |
1328 | } | 1325 | } |
1329 | 1326 | ||
1330 | host->rtmin = DBL_MAX; | 1327 | host->rtmin = INFINITY; |
1331 | 1328 | ||
1332 | if(!list) list = cursor = host; | 1329 | if(!list) list = cursor = host; |
1333 | else cursor->next = host; | 1330 | else cursor->next = host; |
@@ -1342,7 +1339,7 @@ add_target_ip(char *arg, struct sockaddr_storage *in) | |||
1342 | static int | 1339 | static int |
1343 | add_target(char *arg) | 1340 | add_target(char *arg) |
1344 | { | 1341 | { |
1345 | int error, result; | 1342 | int error, result = -1; |
1346 | struct sockaddr_storage ip; | 1343 | struct sockaddr_storage ip; |
1347 | struct addrinfo hints, *res, *p; | 1344 | struct addrinfo hints, *res, *p; |
1348 | struct sockaddr_in *sin; | 1345 | struct sockaddr_in *sin; |
@@ -1433,20 +1430,21 @@ set_source_ip(char *arg) | |||
1433 | static in_addr_t | 1430 | static in_addr_t |
1434 | get_ip_address(const char *ifname) | 1431 | get_ip_address(const char *ifname) |
1435 | { | 1432 | { |
1433 | // TODO: Rewrite this so the function return an error and we exit somewhere else | ||
1434 | struct sockaddr_in ip; | ||
1436 | #if defined(SIOCGIFADDR) | 1435 | #if defined(SIOCGIFADDR) |
1437 | struct ifreq ifr; | 1436 | struct ifreq ifr; |
1438 | struct sockaddr_in ip; | ||
1439 | 1437 | ||
1440 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); | 1438 | strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); |
1441 | ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; | 1439 | ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; |
1442 | if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1) | 1440 | if(ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1) |
1443 | crash("Cannot determine IP address of interface %s", ifname); | 1441 | crash("Cannot determine IP address of interface %s", ifname); |
1444 | memcpy(&ip, &ifr.ifr_addr, sizeof(ip)); | 1442 | memcpy(&ip, &ifr.ifr_addr, sizeof(ip)); |
1445 | return ip.sin_addr.s_addr; | ||
1446 | #else | 1443 | #else |
1447 | errno = 0; | 1444 | errno = 0; |
1448 | crash("Cannot get interface IP address on this platform."); | 1445 | crash("Cannot get interface IP address on this platform."); |
1449 | #endif | 1446 | #endif |
1447 | return ip.sin_addr.s_addr; | ||
1450 | } | 1448 | } |
1451 | 1449 | ||
1452 | /* | 1450 | /* |