[monitoring-plugins] check_icmp: Correctly set address_family on lookup

Jacob Hansen git at monitoring-plugins.org
Tue Feb 19 15:50:16 CET 2019


 Module: monitoring-plugins
 Branch: master
 Commit: 0882b4201bfa0608b90448c4866b571a20e1fd66
 Author: Jacob Hansen <jhansen at op5.com>
   Date: Thu Dec  6 15:33:34 2018 +0000
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=0882b42

check_icmp: Correctly set address_family on lookup

If a hostname is supplied instead of an IP address, the automatic
address family detection would fail to correctly set the IP protocol
version (it would always be IPv6).

We now supply AF_UNSPEC to getaddrinfo, which should then return the
correct address family in the result.

Signed-off-by: Jacob Hansen <jhansen at op5.com>

---

 plugins-root/check_icmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 749e2d4..1a2a177 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -1362,13 +1362,14 @@ add_target(char *arg)
 	else {
 		errno = 0;
 		memset(&hints, 0, sizeof(hints));
-		hints.ai_family = address_family == AF_INET ? PF_INET : PF_INET6;
+		hints.ai_family = AF_UNSPEC;
 		hints.ai_socktype = SOCK_RAW;
 		if((error = getaddrinfo(arg, NULL, &hints, &res)) != 0) {
 			errno = 0;
 			crash("Failed to resolve %s: %s", arg, gai_strerror(error));
 			return -1;
 		}
+		address_family = res->ai_family;
 	}
 
 	/* possibly add all the IP's as targets */



More information about the Commits mailing list