[monitoring-plugins] Improve handling of -4/-6
William
git at monitoring-plugins.org
Tue May 13 09:10:11 CEST 2025
Module: monitoring-plugins
Branch: master
Commit: 4acba2b3ecef7c1482b3cd25e35773947d80e2c6
Author: William <william at blackhats.net.au>
Date: Thu Mar 27 11:20:36 2025 +1000
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=4acba2b3
Improve handling of -4/-6
If fping is used with a target that has dual stack v4/v6, then due to
the logic during command construction, ipv4 will never be checked as v6
is preferred by fping.
This explicitly flags -4/-6 when it is requested by the user.
---
plugins/check_fping.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index ec7abb67..1c2b7689 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -79,7 +79,29 @@ int main(int argc, char **argv) {
server = strscpy(server, config.server_name);
char *option_string = "";
+ char *fping_prog = NULL;
+
/* compose the command */
+#ifdef PATH_TO_FPING6
+ if (address_family != AF_INET && is_inet6_addr(server)) {
+ fping_prog = strdup(PATH_TO_FPING6);
+ } else {
+ xasprintf(&option_string, "%s-4 ", option_string);
+ fping_prog = strdup(PATH_TO_FPING);
+ }
+#else
+ if (address_family != AF_INET) {
+ // -4 / -6 must be set explicitly as when a host has dual stack
+ // if we don't specify -4 then fping selects ipv6 which can mess
+ // with some checks.
+ xasprintf(&option_string, "%s-6 ", option_string);
+ } else {
+ xasprintf(&option_string, "%s-4 ", option_string);
+ }
+
+ fping_prog = strdup(PATH_TO_FPING);
+#endif
+
if (config.target_timeout) {
xasprintf(&option_string, "%s-t %d ", option_string, config.target_timeout);
}
@@ -99,17 +121,6 @@ int main(int argc, char **argv) {
xasprintf(&option_string, "%s-R ", option_string);
}
- char *fping_prog = NULL;
-#ifdef PATH_TO_FPING6
- if (address_family != AF_INET && is_inet6_addr(server)) {
- fping_prog = strdup(PATH_TO_FPING6);
- } else {
- fping_prog = strdup(PATH_TO_FPING);
- }
-#else
- fping_prog = strdup(PATH_TO_FPING);
-#endif
-
char *command_line = NULL;
xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server);
More information about the Commits
mailing list