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 /plugins-root/check_icmp.c | |
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>
Diffstat (limited to 'plugins-root/check_icmp.c')
-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) | |||
1336 | 1336 | ||
1337 | switch (address_family) { | 1337 | switch (address_family) { |
1338 | case -1: | 1338 | case -1: |
1339 | // -4 and -6 are not specified on cmdline | 1339 | /* -4 and -6 are not specified on cmdline */ |
1340 | address_family = AF_INET; | 1340 | address_family = AF_INET; |
1341 | sin = (struct sockaddr_in *)&ip; | 1341 | sin = (struct sockaddr_in *)&ip; |
1342 | result = inet_pton(address_family, arg, &sin->sin_addr); | 1342 | result = inet_pton(address_family, arg, &sin->sin_addr); |
@@ -1347,6 +1347,10 @@ add_target(char *arg) | |||
1347 | result = inet_pton(address_family, arg, &sin6->sin6_addr); | 1347 | result = inet_pton(address_family, arg, &sin6->sin6_addr); |
1348 | } | 1348 | } |
1349 | #endif | 1349 | #endif |
1350 | /* If we don't find any valid addresses, we still don't know the address_family */ | ||
1351 | if ( result != 1) { | ||
1352 | address_family = -1; | ||
1353 | } | ||
1350 | break; | 1354 | break; |
1351 | case AF_INET: | 1355 | case AF_INET: |
1352 | sin = (struct sockaddr_in *)&ip; | 1356 | sin = (struct sockaddr_in *)&ip; |
@@ -1367,7 +1371,11 @@ add_target(char *arg) | |||
1367 | else { | 1371 | else { |
1368 | errno = 0; | 1372 | errno = 0; |
1369 | memset(&hints, 0, sizeof(hints)); | 1373 | memset(&hints, 0, sizeof(hints)); |
1370 | hints.ai_family = AF_UNSPEC; | 1374 | if (address_family == -1) { |
1375 | hints.ai_family = AF_UNSPEC; | ||
1376 | } else { | ||
1377 | hints.ai_family = address_family == AF_INET ? PF_INET : PF_INET6; | ||
1378 | } | ||
1371 | hints.ai_socktype = SOCK_RAW; | 1379 | hints.ai_socktype = SOCK_RAW; |
1372 | if((error = getaddrinfo(arg, NULL, &hints, &res)) != 0) { | 1380 | if((error = getaddrinfo(arg, NULL, &hints, &res)) != 0) { |
1373 | errno = 0; | 1381 | errno = 0; |