diff options
Diffstat (limited to 'plugins-root/check_icmp.c')
| -rw-r--r-- | plugins-root/check_icmp.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index d46d2ccc..35cae3ed 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
| @@ -54,6 +54,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 54 | #endif | 54 | #endif |
| 55 | 55 | ||
| 56 | #include <sys/time.h> | 56 | #include <sys/time.h> |
| 57 | #if defined(SIOCGIFADDR) | ||
| 58 | #include <sys/ioctl.h> | ||
| 59 | #endif /* SIOCGIFADDR */ | ||
| 57 | #include <errno.h> | 60 | #include <errno.h> |
| 58 | #include <signal.h> | 61 | #include <signal.h> |
| 59 | #include <ctype.h> | 62 | #include <ctype.h> |
| @@ -146,7 +149,7 @@ static get_timevar_wrapper get_timevar(const char *str); | |||
| 146 | static time_t get_timevaldiff(struct timeval earlier, struct timeval later); | 149 | static time_t get_timevaldiff(struct timeval earlier, struct timeval later); |
| 147 | static time_t get_timevaldiff_to_now(struct timeval earlier); | 150 | static time_t get_timevaldiff_to_now(struct timeval earlier); |
| 148 | 151 | ||
| 149 | static in_addr_t get_ip_address(const char *ifname); | 152 | static in_addr_t get_ip_address(const char *ifname, const int icmp_sock); |
| 150 | static void set_source_ip(char *arg, int icmp_sock, sa_family_t addr_family); | 153 | static void set_source_ip(char *arg, int icmp_sock, sa_family_t addr_family); |
| 151 | 154 | ||
| 152 | /* Receiving data */ | 155 | /* Receiving data */ |
| @@ -1769,7 +1772,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil | |||
| 1769 | memset(&src, 0, sizeof(src)); | 1772 | memset(&src, 0, sizeof(src)); |
| 1770 | src.sin_family = addr_family; | 1773 | src.sin_family = addr_family; |
| 1771 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) { | 1774 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) { |
| 1772 | src.sin_addr.s_addr = get_ip_address(arg); | 1775 | src.sin_addr.s_addr = get_ip_address(arg, icmp_sock); |
| 1773 | } | 1776 | } |
| 1774 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) { | 1777 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) { |
| 1775 | crash("Cannot bind to IP address %s", arg); | 1778 | crash("Cannot bind to IP address %s", arg); |
| @@ -1777,7 +1780,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil | |||
| 1777 | } | 1780 | } |
| 1778 | 1781 | ||
| 1779 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ | 1782 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ |
| 1780 | static in_addr_t get_ip_address(const char *ifname) { | 1783 | static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { |
| 1781 | // TODO: Rewrite this so the function return an error and we exit somewhere else | 1784 | // TODO: Rewrite this so the function return an error and we exit somewhere else |
| 1782 | struct sockaddr_in ip_address; | 1785 | struct sockaddr_in ip_address; |
| 1783 | ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy | 1786 | ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy |
| @@ -1792,7 +1795,7 @@ static in_addr_t get_ip_address(const char *ifname) { | |||
| 1792 | crash("Cannot determine IP address of interface %s", ifname); | 1795 | crash("Cannot determine IP address of interface %s", ifname); |
| 1793 | } | 1796 | } |
| 1794 | 1797 | ||
| 1795 | memcpy(&ip, &ifr.ifr_addr, sizeof(ip)); | 1798 | memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); |
| 1796 | #else | 1799 | #else |
| 1797 | (void)ifname; | 1800 | (void)ifname; |
| 1798 | errno = 0; | 1801 | errno = 0; |
