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:
William 2025-03-27 11:20:36 +10:00
parent 35d957fa5c
commit 4acba2b3ec

View file

@ -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);