summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Hansen <jhansen@op5.com>2018-12-06 15:33:34 (GMT)
committerJacob Hansen <jhansen@op5.com>2018-12-07 09:51:21 (GMT)
commit0882b4201bfa0608b90448c4866b571a20e1fd66 (patch)
tree1de258e676765c7b895c7e73b4aebc526ca09511
parente5eccb663efb40c010ed608f5900b341592cfa68 (diff)
downloadmonitoring-plugins-0882b42.tar.gz
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@op5.com>
-rw-r--r--plugins-root/check_icmp.c3
1 files changed, 2 insertions, 1 deletions
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)
1362 else { 1362 else {
1363 errno = 0; 1363 errno = 0;
1364 memset(&hints, 0, sizeof(hints)); 1364 memset(&hints, 0, sizeof(hints));
1365 hints.ai_family = address_family == AF_INET ? PF_INET : PF_INET6; 1365 hints.ai_family = AF_UNSPEC;
1366 hints.ai_socktype = SOCK_RAW; 1366 hints.ai_socktype = SOCK_RAW;
1367 if((error = getaddrinfo(arg, NULL, &hints, &res)) != 0) { 1367 if((error = getaddrinfo(arg, NULL, &hints, &res)) != 0) {
1368 errno = 0; 1368 errno = 0;
1369 crash("Failed to resolve %s: %s", arg, gai_strerror(error)); 1369 crash("Failed to resolve %s: %s", arg, gai_strerror(error));
1370 return -1; 1370 return -1;
1371 } 1371 }
1372 address_family = res->ai_family;
1372 } 1373 }
1373 1374
1374 /* possibly add all the IP's as targets */ 1375 /* possibly add all the IP's as targets */