mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-06-08 16:26:23 -04:00
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.
This commit is contained in:
parent
35d957fa5c
commit
4acba2b3ec
1 changed files with 22 additions and 11 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue