Erik Auerswald [Sat, 17 Feb 2024 16:34:57 +0000 (17:34 +0100)]
use function stats_reset_interval()
Git commit bb8d71ef27f673f25c7e1648ea982c27bb61ac0d from 2020 among many
other things introduced the function stats_reset_interval() to reset the
*_i interval (or split) host statistics, but did not use it. This commit
replaces the open coded reset of interval stats inside print_host_splits()
and print_netdata() with calling stats_reset_interval().
Erik Auerswald [Sat, 17 Feb 2024 16:21:32 +0000 (17:21 +0100)]
typo fixes pertaining to ICMP for IPv6 sockets
As mentioned in issue #300, error messages pertaining to
socket creation may not be printed. But they should be
corrected anyway, just as the comments. Having correct
error messages also makes a fix for issue #300 more
obvious, because the messages itself would not change.
Erik Auerswald [Wed, 7 Feb 2024 18:36:48 +0000 (19:36 +0100)]
Decouple -a/-u effects from -c
As described in issue #295, the option combinations "-c N -u"
and "-c N -a" inadvertently have the same effect as "-c N -q".
Prevent this by first acting on -c, which includes disabling
either -a or -u, if -c is given, before acting on -a/-u.
Erik Auerswald [Wed, 7 Feb 2024 18:31:42 +0000 (19:31 +0100)]
Move description of -i MSEC to probing options
The -i MSEC, --interval=MSEC option does not directly affect
the output format, but rather the probe generation, i.e., the
minimum time between probes. Thus it is more fitting to list
it under "probing options" than under "output options".
Erik Auerswald [Tue, 6 Feb 2024 20:55:09 +0000 (21:55 +0100)]
Test ping to "all IPv6 nodes" multicast address
Any Echo Response packet uses a different source address than
used for the target, because it is not allowed to use a multicast
address as source. This results in extra output in a specific
format on standard error.
This should work, because IPv6 requires multicast support, and
every IPv6 node is supposed to join the "all nodes" multicast
group, including the node the test runs on. It at least works
on my Ubuntu 20.04 LTS system.
Erik Auerswald [Tue, 6 Feb 2024 20:52:31 +0000 (21:52 +0100)]
Test edge cases of -f and -g
* -f with non-existing file
* -f with input file containing comment and empty line
* -g with non-numeric address in "CIDR" format
* -g with one non-numeric address in start resp. end position
* -g with one IPv6 address in start resp. end position
Erik Auerswald [Tue, 9 Jan 2024 11:40:46 +0000 (12:40 +0100)]
Defensive coding: guard against a division by zero
In the function print_per_system_stats(), if packets have been
lost, the number of sent packets is checked to be positive before
dividing by it. If no packets have been lost, this is not checked.
Either the existing check is not needed, or both code paths need
the check.
The function print_per_system_splits() is quite similar to
print_per_system_stats(), and has the equivalent guards against a
division by zero in both code paths, not just one of them.
In the spirit of defensive coding, I think it is better to be safe
and add the missing guard against a division by zero.
Erik Auerswald [Mon, 8 Jan 2024 08:35:49 +0000 (09:35 +0100)]
Test examples from man page
The man page gives two examples combining -C and -q, but
these combinations are not yet tested. Add tests to help
ensure the documented examples continue to work.
Erik Auerswald [Mon, 8 Jan 2024 08:15:04 +0000 (09:15 +0100)]
Add longer test for -Q SECS
The statistics printed every SECS seconds show the results
since the the last report, not since the beginning. Also,
every report starts with a timestamp.
Erik Auerswald [Mon, 8 Jan 2024 08:12:09 +0000 (09:12 +0100)]
Test edge case behavior of "fping -g"
* wrong number or kind of arguments fails and prints usage;
* an empty range silently pings nothing and fping returns 1;
* a too large range fails with an error message;
* a zero CIDR prefix length fails with an error message.
Khem Raj [Mon, 29 Aug 2022 22:41:51 +0000 (15:41 -0700)]
fping: Initialize msghdr struct in a portable way
Initializing the structure assuming glibc layout results in
compile errors on musl, therefore do partial intialization and then
assigning the members individually.
Erik Auerswald [Sun, 30 Jan 2022 12:30:05 +0000 (13:30 +0100)]
Improve -Q documentation
The `-Q, --squiet=SECS` option does not replace the summary
statistics of `-q, --quiets`, but adds interval summary
statistics every SECS seconds to the output.
Erik Auerswald [Sun, 30 Jan 2022 12:10:29 +0000 (13:10 +0100)]
Improve -d and -n documentation
* Adjust `fping.pod` entries for `-d, --rdns` and `-n, --name`:
* The code performs reverse DNS lookups on the given targets,
not on source addresses from ICMP Echo Responses or ICMP
error messages. Adjust the `-d` description to reflect this.
* The sentence describing `-n` seems incomplete, so provide a
completion in similar spirit to `-d`.
* Add `-d, --rdns` to `-h, --help` output since `-d` and `-n` are
no longer equivalent.
aafbsd [Sat, 7 Aug 2021 09:51:04 +0000 (11:51 +0200)]
Update fping.c
getnameinfo() was not called properly for IPv4 (didn't check v6).
Additionally, one might also want to check the result code, call gai_strerror() and inform the user if s.th. goes wrong
fping: retain privileges until after privileged setsockopt
On Linux, one needs privileges to setsockopt(SO_BINDTODEVICE), and the
current code would drop setuid root privileges too soon.
Temporarily drop privileges instead, and raise them back to issue the
privileged setsockopt(). Once we know we won't need to do any further
privileged setsockopt(), permanently drop privileges.
For now, assume SO_BINDTODEVICE is the only setsockopt that needs this.
Dirk Meyer [Thu, 20 Aug 2020 06:13:42 +0000 (08:13 +0200)]
- fix regression introduced in fping 4.3
bind to source only when option was set.
this allows to work in jails and lxc with custom IPs.
this allows IPv4 only and IPv6 only hosts