diff options
author | Jacob Hansen <jhansen@op5.com> | 2018-12-10 14:00:43 +0000 |
---|---|---|
committer | Jacob Hansen <jhansen@op5.com> | 2018-12-10 14:39:13 +0000 |
commit | 4a4ef0d6898cd1590561cd7685d1b8b02b757823 (patch) | |
tree | 445d965d69651ebbf10c937a9107a937874ff38d | |
parent | ca6efcd02b203e9e07b869af050c1b9849e04608 (diff) | |
download | monitoring-plugins-4a4ef0d6898cd1590561cd7685d1b8b02b757823.tar.gz |
check_icmp: Do not overwrite -4,-6 on lookup
In case we needed to do a lookup, we previously overwrote the
address_family to IPv6, even if we supplied -4 as a cmd line argument.
This commit should ensure the cmd line argument is always followed.
Signed-off-by: Jacob Hansen <jhansen@op5.com>
-rw-r--r-- | plugins-root/check_icmp.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 98891f02..e45fdf60 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1336,7 +1336,7 @@ add_target(char *arg) switch (address_family) { case -1: - // -4 and -6 are not specified on cmdline + /* -4 and -6 are not specified on cmdline */ address_family = AF_INET; sin = (struct sockaddr_in *)&ip; result = inet_pton(address_family, arg, &sin->sin_addr); @@ -1347,6 +1347,10 @@ add_target(char *arg) result = inet_pton(address_family, arg, &sin6->sin6_addr); } #endif + /* If we don't find any valid addresses, we still don't know the address_family */ + if ( result != 1) { + address_family = -1; + } break; case AF_INET: sin = (struct sockaddr_in *)&ip; @@ -1367,7 +1371,11 @@ add_target(char *arg) else { errno = 0; memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; + if (address_family == -1) { + hints.ai_family = AF_UNSPEC; + } else { + hints.ai_family = address_family == AF_INET ? PF_INET : PF_INET6; + } hints.ai_socktype = SOCK_RAW; if((error = getaddrinfo(arg, NULL, &hints, &res)) != 0) { errno = 0; |