diff options
author | Jacob Hansen <jhansen@op5.com> | 2018-12-06 15:33:34 +0000 |
---|---|---|
committer | Jacob Hansen <jhansen@op5.com> | 2018-12-07 09:51:21 +0000 |
commit | 0882b4201bfa0608b90448c4866b571a20e1fd66 (patch) | |
tree | 1de258e676765c7b895c7e73b4aebc526ca09511 /plugins-root/check_icmp.c | |
parent | e5eccb663efb40c010ed608f5900b341592cfa68 (diff) | |
download | monitoring-plugins-0882b4201bfa0608b90448c4866b571a20e1fd66.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>
Diffstat (limited to 'plugins-root/check_icmp.c')
-rw-r--r-- | plugins-root/check_icmp.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 749e2d44..1a2a1772 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 */ |