From 0882b4201bfa0608b90448c4866b571a20e1fd66 Mon Sep 17 00:00:00 2001 From: Jacob Hansen Date: Thu, 6 Dec 2018 15:33:34 +0000 Subject: 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 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 */ -- cgit v0.10-9-g596f