Compare commits

..

316 Commits

Author SHA1 Message Date
Raphael 062d6419d6 Merge branch 'develop-eduard' into develop 5 months ago
Erik Auerswald 00d6417104 adjust generator limit to allow an IPv4 /15 6 months ago
Erik Auerswald a1509c1b4d fix off-by-one error in generator limit
This commit does not add tests that verify the exact limit,
because pinging 100000 localhost addresses takes over 15
minutes on my PC.  I have tested this fix manually.
6 months ago
Erik Auerswald 54e6f838c3 also apply generator limit to use with CIDR
As described in GH issue #299, the MAX_GENERATE+1 limit is only
applied when using an address range, not when using CIDR.  This
commit changes this to always honor the generator limit.

* refactor target address generation to use the same new function
  for both range and CIDR notation
* check the limit for addresses to generate in the new function
* document the generator limit in "fping --help" output
* document the generator limit in the fping man page
* test that the address generation limit applies when using CIDR
  notation
6 months ago
Erik Auerswald d0ed64bcc7 align functions add_cidr() and add_range()
* call freeaddrinfo() before checking the prefix length in
  add_cidr()
* add a comment to the generator limit check in add_range()
6 months ago
Erik Auerswald ab20b150b8 ci: skip an unreliable test on macOS
Sometimes, this test fails on macOS, at least on the GitHub CI.
It looks as if the fping process is killed before it produces
the required output.  This test works reliably on GNU/Linux, so
keep it, but skip it when running on macOS.
6 months ago
Erik Auerswald 65f00ff013 ci: test timestamp plausibility
Some changes of fping resulted in some systems reporting
implausible timestamps, see, e.g., GH issue #203.  This
commit adds a simplistic plausability check for timestamps
in Unix time format: they need to be greater or equal to
1000000000 (2001-09-09 03:46:40+02:00).
6 months ago
Erik Auerswald a333f95c9d ci: test empty string argument instead of number
Giving an empty string instead of a number as option argument
was not reliably caught, see GH issue #324 and GH PR #323.
6 months ago
German Service Network 94de79153f Fix incorrect return-value check for a scanf like function 6 months ago
German Service Network 118cdc5cc6 configure.ac check required function strftime 6 months ago
German Service Network b39f5a5cef Extended dokumentation for parameter timestamp-format 6 months ago
German Service Network aa724910b8 Test 05 for --timestamp-format extended 6 months ago
German Service Network 85b92d3d21 New parameter timestamp-format for changing the timestamp output 6 months ago
German Service Network 652d319803 Handling optparse long option 6 months ago
German Service Network 2f2ff0bd2c Change to codeql-action-v2 7 months ago
German Service Network 46793cdf80 Debug with Visual Studio Code 7 months ago
Erik Auerswald 97b7484350 test error when binding to wrong local address
Test "fping -S" with both IPv4 and IPv6 addresses not configured
on local interfaces using addresses reserved for documentation.
Check the fping error message, but accept any system generated
additional information.  This additional information differs
between operation systems.
7 months ago
Erik Auerswald 79e274d4b8 test help output during normal option parsing
The existing test for "fping -h" triggers the special code path
for only one option, either -h or --help, that is handled before
normal option parsing.
7 months ago
Eduard Vlad 11a48b4de1 add nonzero flag instead of random data for accessing it 7 months ago
Erik Auerswald 90ad83fbd0 Print cumulative stats with -Q SECS,cumulative
With -Q SECS, fping emits information for the just finished
interval.  This is good for long-running fping processes where
one would like to get an update on recent results, ignoring
missing responses from older intervals.  This seems appropriate
for use with other software like netdata or smokeping.

But for short(er)-running fping processes, e.g., during a change
window, it may be more interesting to get a status update since
the beginning of the change window, i.e., the start of fping.
Adding a comma followed by the keyword "cumulative" to -Q SECS
(i.e., -Q SECS,cumulative) changes the interim reports to output
the current per system overall statistics, unless -N is used, too.

The new syntax is documented in fping.pod and added to fping -h
output.

Four tests are added:

  1. Characters after SECS are ignored as before.
  2. Unknown keywords are ignored as before.
  2. Adding ",cumulative" changes -Q output.
  3. Adding ",cumulative" also affects the additional -o output.

This addresses issue #243.
8 months ago
dwes 0d08321346 Prepare v5.2 release. 8 months ago
German Service Network bd44c9f016 Removes the unnecessary file 18 8 months ago
German Service Network f71e40ab60 Extended configure.ac with --enable-debug and create debug output cpu time use 9 months ago
German Service Network 5a2a23d2af Update Azure Pipline add macOS pipline job 9 months ago
German Service Network 47c0c3d8de Update Azure Pipline linux test based on github pipline with matching exclude 9 months ago
David Schweikert ab05279782 Fix number of tests 9 months ago
David Schweikert d6d9c653eb Remove flaky test for now.
Remove the 'fping -X 2 --generate 8.8.0.0/29' test, because it
is currently failing on the MacOS runner. Also, I am not sure that
it is a good idea to ping the IPs 8.8.0.1 and 8.8.0.2 and rely on
them being up.
9 months ago
German Service Network 94e98acaaa Check if the variable next_value->ping_ts != 0 in seqmap_add() 9 months ago
Erik Auerswald c3a2f2c7cc always output error message in crash_and_burn()
This aligns crash_and_burn() with errno_crash_and_burn()
and addresses issue #300.
10 months ago
Erik Auerswald 4151976986 improve help output for options -c and -C 10 months ago
Erik Auerswald 266eb16568 use function stats_reset_interval()
Git commit bb8d71ef27 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().
10 months ago
Erik Auerswald c138b08141 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.
10 months ago
Erik Auerswald ae0bc23804 Document that -c N overrides -a or -u 10 months ago
Erik Auerswald 1443614dad 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.
10 months ago
Erik Auerswald c122186f70 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".
10 months ago
Erik Auerswald d312a278d5 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.
11 months ago
Erik Auerswald ef74f642d1 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
11 months ago
Erik Auerswald 32b9a55a98 Test -l together with -Q or -t 11 months ago
Erik Auerswald dcda0cc595 Test that -x, -X, -k require numeric argument 11 months ago
Erik Auerswald c5428391a6 Test that negative numbers are not accepted 11 months ago
Erik Auerswald 8ae2babae0 Fix a comment describing a test 11 months ago
Erik Auerswald 290d944b56 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.
11 months ago
Erik Auerswald e4bae43d66 Update exit status description in man page
With the options -x and -X, fping does not require all hosts to
be reachable for an exit status of 0.

This addresses a comment in issue #99 suggesting such a man page
update.
11 months ago
Erik Auerswald 2a609b856d 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.
12 months ago
Erik Auerswald 3a527fbc86 Add test for option combination -Q SECS -o
The -o option adds outage duration to the periodic reports.
Each report shows the outage since the last report, not since
the beginning.
12 months ago
Erik Auerswald 4753437b17 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.
12 months ago
Erik Auerswald ccc0cdfdd7 Test that -g does not accept IPv6 12 months ago
Erik Auerswald 2fa4f61079 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.
12 months ago
deepkv c8e9632150 Add --fwmark/-k option for Linux 12 months ago
German Service Network a3f4c573bf Change obsolete macro from AC_CANONICAL_SYSTEM to AC_CANONICAL_TARGET 1 year ago
German Service Network 7351afdd89 Move the OS detection to configure.ac script to set the use of clock_realtime 1 year ago
German Service Network 163fcdb1ed Fix deprected github action ubuntu-18.04 to ubuntu-22.04 1 year ago
German Service Network b8e413f5ba Checking obsolete macro AC_PROG_CC_STDC as of autoconf-2.70 1 year ago
German Service Network 88091f7c94 Checking obsolete macro AC_GNU_SOURCE as of autoconf-2.62 1 year ago
darless 8601d1ba70 Remove dockerfile from root 1 year ago
darless1 e20939ebfe Move to contrib folder 1 year ago
darless1 55ad83898f Dockerfile for fping 1 year ago
German Service Network 59f32cefb2 Repair the faulty test 15 1 year ago
ilyam8 a6c314516c remove host from netdata chart titles 1 year ago
ilyam8 16108c4fa7 remove www 1 year ago
ilyam8 d95370cbb0 update netdata link 1 year ago
Vincent OLLIVIER 86dedacbe7 Updating documentation regarding root requirements since for --file parameter 1 year ago
Khem Raj c0fbccb977 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.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
1 year ago
German Service Network f94adaf29e Test for fping: add option to exit immediately once N hosts have been found 1 year ago
German Service Network d45438c723 fping: add option to exit immeditely once N hosts have been found 1 year ago
German Service Network e597c48d77 Fixing build warning long int on seqmap.c line 84 1 year ago
German Service Network 9d7731e7a0 OpenBSD is not affected by the "broken alpha headers" bug, too. 1 year ago
German Service Network e8660637cc Fallback to SO_TIMESTAMP if SO_TIMESTAMPNS is not available 1 year ago
David Schweikert 8dc0b7f39a correctly call getnameinfo() 2 years ago
David Schweikert 041ba7acb8 reformat 2 years ago
Thomas Klausner 5d3eee1105 NetBSD/alpha is not affected by the "broken alpha headers" bug. 3 years ago
David Schweikert ab1ed993ba fix socket4 vs socket6 typo (#249, thanks @sfan5) 3 years ago
David Schweikert e975a4339b fix unprivileged ping broken in v5.1 (fixes #248) 3 years ago
David Schweikert 87c9b29d86 update changelog and 5.1 release date 3 years ago
David Schweikert ae49f4d933 Update autotools and fix code coverage issues. 3 years ago
Erik Auerswald c67f6deb51 add missing files to autoclean.sh
At least on my system (Ubuntu GNU/Linux 18.04.6 LTS), autoclean.sh
misses three files: compile, doc/Makefile, and src/Makefile.  Add
them.
3 years ago
German Service Network 948b58ee1f Remove dublicate include time.h entry 3 years ago
David Schweikert 3ecfbb7c1e GH action test 3 years ago
David Schweikert 2d574aa1d1
Create codeql-analysis.yml (#241)
Create codeql-analysis.yml
3 years ago
David Schweikert 052b58be65
Merge pull request #240 from auerswal/doc-fixes
Documentation improvements
3 years ago
Erik Auerswald 36b652b358 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.
3 years ago
Erik Auerswald 1452bf362e 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.
3 years ago
David Schweikert 477e6776ce
Merge pull request #236 from schweikert/travis-fix
Prepare 5.1 release
3 years ago
David Schweikert cbe7a92c14 prepare 5.1 release 3 years ago
David Schweikert bbaa365526 more travis stability fixes 3 years ago
David Schweikert cf03fa5bdb skip timing test on macos 3 years ago
David Schweikert f1d3615706
Merge pull request #217 from gsnw/bug/203
Fixed wrong timestamp under Free- and OpenBSD and macOS
3 years ago
German Service Network 04af04c839 Fixed wrong timestamp under Free- and OpenBSD and macOS 3 years ago
David Schweikert 749127f525
Merge pull request #227 from aafbsd/patch-1
fix getnameinfo
3 years ago
David Schweikert 03aea81617
Merge pull request #229 from gsnw/bug/219
use formatstring macro PRId64 in print_netdata for output int64_t
3 years ago
David Schweikert df5f072ddd
Merge pull request #235 from schweikert/travis-fix
make travis testing more robust
3 years ago
David Schweikert 7b3cf2593a fix travis build 3 years ago
David Schweikert ca3cf3a347
Merge pull request #232 from zdyxry/spec
Use setcap to specify specific files
3 years ago
Yiran Zhou 029da075e2 Use setcap to specify specific files 3 years ago
David Schweikert 19ddae8fdc
Merge pull request #226 from k0ste/help
Netdata feature: use host instead name as family label
3 years ago
German Service Network ea0eda41f1 use formatstring macro PRId64 in print_netdata for output int64_t 3 years ago
aafbsd bbe847a5d9
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
3 years ago
David Schweikert b4aeda17fd
Merge pull request #215 from normanr/develop
Allow -4 option to be given multiple times when IPv6 is enabled.
3 years ago
Konstantin Shalygin b46c161bb3
Netdata feature: use host instead name as family label
Fixes https://github.com/netdata/netdata/issues/11336
3 years ago
David Schweikert d05a7e7bf9
Merge pull request #208 from timgates42/bugfix_typo_permanently
docs: fix simple typo, permanetly -> permanently
3 years ago
Norman Rasmussen e432f46e01 Allow -4 option to be given multiple times when IPv6 is enabled. 4 years ago
Tim Gates 95df9d00f5
docs: fix simple typo, permanetly -> permanently
There is a small typo in src/fping.c.

Should read `permanently` rather than `permanetly`.
4 years ago
David Schweikert eac20347ba
Merge pull request #200 from simetnicbr/for-upstream/privileged-SO_BINDTODEVICE
fping: retain privileges until after privileged setsockopt
4 years ago
David Schweikert 49673f7862
Merge pull request #198 from dinoex/develop
- fix regression introduced in fping 4.3
4 years ago
David Schweikert ce9d6b351e
Merge pull request #197 from gsnw/develop
Update Azure Pipline based on travis-ci tuning
4 years ago
Henrique de Moraes Holschuh 59d83ed402 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.
4 years ago
Dirk Meyer 31f76f6071 - 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
4 years ago
German Service Network f2b2cdf620 Update Azure Pipline based on travis-ci tuning 4 years ago
David Schweikert 296de3d7a2 small fixes to changelog 4 years ago
David Schweikert 03bfc48ff4 travis-ci: fix deploy stage 4 years ago
David Schweikert 5f5220939d travis-ci: fix deploy stage 4 years ago
David Schweikert f6e3d7194d prepare 5.0 release 4 years ago
David Schweikert 57d49f2d8e move coverity scan to a script, so that it doesn't run for every job 4 years ago
David Schweikert 2ca8edeaf6 change license field in fping.spec to something that seems better matching, fixes #192 4 years ago
David Schweikert 0d8f3cef2a move coverity scan to a script, so that it doesn't run for every job 4 years ago
David Schweikert aeea60a0e0 move coverity scan to a script, so that it doesn't run for every job 4 years ago
David Schweikert 5a6a61cb32 update coverage badge link 4 years ago
David Schweikert 4f16eea49f use int64_t for time-related variables 4 years ago
David Schweikert 2dbe46f936 remove debug output 4 years ago
David Schweikert 363396c28f use int64_t everywhere, instead of long and 10us values 4 years ago
David Schweikert 88ef7a7b98 Merge branch 'testing-improvements' into develop 4 years ago
David Schweikert 73bfc121c2 more travis-ci improvements 4 years ago
David Schweikert d06b8fcea3
Merge pull request #196 from schweikert/travis-improvements
Travis CI improvements, add macos testing
4 years ago
David Schweikert 5655b7664c travis-ci improvements 4 years ago
David Schweikert 3bb2811139 travis-ci: use xenial autotools instead of building them 4 years ago
David Schweikert 2f71a6a701 travis-ci improvements, add macos testing 4 years ago
David Schweikert 9682f3e49d add a not about unprivileged mode 4 years ago
David Schweikert a136764f8c always exclude IP header in returned size 4 years ago
David Schweikert 43f6e3498e print lost pings in loop and count mode, fixes #175 4 years ago
David Schweikert 130b1d6f9b revert sprint_tm change doing apparent wrong casting 4 years ago
David Schweikert fec099871c fix compiler warning 4 years ago
David Schweikert da27697eb4 small formatting fixes to printed time 4 years ago
David Schweikert fe4388ca3d use int64_t whenever time is stored, fixes #195 4 years ago
David Schweikert eb87a2affd use int64_t instead of struct timespec everywhere
This should be more efficient and is also easier to read.
4 years ago
David Schweikert 5473c7d734 remove unused host_entry fields 4 years ago
David Schweikert ac3eb34ad7 Merge branch 'develop' of github.com:schweikert/fping into develop 4 years ago
David Schweikert 2cb373463f simplify timespec conversions to ns, prepare mocking of receive_packet 4 years ago
David Schweikert 6505832d6a
Merge pull request #194 from Kiskae/portable_signals
Improve portability of signal handling
4 years ago
David van Leusen 254573f241 use sigaction when possible 4 years ago
David van Leusen 69f7277076 implement finish handler through flag instead of direct call in signal handler 4 years ago
David Schweikert 2b5c0e62ec
Merge pull request #193 from schweikert/timeout-events
refactored event loop, now for each ping create both next-ping+timeout events
4 years ago
David Schweikert bb8d71ef27 refactored event loop, now for each ping we create both a ping and a timeout event 4 years ago
Steven Noonan 6600b04152 only use getsockname() for identity with SOCK_DGRAM sockets
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
4 years ago
David Schweikert 8152668607 update CHANGELOG 5 years ago
David Schweikert c7437d8f61
Merge pull request #187 from Polynomial-C/disable-ipv6_build_fix
Fix build with --disable-ipv6
5 years ago
Lars Wendler 54e97d9e39
Fix build with --disable-ipv6
Otherwise build breaks with:

fping.c:399:14: error: ‘ident6’ undeclared (first use in this function); did you mean ‘ident4’?
  399 |     ident4 = ident6 = getpid() & 0xFFFF;
      |              ^~~~~~
      |              ident4

Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
5 years ago
David Schweikert 08c83453f3 Merge branch 'v4.x' into develop 5 years ago
David Schweikert 3690be9cdd avoid including ci/build in dist tarball 5 years ago
David Schweikert 9731556633 prepare for version 5.x 5 years ago
David Schweikert c1d3f65694 update changelog 5 years ago
David Schweikert 721af135db
Merge pull request #136 from tycho/high-resolution-clock-sources
Move to 1us resolution for latency measurements
5 years ago
David Schweikert c27f37c91c prepare release 4.3 5 years ago
David Schweikert 97f995f38e get rid of deprecated bzero() 5 years ago
David Schweikert efc5ed3263 Use line buffering for stdout. fixes #179 5 years ago
David Schweikert e38f2b221c add missing files from tar.gz (ci, contrib, README.md) - fixes #178 5 years ago
David Schweikert 52af20a3ed update changelog 5 years ago
David Schweikert f5f9415651
Merge pull request #151 from brownowski/duplicate-patch-1
Only increase num_alive if response is not a duplicate
5 years ago
David Schweikert 5eff605bbb
Merge pull request #185 from laddp/develop
Add SIGQUIT summary support similar to ping
5 years ago
Patrick Ladd e064c36df8 Add SIGQUIT summary support similar to ping
This reverts commit 3b3877f651af816006ab620f7a189c2c1a3fad8a.
5 years ago
David Schweikert ee648fccde Merge pull request #172 from vlvkobal/develop
Fix xmt stats in Netdata output
5 years ago
Steven Noonan ad451e7a15
test-05: don't assume -D timestamp is based on UNIX epoch
If CLOCKID != CLOCK_REALTIME, it probably will not have anything to do
with the UNIX epoch, so it could be smaller than 10 digits.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
Steven Noonan 754a21e2bd
move to 1us resolution for latency measurement
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
Steven Noonan 8aa4361118
allow passing hex or decimal arguments to -z (debug) flag
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
Steven Noonan e21b68f62e
main: add missing getopt_long specification for -z debug argument
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
David Schweikert 25e30da512
Merge pull request #172 from vlvkobal/develop
Fix xmt stats in Netdata output
5 years ago
David Schweikert 589d326650
Merge pull request #174 from tycho/macos-unbreak-getaddrinfo
macos: use AI_UNUSABLE hint for getaddrinfo()
5 years ago
David Schweikert 43767e2fbc
Merge pull request #173 from tycho/linux-unprivileged-ping
Linux unprivileged ping support
5 years ago
Steven Noonan 44dd04562c
test-11-nopriv: check Linux GID permission for unprivileged ping
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
Steven Noonan 6bc29919d3
linux: account for missing IP header block when using SOCK_DGRAM
Linux doesn't include an IP header in the payload when using an
unprivileged SOCK_DGRAM socket.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
Steven Noonan 1486bf209b
use kernel-assigned ping ident value
On Linux, when running with an unprivileged process, the kernel does not
respect the assigned "id" field. So in that scenario we need to ask the
kernel what assignment it has given us instead.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
Steven Noonan 5187f5b990
macos: use AI_UNUSABLE hint for getaddrinfo()
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
5 years ago
Vladimir Kobal edf8475f63 Fix xmt stats in Netdata output 5 years ago
David Schweikert bc5017b329
Merge pull request #167 from cranderson/gcc10
use extern in header files when declaring global variables
5 years ago
David Schweikert c1967a21fc
Merge pull request #168 from cranderson/formatstrings
increase some buffer sizes to eliminate format warnings
5 years ago
David Schweikert 659d3d837d
Merge pull request #170 from gsnw/develop
Add Azure Pipline jobs
5 years ago
German Service Network 5b5fa55d63 Add Azure Pipline jobs 5 years ago
Charles R. Anderson a75a6f8675 increase some buffer sizes to eliminate -Wformat-overflow and -Wformat-truncation warnings 5 years ago
Charles R. Anderson 0ed73181eb GCC 10 compatibility: use extern in header files when declaring global variables 5 years ago
David Schweikert aba04241c7 add _GNU_SOURCE to fix some warnings 5 years ago
David Schweikert 410e66ddcc fix usage of open_ping_socket_ipv4/6 5 years ago
David Schweikert 18dcc6af70 get rid of &tz argument in gettimeofday (obsolete) 5 years ago
David Schweikert 99c0829df0
Merge pull request #153 from gsnw/develop
Create Azure Pipline Testbuild without test-14-ping-internet-hosts.pl
5 years ago
David Schweikert 88963ebb1b
Merge pull request #154 from pbhenson/fix_-4_bug
Fix -4 option when IPv6 disabled
5 years ago
David Schweikert 39a567d162
Merge pull request #163 from kbucheli/fail_on_interface_binding_errors
Fail on interface binding errors
5 years ago
Konrad Bucheli 745cf4b1cf make fping fail if it cannot bind the interface (-I) 5 years ago
Konrad Bucheli bc9ce2fdf1 make fping fail if it cannot bind the interface (-I) 5 years ago
Paul B. Henson 509f5a59cb
Fix -4 option when IPv6 disabled
When IPv6 is disabled, hints_ai_family is set to AF_INET at initialization, resulting in the error "can't specify both -4 and -6" if the -4 option is supplied. If there's no IPv6, make the -4 option a no-op.
5 years ago
German Service Network a77e2e6c18 Create Azure Pipline Testbuild without test-14-ping-internet-hosts.pl 5 years ago
brownowski 5883c6f272
Update fping.c
Should only increase num_alive if response is not a duplicate.  

In cases where multiple pings are sent, num_alive can increase past one for a host if a duplicate ping response is received while h->num_recv ==1.
6 years ago
David Schweikert 12961d59ec fix google dns names 6 years ago
David Schweikert 7c61ac54be update changelog 6 years ago
David Schweikert 1d24c3f48a Merge branch 'master' into develop 6 years ago
David Schweikert f8b327923e
Merge pull request #149 from stromnet/inet6-too-strict-check
Do not fail if using fping6 with -6 flag
6 years ago
Johan Ström 6fd4f8bd91 Do not fail if using fping6 with -6 flag
Mostly for backwards compatability
6 years ago
David Schweikert 54a1321775 update changelog 6 years ago
David Schweikert 4fa4c15530
Merge pull request #148 from wopfel/docu-stats-correction
Corrected long option name of -s to --stats
6 years ago
David Schweikert 151fef9312 fix internet test that uses a name with multiple a records 6 years ago
Bernd Arnold 4125a1922c Corrected long option name of -s to --stats
The option --src is an alias for the uppercase -S.

Stumbled upon this in the man page.

When running "fping -h", the option is printed correctly:
$ -s, --stats        print final stats
6 years ago
David Schweikert d6b67d84e6
Merge pull request #145 from Jesin/fixurl
Fix links to CHANGELOG.md and README.md
6 years ago
Jesin ec3b62cad5 Fix links to CHANGELOG.md and README.md 6 years ago
David Schweikert d6d037b900
Merge pull request #144 from xtaran/develop
README.md improvements
6 years ago
Axel Beckert 60c0ad3a6a Merge the two redundant mentions of the man page 6 years ago
Axel Beckert 0d4648c976 Add some missing full stops
Capitalize "github".
6 years ago
Axel Beckert 046d9e4a45 Improve Markdown formatting 6 years ago
Axel Beckert f4a5de41d3 Use HTTPS for link to fping homepage 6 years ago
David Schweikert f47dc1948a prepare release v4.2 6 years ago
David Schweikert a4522f1af2 Get rid of warning "timeout (-t) value larger than period (-p) produces unexpected results", fixes #142 6 years ago
David Schweikert 633ea983ed test robustness fixes 6 years ago
David Schweikert a74d32cfb1 Merge branch 'develop' of github.com:schweikert/fping into develop 6 years ago
David Schweikert 4b7d4cb536 Allow decimal numbers for '-t', '-i', '-p', and '-Q'. fixes #133 6 years ago
David Schweikert 69f11b104d rename --min_reachable again to --reachable, and update changelog 6 years ago
David Schweikert 80067fcdd5
Merge pull request #138 from deepak0004/develop
Adding -x option which allows user to specify a threshold and check if atleast those many hosts are active
6 years ago
deepak0004 03d821e983 Removing flag variable and its dependencies, printing required and reachable hosts, and changing initialisation of min_reachable 6 years ago
David Schweikert cc7316b7b8 CHANGELOG.md: add note about #139 6 years ago
deepak0004 af9b3bfbfe Adding separate exit codes for success or failure, and printing the number of reachable hosts 6 years ago
David Schweikert 6694668fdb
Merge pull request #139 from abelbeck/fping6
Add backward compatibility for fping6 sym-link

Using sym-links to select IPv6 is discouraged (because it doesn't work the same for IPv4), but I understand that this can help for some use cases (i.e. in particular for the embedded linux distro use case, where having two binaries is an issue). Also, I guess nobody is going to have a binary called fping6 and expect it to do IPv4, so, I guess, no harm done.
6 years ago
David Schweikert cc4a504d09 update changelog 6 years ago
David Schweikert 0a1983ca46
Merge pull request #140 from abelbeck/fix-no-ipv6-hang
Fix hang with '-6', with ipv6 kernel module, but not loaded
6 years ago
Lonnie Abelbeck 03e050a395 Fix hang with '-6', with ipv6 kernel module, but not loaded 6 years ago
Lonnie Abelbeck a82f40f246 Add backward compatibility for fping6 sym-link 6 years ago
deepak0004 9812557c71 Changing the exit code as per travis ci 6 years ago
deepak0004 8e33daed93 Adding travis ci tests for more coverage and rectifying a mistake 6 years ago
deepak0004 b18e930bed Making the reqd changes 6 years ago
deepak0004 7338b4b859 Adding -x option which allows user to specify a threshold and check if atleast those many hosts are active 6 years ago
David Schweikert 180c6dd8d0 fix whitespace 6 years ago
David Schweikert c380986972 add note about fixing #134 6 years ago
David Schweikert 8cff0657be
Merge pull request #134 from Polynomial-C/v4.1_diable-ipv6_fix
Fix build with --disable-ipv6
6 years ago
Lars Wendler aa4a5f681a
Fix build with --disable-ipv6
Otheriwse build breaks with:

fping.c:690:24: error: ‘socket6’ undeclared (first use in this function);
did you mean ‘socket4’?
6 years ago
David Schweikert f9e1964160 prepare release 6 years ago
David Schweikert 1a660bd63b Add note about #132 6 years ago
David Schweikert 1b47fba939
Merge pull request #132 from gsnw/develop
Fix FreeBSD ipv6 build
6 years ago
German-Service-Network d9acc8e5a7
Fix FreeBSD ipv6 build
Source: https://svnweb.freebsd.org/ports/head/net/fping/files/patch-configure.ac?revision=473606&view=markup
Fix build fping with ipv6 support on FreeBSD
6 years ago
David Schweikert b4277e33a9 fix --help test, prepare 4.1 release 7 years ago
David Schweikert df7a819fd9 Allow running fping --help even when raw socket can't be opened, fixes #131 7 years ago
David Schweikert b2d35174c9 Fix segfault introduced with #118 change, thanks Simon 7 years ago
David Schweikert d46f298e62 fix test-14-ping-internet-hosts.pl failing 7 years ago
David Schweikert bb0eeaaeba Fix running on servers with disabled IPv6, fixes #118 7 years ago
David Schweikert 537430f57f update CHANGELOG 7 years ago
David Schweikert 47e1d573d8 Merge branch 'master' into develop 7 years ago
David Schweikert 520e6df833
Merge pull request #124 from nramon/bugfix-fd0
Return -1 when socket_can_read times out.
7 years ago
Ramon Novoa c950ceccea Return -1 when socket_can_read times out.
0 is a valid file descriptor. Use -1 instead to signal a timeout.
7 years ago
David Schweikert 9335b07f58 Merge pull request #114 from deafgoat/develop
fix typo: quet -> quiet
8 years ago
Wisdom Omuya e156b08ab6 fix typo: quet -> quiet 8 years ago
David Schweikert 24cd500259 Re-added README file to the distribution 8 years ago
David Schweikert 16aaa609cd link github issues 8 years ago
David Schweikert 0d8f704f20 add new changelog files to dist 8 years ago
David Schweikert 98e45b5ed5 add a note to the changelog 8 years ago
David Schweikert 3596aa3be6 merge develop 8 years ago
David Schweikert da90052d1c release 4.0 8 years ago
David Schweikert ef0ab382d0 New changelog format 8 years ago
David Schweikert 8505f5c3be release 4.0 8 years ago
David Schweikert 06dfaef9c3 some more text tuning 8 years ago
David Schweikert 5d84ad4c94 avoid duplicate hosts with -m 8 years ago
David Schweikert 2ac223ed34 improve help text 8 years ago
David Schweikert 7f54300634 improve help text 8 years ago
David Schweikert e0d45cbd54 whitespace fixes 8 years ago
David Schweikert 4c1d12c333 prepare 4.0-rc3 8 years ago
David Schweikert c2d86786e2 fix compiler warning 8 years ago
David Schweikert 965cae1bdc fix wording, #32 8 years ago
David Schweikert d22a3ccb00 add note on -i default being changed 8 years ago
David Schweikert 41de489bd8 fix test 8 years ago
David Schweikert cbfdcb40ff -i/-p restrictions only enforced with ./configure --enable-safe-limits, change -i default from 25 to 10 8 years ago
David Schweikert 94f976910a reword a bit help text for #32 8 years ago
David Schweikert 9b283310bd wording fixes 8 years ago
David Schweikert 80a45dc165 reformat 8 years ago
David Schweikert 5b3b94f367 minor wording fix 8 years ago
David Schweikert 2850b7a32e 4.0-rc2 8 years ago
David Schweikert 7592cc2a19 discard late packets, auto-adjust timeout for -c/-C/-l, fixes #32 8 years ago
David Schweikert 24ce982e5b improve coverage 8 years ago
David Schweikert 4e0b2277a3 improve test coverage 8 years ago
David Schweikert d4fe99d8cc improve test coverage 8 years ago
David Schweikert 624640c779 fix test 8 years ago
David Schweikert c9e2f9ce1d fix help test (and be less pedantic about help text changes) 8 years ago
David Schweikert 2ff3352f96 pod syntax 8 years ago
David Schweikert 71a6e4deef spacing fixes 8 years ago
David Schweikert 1b02b0fae8 sort options, remove whitespace 8 years ago
David Schweikert d18ad321de long options, better example 8 years ago
David Schweikert bab585e9fa new option --rdns 8 years ago
David Schweikert 2a86182f95 make help a bit narrower 8 years ago
David Schweikert 4f672b9b62 work on long option names, #73 8 years ago
David Schweikert 6bd608bf7a initial work on long option names, #73 8 years ago
David Schweikert 9be8d6cb5d remove references to fping6 8 years ago
David Schweikert d9f86182e8 fix setting of IPv4 source address 8 years ago
David Schweikert 94720be6fe fix coveralls call 8 years ago
David Schweikert 48ec5600e0 fix compatibility issue with GNU Hurd 8 years ago
David Schweikert 725893402d reformat 8 years ago
David Schweikert b4984b4549 minor wording fix 8 years ago
David Schweikert d19ca36405 exclude optparse for test coverage 8 years ago
David Schweikert e5c3839073 integrate optparse (https://github.com/skeeto/optparse) 8 years ago
David Schweikert 7605ef1b90 Merge branch 'develop' into coverity_scan 8 years ago
David Schweikert 9787dd0136 sync with develop 8 years ago
David Schweikert 2f95647566 fping and fping6 unification, fixes #80 8 years ago
David Schweikert c5612265ae document #80 8 years ago
David Schweikert 6b99b7bb89 compatibility fixes and prepare rc2 8 years ago
David Schweikert cae1bcd210 fix -m test 8 years ago
David Schweikert 35d52d0b30 Fix option -m to return all IPs of a hostname 8 years ago
David Schweikert 98269fb83e unification work 8 years ago
David Schweikert 12971e5409 ipv4/ipv6 unification fixes 8 years ago
David Schweikert 3c53d9be3f first version of fping that can do ipv4 and ipv6 at the same time 8 years ago
David Schweikert 8d4c69998d unification work 8 years ago
David Schweikert b35f60af8c fix test 8 years ago
David Schweikert 4262e74ff9 more cleanup 8 years ago
David Schweikert e827b6719a another attempt at fixing coverity warning 8 years ago
David Schweikert 3781fbe9bd Add Coverity link 8 years ago
David Schweikert 81c8002798 coverity scan fixes 8 years ago
David Schweikert 64d41f6295 coverity scan fixes 8 years ago
David Schweikert 989877829e coverity fix 8 years ago
David Schweikert 9ae26b603f add automated coverity 8 years ago
David Schweikert 23d4a021fc fix warnings 8 years ago
David Schweikert 324242b144 space / formatting fixes and remove unused code 8 years ago
David Schweikert d017390cbc remove trailing whitespace, fix mixed whitespace 8 years ago
David Schweikert 9d2daa77c8 remove trailing whitespace 8 years ago
David Schweikert 9adb9a8480 Merge branch 'develop' into unify 8 years ago
David Schweikert b5046cfa78 Fix -M expecting an argument, when it shouldn't 8 years ago
David Schweikert c090cd770d work on ipv4/ipv6 unification 8 years ago
David Schweikert e71164de22 restart work on ipv4/ipv6 unification 8 years ago

@ -0,0 +1,30 @@
.*.swp
*.tar.gz
*~
src/*.gcno
src/*.gcda
src/*.gcov
src/tags
.deps
Makefile
Makefile.in
aclocal.m4
autom4te.cache
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
install-sh
missing
src/*.o
src/fping
src/fping6
stamp-h1
doc/fping.8
doc/fping6.8
ci/build

@ -0,0 +1,67 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ develop ]
schedule:
- cron: '38 4 * * 3'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

@ -0,0 +1,108 @@
name: Test
on: [push, pull_request]
jobs:
Test-Linux:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install libcap2-bin libtest-command-perl lcov
sudo sysctl net.ipv4.ping_group_range='0 2147483647'
- name: Build
run: |
ci/build-1-autotools.sh
ci/build-4-compile.sh
ci/test-tarball.sh
- name: Test
run: |
set -ex
PATH=`pwd`/src:$PATH
# avoid pinging internet hosts because it doesn't
# work with GitHub Actions being hosted in Azure.
prove $(ls ci/test-*.pl|grep -v internet-hosts)
ci/run-lcov.sh
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
flag-name: ${{ matrix.os }}
parallel: true
Test-Mac:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dependencies
run: |
brew install automake lcov
ci/build-2-test-command.sh
ci/build-3-prepare-macos.sh
- name: Build
run: |
ci/build-4-compile.sh
- name: Test
run: |
set -ex
PATH=`pwd`/src:$PATH
export SKIP_IPV6=1
prove $(ls ci/test-*.pl|grep -v internet-hosts)
ci/run-lcov.sh
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
flag-name: macos
parallel: true
Coveralls-Finish:
needs: [Test-Linux, Test-Mac]
runs-on: ubuntu-latest
steps:
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
Release-Tarball:
needs: [Test-Linux, Test-Mac]
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install libcap2-bin libtest-command-perl
- name: Build
run: |
ci/build-1-autotools.sh
ci/build-4-compile.sh
ci/test-tarball.sh
- uses: actions/upload-artifact@v2
with:
name: dist
path: fping-*.tar.gz

1
.gitignore vendored

@ -4,6 +4,7 @@
src/*.gcno
src/*.gcda
src/*.gcov
src/tags
.deps
Makefile
Makefile.in

@ -1,40 +1,98 @@
# travis-ci.org configuration
#
language: generic
sudo: required
dist: trusty
os:
- linux
dist:
- trusty
- xenial
env:
global:
- secure: "CoI8hwHH1yfQoQxIfWGRS0WfTyScox+5aJn0fDDgz2uKrrIxmBvIw/WKX8wcSiV6fLmLuwgNkKqSM3hdO4qaG+JxfWcuEiZZHm+kxSGMkWbGb/fvAI+gHg8ldKyYttcIX71O5rlZiC2QpNKQi2v18S6pI5p8eqnx7DYx4YrmguQ="
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "C9ZJ9LYnuowRdF4D66KLfquimvu8GtRGIafwvCcGYKReEy8phlBdFsHlybkMBNYJNTJSM0j6wyo1lKTVGHxmpQDimjR7kmxUtawbhuJ5qOCBtFqNVh9lRQi7hC4+UOhvRsIcbV8HAJM5u/5RxGOfXCePK3a2DtiYv1d2NHToZN8="
notifications:
webhooks: https://coveralls.io/webhook
compiler:
- gcc
before_install:
- sudo apt-get update -qq
- sudo apt-get install libcap2-bin
#- sudo apt-get install traceroute
#- traceroute google.com
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
install:
- ci/build-1-autotools.sh
- curl -L http://cpanmin.us | perl - --sudo App::cpanminus
- cpanm --sudo Test::Command
addons:
apt:
update: true
packages:
- libcap2-bin
- libtest-command-perl
script:
- ci/build-2-install.sh
- env PATH=`pwd`/src:$PATH prove ci/test-*.pl
- ci/test-tarball.sh
- ci/build-4-compile.sh
- ci/run-tests.sh
after_success:
- ci/coveralls.sh
- ci/deploy-coveralls.sh
stages:
- test
- name: deploy
if: branch = master OR branch = v4.x
- name: coverity
if: branch = master OR branch = coverity_scan
jobs:
include:
#### STAGE: test
- stage: test
name: test trusty
os: linux
dist: trusty
env:
- SKIP_IPV6=1
install:
- ci/build-1-autotools.sh
- name: test xenial
os: linux
dist: xenial
env:
- SKIP_IPV6=1
- name: test bionic
os: linux
dist: bionic
env:
- SKIP_IPV6=1
- name: test bionic lxd arm64
os: linux
dist: bionic
arch: arm64
- name: test macos
os: osx
install:
- ci/build-2-test-command.sh
- ci/build-3-prepare-macos.sh
env:
- SKIP_IPV6=1
#### STAGE: deploy
- stage: deploy
name: deploy
os: linux
dist: xenial
env:
- SKIP_IPV6=1
after_success:
- ci/deploy-bintray.sh
addons:
coverity_scan:
project:
name: "schweikert/fping"
description: "Build submitted via Travis CI"
notification_email: david@schweikert.ch
#build_command_prepend: "ci/build-2-install.sh"
build_command: "ci/build-2-install.sh"
branch_pattern: coverity_scan
#### STAGE: coverity
- stage: coverity
name: coverity
os: linux
dist: xenial
after_success:
script:
- ci/deploy-coverity.sh

@ -0,0 +1,35 @@
{
"configurations": [
{
"name": "Debug fping",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/src/fping",
"args": ["127.0.0.1"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "build",
"postDebugTask": "autoclean",
"miDebuggerPath": "/usr/bin/gdb",
"logging": {
"engineLogging": false
}
}
],
"version": "2.0.0"
}

45
.vscode/tasks.json vendored

@ -0,0 +1,45 @@
{
"tasks": [
{
"type": "shell",
"label": "autogen",
"command": "./autogen.sh",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"type": "shell",
"label": "configure",
"command": "./configure",
"args": ["--enable-debug"],
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": ["autogen"],
"problemMatcher": []
},
{
"type": "shell",
"label": "build",
"command": "make",
"args": ["CFLAGS=\"-g -O0\""],
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": ["configure"],
"problemMatcher": ["$gcc"]
},
{
"type": "shell",
"label": "autoclean",
"command": "./autoclean.sh",
"problemMatcher": []
}
],
"version": "2.0.0"
}

@ -0,0 +1,246 @@
fping 5.2 (2024-04-21)
======================
## New features
- New option -X / --fast-reachable to exit immediately once N hosts have been
found (#260, thanks @chriscray and @gsnw)
- New option -k / -fwmark to set Linux fwmark mask (#289, thanks @tomangert and
@deepkv)
## Bugfixes and other changes
- Always output fatal error messages (#303, thanks @auerswal)
- Fallback to SO\_TIMESTAMP if SO\_TIMESTAMPNS is not available (#279, thanks
@gsnw)
- Fix "not enough sequence numbers available" error on BSD-like systems (#307,
thanks @cagney, @gsnw)
- Fix running in unprivileged mode (#248, thanks @sfan5)
- Fix build issue for NetBSD/alpha (#255, thanks @0-wiz-0)
- Fix build issue for OpenBSD/alpha (#275, thanks @gsnw)
- Fix build warning for long int usage (#258, thanks @gsnw)
- Fix build error with musl libc (#263, thanks @kraj)
- Fix to guard against division by zero (#293, thanks @auerswal)
- Decouple -a/-u effects from -c (#298, thanks @auerswal)
- Added contrib/Dockerfile (#224, thanks @darless)
- Remove host from Netdata chart titles (#253, thanks @ilyam8)
- Add additional tests (#292, #297, thanks @auerswal)
- Update github action os images (#282, thanks @gsnw)
- Fix Azure pipeline tests (#308, thanks @gsnw)
- Various autoconf fixes (#286, #283, thanks @gsnw)
- Extended configure script with --enable-debug and output cpu usage (#311,
thanks @gsnw)
- Documentation: Update Netdata website link (#257, thanks @ilyam8)
- Documentation: fix description of --file option (#268, thanks @MohGeek)
- Documentation: improve exit status description (#294, thanks @auerswal)
- Documentation: move description of -i MSEC (#298, thanks @auerswal)
- Documentation: improve help output for options -c and -C (#302, #auerswal)
fping 5.1 (2022-02-06)
======================
## Bugfixes and other changes
- Use setcap to specify specific files in fping.spec (#232, thanks @zdyxry)
- Netdata: use host instead name as family label (#226, thanks @k0ste)
- Netdata: use formatstring macro PRId64 (#229, thanks @gsnw)
- Allow -4 option to be given multiple times (#215, thanks @normanr)
- Documentation fix (#208, thanks @timgates42)
- Retain privileges until after privileged setsockopt (#200, thanks @simetnicbr)
- Set bind to source only when option is set (#198, thanks @dinoex)
- Update Azure test pipeline (#197, thanks @gsnw)
- Fix getnameinfo not called properly for IPv4 (#227, thanks @aafbsd)
- Fixed wrong timestamp under Free- and OpenBSD and macOS (#217, thanks @gsnw)
- Documentation updates (#240, thanks @auerswal)
- Updated autotools (autoconf 2.71, automake 1.16.5, libtool 2.4.6)
fping 5.0 (2020-08-05)
======================
## Incompatible Changes
- In non-quiet loop and count mode, a line is printed for every lost packet
(#175, thanks @kbucheli):
```
$ fping -D -c2 8.8.8.8 8.8.8.7
[1596092373.18423] 8.8.8.8 : [0], 64 bytes, 12.8 ms (12.8 avg, 0% loss)
[1596092374.18223] 8.8.8.7 : [0], timed out (NaN avg, 100% loss)
[1596092374.18424] 8.8.8.8 : [1], 64 bytes, 12.3 ms (12.5 avg, 0% loss)
[1596092375.18344] 8.8.8.7 : [1], timed out (NaN avg, 100% loss)
8.8.8.8 : xmt/rcv/%loss = 2/2/0%, min/avg/max = 12.3/12.5/12.8
8.8.8.7 : xmt/rcv/%loss = 2/0/100%
```
- The returned size in bytes now always excludes the IP header, so if before it
reported '84 bytes' e.g. when using 'fping -l', now it reports '64 bytes'.
This is to make the reported size consistent with ping(8) from iputils and
also with fping when pinging a IPv6 host (which never included the IPv6
header size).
## New features
- The number of sent pings is only counted when the pings are received or have
timed out, ensuring that the loss ratio will be always correct. This makes it
possible, for example, to use loop mode (-l) with interval statistics (-Q)
and a timeout larger than period, without having the issue that initially
some pings would be reported as missing (#193)
- Improved precision of measurements from 10us to 1us (#136, thanks @tycho)
## Bugfixes and other changes
- The reported size of received packets is now always correct on Linux even for
packets > 4096 bytes (#180)
- Travis CI automated testing now also macos testing and additional ubuntu
distributions (#196)
fping 4.4 (2020-07-24)
======================
## Bugfixes and other changes
- Fix wrong ident used for normal (non-unprivileged) pings (#191, thanks @tycho)
- Fix build with --disable-ipv6 (#187, thanks Polynomial-C)
fping 4.3 (2020-07-11)
======================
## New features
- Linux unprivileged ping support (#173, thanks @tycho)
- Add SIGQUIT summary support similar to ping (#185, thanks @laddp)
## Bugfixes and other changes
- Corrected long option name of -s to --stats (#148, thanks @wopfel)
- Do not fail if using fping6 with -6 flag (#149, thanks @stromnet)
- Fail if interface binding (-I) does not work (#162, thanks @kbucheli)
- Fix using option -4 when fping is compiled IPv4-only (#154, thanks @pbhenson)
- Add Azure pipeline test build (#153 and #170, thanks @gsnw)
- GCC 10 compatibility fixes (#167 and #168, thanks @cranderson)
- Macos build fix (#174, thanks @tycho)
- Fix xmt stats in Netdata output (#172, thanks @vlvkobal)
- Only increase num_alive if response is not a duplicate (#151, thanks @brownowski)
- Use line buffering for stdout (#179, thanks @bg6cq)
fping 4.2 (2019-02-19)
======================
## New features
- New option -x / --reachable to check if the number of reachable hosts is >= a certain
number. Useful for example to implement connectivity-checks (#138, thanks @deepak0004)
## Bugfixes and other changes
- Allow decimal numbers for '-t', '-i', '-p', and '-Q'
- Fix build with --disable-ipv6 (#134, thanks @Polynomial-C)
- Fix hang with '-6', with ipv6 kernel module, but not loaded (#140, thanks @abelbeck)
- Assume '-6' if the binary is named 'fping6' (this is mostly for special
embedded-distro use cases, and not meant to be used generally in place of
compiling IPv6-only binary or using '-6', see also the notes in #139, thanks
abelbeck)
- Get rid of warning "timeout (-t) value larger than period (-p) produces unexpected results"
(#142, thanks @MrDragon1122)
fping 4.1 (2018-09-17)
======================
## Bugfixes and other changes
- Fix problem when socket fd is 0 (#125, thanks Ramón Novoa!)
- Fix running on servers with disabled IPv6 (#118, thanks Simon Matter)
- Allow running "fping -h" or "--help" even when raw socket can't be opened (#131, thanks @teto)
- Fix build issue with FreeBSD and IPv6 (#132, thanks @gsnw)
fping 4.0 (2017-04-23)
======================
## Incompatible Changes
##### fping and fping6 unification
fping and fping6 are now unified into one binary. It means that, for example,
doing 'fping google.com' is going to ping the IPv6 IP of google.com on
IPv6-enabled hosts.
If you need exact compatibility with old versions, you can configure and
install fping twice: once for ipv4, and once for ipv6:
./configure --disable-ipv6; make clean install
./configure --disable-ipv4 --program-suffix=6; make clean install
##### Option -n, not the same as -d anymore
Option -n / --name is now doing a reverse-DNS lookups on host addresses,
only if they are given as IP address, but not for hostnames. For example,
if you write 'fping -n google.com', fping would previously do a
forward-DNS lookup on google.com, and then a reverse-DNS lookup on the
resolved IP address. Now, it is just going to keep the name 'google.com'.
That same behavior can be achieved with the option -d / --rdns (which was
previously an alias for -n).
fping<4.0 fping>=4.0
fping -n NAME NAME->IP->IPNAME NAME
fping -d NAME NAME->IP->IPNAME NAME->IP->IPNAME
##### Discarding of late packets
fping will now discard replies, if they arrive after the defined timeout
for reply packets, specified with -t. This change is relevant only for the
count and loop modes, where the measured times should be now more
consistent (see github issue [#32][i32] for details).
To prevent loosing reply packets because of this change, the default
timeout in count and loop modes is now automatically adjusted to the
period interval (up to 2000 ms), but it can be overriden with the -t
option. The default timeout for non-loop/count modes remains 500 ms.
##### No restrictions by default
fping will not enforce -i >= 1 and -p >= 10 anymore, except if you
'./configure --enable-safe-limits'.
The reasoning to removing the restrictions by default, is that users can
clog the network with other tools anyway, and these restrictions are
sometimes getting in the way (for example if you try to ping a lot of
hosts).
##### Default interval (-i) changed from 25ms to 10ms
The default minimum interval between ping probes has been changed from
25ms to 10ms. The reason is that 25ms is very high, considering today's
fast networks: it generates at most 31 kbps of traffic (for IPv4 and
default payload size).
## New features
- Unified 'fping' and 'fping6' into one binary ([#80][i80])
- Long option names for all options
- IPv6 enabled by default
- New option -4 to force IPv4
- New option -6 to force IPv6
- Keep original name if a hostname is given with -n/--name
- Option -d/--rdns now always does a rdns-lookup, even for names, as '-n' was doing until now
- Enforce -t timeout on reply packets, by discarding late packets ([#32][i32])
- Auto-adjust timeout for -c/-C/-l mode to value of -p
## Bugfixes and other changes
- -i/-p restrictions disabled by default (enable with --enable-safe-limits)
- Default interval -i changed from 25ms to 10ms
- Fix compatibility issue with GNU Hurd
- A C99 compiler is now required
- Option parsing with optparse (https://github.com/skeeto/optparse). Thanks Christopher Wellons!
- New changelog file format
[i32]: https://github.com/schweikert/fping/issues/32
[i80]: https://github.com/schweikert/fping/issues/80
(see doc/CHANGELOG.pre-v4 for older changes)

@ -1 +1,3 @@
SUBDIRS = doc src
EXTRA_DIST = CHANGELOG.md contrib README.md ci/*.sh ci/*.pl

@ -1,55 +0,0 @@
fping 3 README
--------------
fping is a program to send ICMP echo probes to network hosts, similar to ping,
but much better performing when pinging multiple hosts. fping has a long long
story: Roland Schemers did publish a first version of it in 1992 and it has
established itself since then as a standard tool.
Current maintainer:
David Schweikert <david@schweikert.ch>
Website:
http://fping.org/
Mailing-list:
https://groups.google.com/group/fping-users
Installation
------------
If you want to install fping from source, proceed as follows:
0. Run ./autogen.sh
(only if you got the source from github)
1. Run ./configure with the correct arguments
(see: ./configure --help)
2. Run make; make install
3. Make fping either setuid, or, if under Linux:
sudo setcap cap_net_raw+ep fping
4. Have a look at the fping(8) manual for usage help
(fping -h will also give a minimal help output)
IPv6 support
------------
You can can compile fping with support for IPv6 addresses. A separate binary
is used for that, called fping6. To build it, use ./configure --enable-ipv6
(possibly combined with --enable-ipv4 to also build fping for IPv4). E.g.:
# ./configure --prefix=/usr/local --enable-ipv4 --enable-ipv6
# make
# make install
# sudo setcap cap_net_raw+ep /usr/local/bin/fping*
Credits
-------
Original author: Roland Schemers (schemers@stanford.edu)
Previous maintainer: RL "Bob" Morgan (morgan@stanford.edu)
Initial IPv6 Support: Jeroen Massar (jeroen@unfix.org / jeroen@ipng.nl)
Other contributors: see ChangeLog

@ -1,8 +1,8 @@
[![Build Status](https://travis-ci.org/schweikert/fping.svg?branch=develop)](https://travis-ci.org/schweikert/fping)
[![Coverage Status](https://coveralls.io/repos/schweikert/fping/badge.svg?branch=develop&service=github)](https://coveralls.io/github/schweikert/fping?branch=develop)
[![Coverage Status](https://coveralls.io/repos/github/schweikert/fping/badge.svg?branch=develop)](https://coveralls.io/github/schweikert/fping?branch=develop)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/11559/badge.svg?flat=1")](https://scan.coverity.com/projects/schweikert-fping)
# fping 3
# fping
fping is a program to send ICMP echo probes to network hosts, similar to ping,
but much better performing when pinging multiple hosts. fping has a long long
@ -13,7 +13,7 @@ _Current maintainer_:
David Schweikert \<david@schweikert.ch\>
_Website_:
http://fping.org/
https://fping.org/
_Mailing-list_:
https://groups.google.com/group/fping-users
@ -22,32 +22,29 @@ _Mailing-list_:
If you want to install fping from source, proceed as follows:
0. Run ./autogen.sh
(only if you got the source from github)
1. Run ./configure with the correct arguments
(see: ./configure --help)
2. Run make; make install
0. Run `./autogen.sh`
(only if you got the source from Github).
1. Run `./configure` with the correct arguments.
(see: `./configure --help`)
2. Run `make; make install`.
3. Make fping either setuid, or, if under Linux:
sudo setcap cap_net_raw+ep fping
4. Have a look at the fping(8) manual for usage help
(fping -h will also give a minimal help output)
`sudo setcap cap_net_raw,cap_net_admin+ep fping`
## Usage
See: [fping man-page](doc/fping.pod)
If you can't run fping as root or can't use the cap_net_raw capability, you can
also run fping in unprivileged mode. This works on MacOS and also on Linux,
provided that your GID is included in the range defined in
`/proc/sys/net/ipv4/ping_group_range`. This is particularly useful for running
fping in rootless / unprivileged containers. The --fwmark option needs root or
cap_net_admin. setuid will not work for --fwmark.
## IPv6 support
You can can compile fping with support for IPv6 addresses. A separate binary
is used for that, called fping6. To build it, use ./configure --enable-ipv6
(possibly combined with --enable-ipv4 to also build fping for IPv4). E.g.:
## Usage
# ./configure --prefix=/usr/local --enable-ipv4 --enable-ipv6
# make
# make install
# sudo setcap cap_net_raw+ep /usr/local/bin/fping*
Have a look at the [fping(8)](doc/fping.pod) manual page for usage help.
(`fping -h` will also give a minimal help output.)
## Credits
Original author: Roland Schemers (schemers@stanford.edu)
Previous maintainer: RL "Bob" Morgan (morgan@stanford.edu)
Initial IPv6 Support: Jeroen Massar (jeroen@unfix.org / jeroen@ipng.nl)
Other contributors: see ChangeLog
* Original author: Roland Schemers (schemers@stanford.edu)
* Previous maintainer: RL "Bob" Morgan (morgan@stanford.edu)
* Initial IPv6 Support: Jeroen Massar (jeroen@unfix.org / jeroen@ipng.nl)
* Other contributors: see [CHANGELOG.md](CHANGELOG.md)

@ -4,6 +4,7 @@ rm -f Makefile
rm -f Makefile.in
rm -f aclocal.m4
rm -rf autom4te.cache
rm -f compile
rm -f config.guess
rm -f config.h
rm -f config.h.in
@ -16,7 +17,9 @@ rm -f install-sh
rm -f missing
rm -f mkinstalldirs
rm -f stamp-h1
rm -f doc/Makefile
rm -f doc/Makefile.in
rm -f src/Makefile
rm -f src/Makefile.in
rm -f doc/fping.8
rm -f src/*.gcda

@ -0,0 +1,52 @@
jobs:
- job: linux_build
displayName: Linux Build
pool:
name: Azure Pipelines
vmImage: 'ubuntu-latest'
workspace:
clean: all
steps:
- script: |
sudo apt-get update -qq
sudo apt-get install libcap2-bin libtest-command-perl
displayName: 'before_install'
- script: |
ci/build-4-compile.sh
displayName: install
- script: |
set -ex
PATH=`pwd`/src:$PATH
prove $(ls ci/test-*.pl|grep -v internet-hosts|grep -v -E "test-13-unknown-host.pl|test-14-ping-internet-hosts.pl")
ci/test-tarball.sh
displayName: 'build_test'
- job: macos_build
displayName: macOS Build
pool:
name: Azure Pipelines
vmImage: 'macos-latest'
workspace:
clean: all
steps:
- script: |
brew install autoconf automake lcov
ci/build-2-test-command.sh
ci/build-3-prepare-macos.sh
displayName: 'before_install'
- script: |
ci/build-4-compile.sh
displayName: install
- script: |
set -ex
PATH=`pwd`/src:$PATH
export SKIP_IPV6=1
prove $(ls ci/test-*.pl|grep -v internet-hosts|grep -v test-10-option-u-x.pl)
ci/run-lcov.sh
displayName: 'build_test'

@ -1,8 +1,15 @@
#!/bin/bash -e
#!/bin/bash
AUTOCONF=http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
AUTOMAKE=http://ftp.gnu.org/gnu/automake/automake-1.14.1.tar.gz
LIBTOOL=http://alpha.gnu.org/gnu/libtool/libtool-2.4.2.418.tar.gz
set -e
set -x
if [[ "$OSTYPE" == "darwin"* ]]; then
exit 0
fi
AUTOCONF=http://ftp.gnu.org/gnu/autoconf/autoconf-2.71.tar.gz
AUTOMAKE=http://ftp.gnu.org/gnu/automake/automake-1.16.5.tar.gz
LIBTOOL=http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz
PREFIX=$(pwd)/ci/build
PATH=$(pwd)/ci/build/bin:$PATH

@ -0,0 +1,6 @@
#!/bin/sh
set -ex
curl -L http://cpanmin.us | perl - -L $HOME/perl5 App::cpanminus
$HOME/perl5/bin/cpanm --sudo Test::Command

@ -11,8 +11,3 @@ if [[ ! `ifconfig lo0` =~ 127\.0\.0\.2 ]]; then
sudo ifconfig lo0 127.0.0.4/8 alias
sudo ifconfig lo0 127.0.0.5/8 alias
fi
if [[ ! $PATH =~ /Users/dws/checkouts/fping/src ]]; then
echo "# WARNING: must set PATH:"
echo PATH=/Users/dws/checkouts/fping/src:\$PATH
fi

@ -9,11 +9,10 @@ if [ ! -d ci ]; then
fi
autoreconf -i
./configure --enable-ipv4 --enable-ipv6 --prefix=/opt/fping
make CFLAGS="-g -fprofile-arcs -ftest-coverage"
./configure --enable-ipv4 --enable-ipv6 --enable-safe-limits --prefix=/opt/fping
make CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
## setcap currently doesn't work anymore on travis-ci
#sudo setcap cap_net_raw+ep src/fping
#sudo setcap cap_net_raw+ep src/fping6
## setcap debugging:
#pwd
#df -k .
@ -26,6 +25,4 @@ make CFLAGS="-g -fprofile-arcs -ftest-coverage"
# use setuid, since setcap is not available
sudo chown root src/fping
sudo chown root src/fping6
sudo chmod u+s src/fping
sudo chmod u+s src/fping6

@ -1,13 +0,0 @@
#!/bin/sh
set -x
sudo -H pip install cpp-coveralls
cd src
ls -l
gcov *.o
cd ..
coveralls --exclude ci --no-gcov

@ -4,18 +4,6 @@
set -e
# do this only for the gcc run
#if [ "$CC" != "gcc" ]; then
# echo "skipped upload because $CC != gcc"
# exit 0
#fi
# do this only for the master and version3 branch
if [ "$TRAVIS_BRANCH" != "master" -a "$TRAVIS_BRANCH" != "version3" ]; then
echo "skipped upload branch $TRAVIS_BRANCH isn't master/version3"
exit 0
fi
VERSION=$(ls fping-*.tar.gz | sed -e 's/^fping-//' | sed -e 's/\.tar\.gz$//')
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
REPO=release

@ -0,0 +1,16 @@
#!/bin/sh
set -xe
if [ "$TRAVIS_DIST" = "trusty" ]; then
echo "skip coveralls on trusty because coveralls errors out due to python issues"
exit 0
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
pip3 install --user cpp-coveralls
PATH="${PATH}:$(python3 -c 'import site; print(site.USER_BASE)')/bin"
else
pip install --user cpp-coveralls
fi
export COVERALLS_PARALLEL=true
coveralls --build-root src --exclude src/optparse.c --exclude ci --exclude config.h --gcov-options '\-lp'

@ -0,0 +1,25 @@
#!/bin/sh
set -e
COVERITY_SCAN_PROJECT_NAME=schweikert/fping
COVERITY_SCAN_EMAIL=david@schweikert.ch
if [ -z "$COVERITY_SCAN_TOKEN" ]; then
echo "ERROR: COVERITY_SCAN_TOKEN not defined." >&2
exit 1
fi
curl -o /tmp/cov-analysis-linux64.tgz https://scan.coverity.com/download/linux64 \
--form project=$COVERITY_SCAN_PROJECT_NAME --form token=$COVERITY_SCAN_TOKEN
tar xfz /tmp/cov-analysis-linux64.tgz
./autogen.sh
./configure --enable-ipv4 --enable-ipv6 --enable-safe-limits --prefix=/opt/fping
cov-analysis-linux64-*/bin/cov-build --dir cov-int make -j4
tar cfz cov-int.tar.gz cov-int
curl https://scan.coverity.com/builds?project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN \
--form email=$COVERITY_SCAN_EMAIL \
--form file=@cov-int.tar.gz \
--form version="`git rev-parse --short HEAD`" \
--form description="`git rev-parse --short HEAD` / $TRAVIS_BUILD_ID "

@ -1,9 +1,7 @@
#!/bin/bash
sudo setcap cap_net_raw+ep src/fping
sudo setcap cap_net_raw+ep src/fping6
sudo setcap cap_net_raw,cap_net_admin+ep src/fping
if [[ ! $PATH =~ fping/src ]]; then
echo "# WARNING: must set PATH:"
echo PATH=/home/dws/checkouts/fping/src:\$PATH
PATH=/home/dws/checkouts/fping/src:$PATH
fi

@ -0,0 +1,9 @@
#!/bin/sh
lcov -c -no-external \
-d . \
-b src \
-o lcov-all.info
lcov --remove lcov-all.info -o lcov.info \
'*/optparse.c'

@ -0,0 +1,8 @@
#!/bin/sh
set -ex
PATH=`pwd`/src:$PATH
prove ci/test-*.pl
ci/test-tarball.sh

@ -1,6 +1,6 @@
#!/usr/bin/perl -w
use Test::Command tests => 9;
use Test::Command tests => 12;
use Test::More;
# ping 127.0.0.1
@ -14,22 +14,34 @@ use Test::More;
# ping ::1
SKIP: {
#system("/sbin/ifconfig >&2");
if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 3;
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping6 ::1");
my $cmd = Test::Command->new(cmd => "fping ::1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("::1 is alive\n");
$cmd->stderr_is_eq("");
}
# ping ff02::1
SKIP: {
#system("/sbin/ifconfig >&2");
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping ff02::1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("ff02::1 is alive\n");
$cmd->stderr_like(qr{ \[<- .*\]});
}
# ping 3 times 127.0.0.1
{
my $cmd = Test::Command->new(cmd => "fping -p 100 -C3 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[2\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[2\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{127\.0\.0\.1 : 0\.\d+ 0\.\d+ 0\.\d+\n});
$cmd->stderr_like(qr{127\.0\.0\.1 : \d\.\d+ \d\.\d+ \d\.\d+\n});
}

@ -1,68 +1,40 @@
#!/usr/bin/perl -w
use Test::Command tests => 9;
use Test::Command tests => 12;
my $I_HELP = " -I if bind to a particular interface\n";
my $I_HELP = " -I, --iface=IFACE bind to a particular interface\n";
$I_HELP = '' if $^O eq 'darwin';
# fping -h
# fping -h (special pre-parse code path)
my $cmd1 = Test::Command->new(cmd => "fping -h");
$cmd1->exit_is_num(0);
$cmd1->stdout_is_eq(<<END);
$cmd1->stdout_like(qr{Usage: fping \[options\] \[targets\.\.\.\]
Usage: fping [options] [targets...]
-a show targets that are alive
-A show targets by address
-b n amount of ping data to send, in bytes (default 56)
-B f set exponential backoff factor to f
-c n count of pings to send to each target (default 1)
-C n same as -c, report results in verbose format
-D print timestamp before each output line
-e show elapsed time on return packets
-f file read list of targets from a file ( - means stdin) (only if no -g specified)
-g generate target list (only if no -f specified)
(specify the start and end IP in the target list, or supply a IP netmask)
(ex. fping -g 192.168.1.0 192.168.1.255 or fping -g 192.168.1.0/24)
-H n Set the IP TTL value (Time To Live hops)
-i n interval between sending ping packets (in millisec) (default 25)
${I_HELP} -l loop sending pings forever
-m use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A
-M set the Don't Fragment flag
-n show targets by name (-d is equivalent)
-N output compatible for netdata (-l -Q are required)
-o show the accumulated outage time (lost packets * packet interval)
-O n set the type of service (tos) flag on the ICMP packets
-p n interval between ping packets to one target (in millisec)
(in looping and counting modes, default 1000)
-q quiet (don't show per-target/per-ping results)
-Q n same as -q, but show summary every n seconds
-r n number of retries (default 3)
-R random packet data (to foil link data compression)
-s print final stats
-S addr set source address
-t n individual target initial timeout (in millisec) (default 500)
-T n ignored (for compatibility with fping 2.4)
-u show targets that are unreachable
-v show version
targets list of targets to check (if no -f specified)
END
Probing options:
.*
-v, --version show version
}s);
$cmd1->stderr_is_eq("");
# fping -4 -h (normal option parsing code path)
my $cmd4 = Test::Command->new(cmd => "fping -4 -h");
$cmd4->exit_is_num(0);
$cmd4->stdout_like(qr{Usage: fping \[options\] \[targets\.\.\.\]
Probing options:
.*
-v, --version show version
}s);
$cmd4->stderr_is_eq("");
# fping -v
my $cmd2 = Test::Command->new(cmd => "fping -v");
$cmd2->exit_is_num(0);
$cmd2->stdout_like(qr{fping: Version \S+
fping: comments to david\@schweikert\.ch\n});
$cmd2->stdout_like(qr{fping: Version \S+});
$cmd2->stderr_is_eq("");
# fping with unknown option
my $cmd3 = Test::Command->new(cmd => "fping -Z");
$cmd3->exit_is_num(1);
$cmd3->stdout_is_eq("");
if($^O eq 'darwin') {
$cmd3->stderr_is_eq("fping: illegal option -- Z\nsee 'fping -h' for usage information\n");
}
else {
$cmd3->stderr_is_eq("fping: invalid option -- 'Z'\nsee 'fping -h' for usage information\n");
}
$cmd3->stderr_like(qr{^fping: (illegal|invalid) option -- '?Z'?\nsee 'fping -h' for usage information\n$});

@ -1,6 +1,6 @@
#!/usr/bin/perl -w
use Test::Command tests => 24;
use Test::Command tests => 36;
# fping -i 0
my $cmd1 = Test::Command->new(cmd => "fping -i 0 -T10 -g 127.0.0.1/29");
@ -24,7 +24,7 @@ END
my $cmd5 = Test::Command->new(cmd => "fping -H 300 127.0.0.1");
$cmd5->exit_is_num(1);
$cmd5->stdout_is_eq("");
$cmd5->stderr_is_eq("ttl 300 out of range\n");
$cmd5->stderr_is_eq("fping: ttl 300 out of range\n");
# fping -a -u
my $cmd6 = Test::Command->new(cmd => "fping -a -u 127.0.0.1");
@ -38,11 +38,11 @@ $cmd7->exit_is_num(1);
$cmd7->stdout_is_eq("");
$cmd7->stderr_is_eq("fping: specify only one of c, l\n");
# fping -b 65489
my $cmd8 = Test::Command->new(cmd => "fping -b 65489 127.0.0.1");
# fping -b 65509
my $cmd8 = Test::Command->new(cmd => "fping -b 65509 127.0.0.1");
$cmd8->exit_is_num(1);
$cmd8->stdout_is_eq("");
$cmd8->stderr_is_eq("fping: data size 65489 not valid, must be lower than 65488\n");
$cmd8->stderr_is_eq("fping: data size 65509 not valid, must be lower than 65488\n");
# fping -B 0.9
my $cmd9 = Test::Command->new(cmd => "fping -B 0.9 127.0.0.1");
@ -50,9 +50,16 @@ $cmd9->exit_is_num(1);
$cmd9->stdout_is_eq("");
$cmd9->stderr_is_eq("fping: backoff factor 0.9 not valid, must be between 1.0 and 5.0\n");
# fping -B 0.9
# fping -B 5.1
my $cmd10 = Test::Command->new(cmd => "fping -B 5.1 127.0.0.1");
$cmd10->exit_is_num(1);
$cmd10->stdout_is_eq("");
$cmd10->stderr_is_eq("fping: backoff factor 5.1 not valid, must be between 1.0 and 5.0\n");
# non-negative only
for my $arg (qw(i p Q t)) {
my $cmd = Test::Command->new(cmd => "fping -$arg -1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{Usage:});
}

@ -1,14 +1,65 @@
#!/usr/bin/perl -w
use Test::Command tests => 14;
use Test::Command tests => 32;
use Test::More;
use Time::HiRes qw(gettimeofday tv_interval);
# -4 only use IPv4 addresses
# -6 only use IPv6 addresses
# -a show targets that are alive
# -A show targets by address
# -b n amount of ping data to send, in bytes (default 56)
# -B f set exponential backoff factor to f
# fping -4 -6
{
my $cmd = Test::Command->new(cmd => "fping -4 -6 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: can't specify both -4 and -6\n");
}
# fping -6 -4
{
my $cmd = Test::Command->new(cmd => "fping -6 -4 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: can't specify both -4 and -6\n");
}
# fping -4
{
my $cmd = Test::Command->new(cmd => "fping -4 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq("");
}
{
my $cmd = Test::Command->new(cmd => "fping -4 ::1");
$cmd->exit_is_num(2);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{^::1:.*(not supported|not known)});
}
# fping -6
SKIP: {
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping -6 ::1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("::1 is alive\n");
$cmd->stderr_is_eq("");
}
{
my $cmd = Test::Command->new(cmd => "fping -6 127.0.0.1");
$cmd->exit_is_num(2);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{127\.0\.0\.1:.*(not supported|not known)});
}
# fping -a
{
my $cmd = Test::Command->new(cmd => "fping -a 127.0.0.1 127.0.0.2");
@ -19,7 +70,7 @@ $cmd->stderr_is_eq("");
# fping -A
{
my $cmd = Test::Command->new(cmd => "fping -A localhost");
my $cmd = Test::Command->new(cmd => "fping -4 -A localhost");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq("");
@ -34,14 +85,17 @@ $cmd->stderr_is_eq("");
}
# fping -B
{
my $t0 = [gettimeofday];
my $cmd = Test::Command->new(cmd => "fping -t 100 -r 3 -B 2 8.8.8.7");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("8.8.8.7 is unreachable\n");
$cmd->stderr_like(qr{^(|(8.8.8.7: error while sending ping: No route to host\n)+)$});
my $elapsed = tv_interval($t0);
# 0.1 + 0.2 + 0.4 + 0.8 = 1.5
cmp_ok($elapsed, '>=', 1.5);
cmp_ok($elapsed, '<', 1.8);
SKIP: {
if($^O eq 'darwin') {
skip 'timing test not reliable on macOS', 5;
}
my $t0 = [gettimeofday];
my $cmd = Test::Command->new(cmd => "fping -t 100 -r 3 -B 2 8.8.8.7");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("8.8.8.7 is unreachable\n");
$cmd->stderr_like(qr{^(|(8.8.8.7: error while sending ping: No route to host\n)+)$});
my $elapsed = tv_interval($t0);
# 0.1 + 0.2 + 0.4 + 0.8 = 1.5
cmp_ok($elapsed, '>=', 1.5);
cmp_ok($elapsed, '<', 1.9);
}

@ -1,6 +1,6 @@
#!/usr/bin/perl -w
use Test::Command tests => 12;
use Test::Command tests => 51;
# -c n count of pings to send to each target (default 1)
# -C n same as -c, report results in verbose format
@ -9,31 +9,120 @@ use Test::Command tests => 12;
# fping -c n
{
my $cmd = Test::Command->new(cmd => "fping -c 2 -p 100 localhost 127.0.0.1");
my $cmd = Test::Command->new(cmd => "fping -4 -c 2 -p 100 localhost 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
localhost : \[1\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = 0\.\d+/0\.\d+/0\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = 0\.\d+/0\.\d+/0\.\d+
$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -c n -q
{
my $cmd = Test::Command->new(cmd => "fping -q -c 2 -p 100 localhost 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -c n -a (-a is ignored)
{
my $cmd = Test::Command->new(cmd => "fping -a -c 2 -p 100 localhost 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -c n -u (-u is ignored)
{
my $cmd = Test::Command->new(cmd => "fping -u -c 2 -p 100 localhost 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -C n
{
my $cmd = Test::Command->new(cmd => "fping -C 2 -p 100 localhost 127.0.0.1");
my $cmd = Test::Command->new(cmd => "fping -4 -C 2 -p 100 localhost 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
localhost : \[1\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{localhost : 0\.\d+ 0\.\d+
127\.0\.0\.1 : 0\.\d+ 0\.\d+
$cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+
127\.0\.0\.1 : \d\.\d+ \d\.\d+
});
}
# fping -C n -q
{
my $cmd = Test::Command->new(cmd => "fping -C 5 -q -p 100 localhost");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{localhost :( \d\.\d+){5}
});
}
# fping -C n -a (-a is ignored)
{
my $cmd = Test::Command->new(cmd => "fping -a -C 2 -p 100 localhost 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+
127\.0\.0\.1 : \d\.\d+ \d\.\d+
});
}
# fping -C n -u (-u is ignored)
{
my $cmd = Test::Command->new(cmd => "fping -u -C 2 -p 100 localhost 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+
127\.0\.0\.1 : \d\.\d+ \d\.\d+
});
}
# fping -C n -i -q
{
my $cmd = Test::Command->new(cmd => "fping --quiet --interval=1 --vcount=20 --period=50 127.0.0.1 127.0.0.2");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{127\.0\.0\.1 :( \d\.\d+){20}
127\.0\.0\.2 :( \d\.\d+){20}
});
}
@ -41,19 +130,82 @@ $cmd->stderr_like(qr{localhost : 0\.\d+ 0\.\d+
{
my $cmd = Test::Command->new(cmd => "fping -D -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\[\d{10}\.\d+\] 127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
\[\d{10}\.\d+\] 127\.0\.0\.1 : \[1\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
$cmd->stdout_like(qr{\[\d+\.\d+\] 127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
\[\d+\.\d+\] 127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -D (timestamp not before 2001-09-09)
{
my $cmd = Test::Command->new(cmd => "fping -D -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\[[1-9]\d{9,}\.\d+\] 127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
\[[1-9]\d{9,}\.\d+\] 127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -D --timestamp-format=ctime
{
my $cmd = Test::Command->new(cmd => "fping -D --timestamp-format=ctime -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\[\w+\s\w+\s+\d+\s[\d+:]+\s\d+\] 127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
\[\w+\s\w+\s+\d+\s[\d+:]+\s\d+\] 127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -D --timestamp-format=iso
{
my $cmd = Test::Command->new(cmd => "fping -D --timestamp-format=iso -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\[[\d+-]+T[\d+:]+\+\d+\] 127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
\[[\d+-]+T[\d+:]+\+\d+\] 127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = 0\.\d+/0\.\d+/0\.\d+
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -D --timestamp-format=rfc3339
{
my $cmd = Test::Command->new(cmd => "fping -D --timestamp-format=rfc3339 -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\[[\d+-]+\s[\d+:]+\] 127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
\[[\d+-]+\s[\d+:]+\] 127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -D --timestamp-format
{
my $cmd = Test::Command->new(cmd => "fping -D --timestamp-format -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{Usage:});
}
# fping -D --timestamp-format="%Y-%m-%d %H:%M:%S"
{
my $cmd = Test::Command->new(cmd => "fping -D --timestamp-format=\"%Y-%m-%d %H:%M:%S\" -c 2 -p 100 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{Usage:});
}
# fping -e
{
my $cmd = Test::Command->new(cmd => "fping -e 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 is alive \(0\.\d+ ms\)
$cmd->stdout_like(qr{127\.0\.0\.1 is alive \(\d\.\d+ ms\)
});
$cmd->stderr_is_eq("");

@ -1,6 +1,7 @@
#!/usr/bin/perl -w
use Test::Command tests => 24;
use Test::Command tests => 75;
use Test::More;
use File::Temp;
# -f file read list of targets from a file ( - means stdin) (only if no -g specified)
@ -13,6 +14,10 @@ my $tmpfile = File::Temp->new();
print $tmpfile "127.0.0.1\n127.0.0.2\n";
close($tmpfile);
my $tmpfile2 = File::Temp->new();
print $tmpfile2 "# comment\n127.0.0.1\n\n127.0.0.2\n";
close($tmpfile2);
# fping without option (-> equivalent to 'fping -f -')
{
my $cmd = Test::Command->new(cmd => "cat ".$tmpfile->filename." | fping");
@ -37,6 +42,70 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
$cmd->stderr_is_eq("");
}
# fping -f file (with comment and empty line)
{
my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile2->filename);
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
$cmd->stderr_is_eq("");
}
# fping -f non-existing-file (error)
{
my $cmd = Test::Command->new(cmd => "fping -f file-does-not-exist");
$cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{: fopen :});
}
# fping -g (error: no argument)
{
my $cmd = Test::Command->new(cmd => "fping -g");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{^Usage: fping \[options\] \[targets\.\.\.\]});
}
# fping -g (error: single argument, but not in cidr format)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{^Usage: fping \[options\] \[targets\.\.\.\]});
}
# fping -g (error: CIDR network is not an IP address)
{
my $cmd = Test::Command->new(cmd => "fping -g xxx/32");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{can't parse address xxx});
}
# fping -g (error: start of range is not an IP address)
{
my $cmd = Test::Command->new(cmd => "fping -g xxx 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{can't parse address xxx});
}
# fping -g (error: end of range is not an IP address)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1 yyy");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{can't parse address yyy});
}
# fping -g (error: too many arguments)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1 127.0.0.2 127.0.0.3");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{^Usage: fping \[options\] \[targets\.\.\.\]});
}
# fping -g (range)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1 127.0.0.5");
@ -45,6 +114,22 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n127.0.0.3 is alive\n
$cmd->stderr_is_eq("");
}
# fping -g (empty range)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("");
}
# fping -g (too large range)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1 127.255.255.254");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: -g parameter generates too many addresses\n");
}
# fping -g (cidr)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1/30");
@ -53,7 +138,7 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
$cmd->stderr_is_eq("");
}
# fping -g (cidr - long prefixes)
# fping -g (cidr - long prefixes: point-to-point)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/31");
$cmd->exit_is_num(0);
@ -61,12 +146,80 @@ $cmd->stdout_is_eq("127.0.0.2 is alive\n127.0.0.3 is alive\n");
$cmd->stderr_is_eq("");
}
# fping -g (cidr - long prefixes: host)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/32");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.2 is alive\n");
$cmd->stderr_is_eq("");
}
# fping -g (cidr - too long prefixes)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/33");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("Error: netmask must be between 1 and 32 (is: 33)\n");
$cmd->stderr_is_eq("fping: netmask must be between 1 and 32 (is: 33)\n");
}
# fping -g (cidr - too short prefixes)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/0");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: netmask must be between 1 and 32 (is: 0)\n");
}
# fping -g (cidr - too many addresses)
{
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.0/8");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: -g parameter generates too many addresses\n");
}
# fping -g (range - no IPv6 generator)
SKIP: {
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping -6 -g ::1 ::1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: -g works only with IPv4 addresses\n");
}
# fping -g (range - no IPv6 generator - start address IPv6)
SKIP: {
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping -6 -g ::1 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: -g works only with IPv4 addresses\n");
}
# fping -g (range - no IPv6 generator - end address IPv6)
SKIP: {
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping -6 -g 127.0.0.1 ::1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: -g works only with IPv4 addresses\n");
}
# fping -g (CIDR - no IPv6 generator)
SKIP: {
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping -6 -g ::1/128");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: -g works only with IPv4 addresses\n");
}
# fping -H

@ -1,10 +1,11 @@
#!/usr/bin/perl -w
use Test::Command tests => 7;
use Test::Command tests => 15;
use Test::More;
# -i n interval between sending ping packets (in millisec) (default 25)
# -l loop sending pings forever
# -k set fwmark on ping packets
# -m ping multiple interfaces on target host
# -M don't fragment
@ -19,8 +20,55 @@ $cmd->stderr_is_eq("");
# fping -l
{
my $cmd = Test::Command->new(cmd => '(sleep 2; pkill fping)& fping -p 900 -l 127.0.0.1');
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\)
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
}
# fping -k
SKIP: {
if($^O ne 'linux') {
skip '-k option is only supported on Linux', 3;
}
my $cmd = Test::Command->new(cmd => 'sudo env "PATH=$PATH" fping -k 256 127.0.0.1');
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq("");
}
# fping -l with SIGQUIT
{
my $cmd = Test::Command->new(cmd => '(sleep 2; pkill -QUIT fping; sleep 2; pkill fping)& fping -p 900 -l 127.0.0.1');
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[2\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[3\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[4\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = \d+/\d+/\d+%, min/avg/max = \d+\.\d+/\d+\.\d+/\d+\.\d+
});
}
# fping -l -Q
SKIP: {
if($^O eq 'darwin') {
skip 'On macOS, this test is unreliable', 2;
}
my $cmd = Test::Command->new(cmd => '(sleep 2; pkill fping)& fping -p 850 -l -Q 1 127.0.0.1');
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d\d:\d\d:\d\d\]
127\.0\.0\.1 : xmt/rcv/%loss = \d/\d/\d%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
\[\d\d:\d\d:\d\d\]
127\.0\.0\.1 : xmt/rcv/%loss = \d/\d/\d%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -l -t
{
my $cmd = Test::Command->new(cmd => '(sleep 2; pkill fping)& fping -p 900 -t 1500 -l 127.0.0.1');
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\)
});
}

@ -1,6 +1,6 @@
#!/usr/bin/perl -w
use Test::Command tests => 12;
use Test::Command tests => 36;
# -n show targets by name (-d is equivalent)
# -O n set the type of service (tos) flag on the ICMP packets
@ -11,11 +11,32 @@ use Test::Command tests => 12;
# fping -n -> test-14-internet-hosts
# fping -d -n
{
my $cmd = Test::Command->new(cmd => "fping -d -n 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: use either one of -d or -n\n");
}
# fping -n -d
{
my $cmd = Test::Command->new(cmd => "fping -n -d 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: use either one of -d or -n\n");
}
# fping -o
{
my $cmd = Test::Command->new(cmd => "fping -t100 -p 100 -o -c 5 8.8.8.7");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stdout_is_eq("8.8.8.7 : [0], timed out (NaN avg, 100% loss)
8.8.8.7 : [1], timed out (NaN avg, 100% loss)
8.8.8.7 : [2], timed out (NaN avg, 100% loss)
8.8.8.7 : [3], timed out (NaN avg, 100% loss)
8.8.8.7 : [4], timed out (NaN avg, 100% loss)
");
$cmd->stderr_like(qr{^\s*8\.8\.8\.7 : xmt/rcv/%loss = 5/0/100%, outage\(ms\) = 50\d\s*$});
}
@ -32,7 +53,7 @@ $cmd->stderr_is_eq("");
my $cmd = Test::Command->new(cmd => "fping -q -p 100 -c 3 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 0\.\d+/0\.\d+/0\.\d+
$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 3/3/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
@ -42,9 +63,86 @@ my $cmd = Test::Command->new(cmd => "fping -Q 1 -p 400 -c 4 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 0\.\d+/0\.\d+/0\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 4/4/0%, min/avg/max = 0\.\d+/0\.\d+/0\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 3/3/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 4/4/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -Q (longer test to show two time stamps and reset statistics)
{
my $cmd = Test::Command->new(cmd => "fping -Q 1 -p 550 -c 5 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 5/5/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -Q n ignores non-number characters after the number, except for keywords
{
my $cmd = Test::Command->new(cmd => "fping -Q 1whatever -p 550 -c 5 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 5/5/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -Q n ignores unknown keywords
{
my $cmd = Test::Command->new(cmd => "fping -Q 1,not_a_keyword -p 550 -c 5 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 5/5/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -Q n,cumulative
{
my $cmd = Test::Command->new(cmd => "fping -Q 1,cumulative -p 550 -c 5 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
\[\d+:\d+:\d+\]
127\.0\.0\.1 : xmt/rcv/%loss = 4/4/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
127\.0\.0\.1 : xmt/rcv/%loss = 5/5/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}
# fping -Q -o
{
my $cmd = Test::Command->new(cmd => "fping -c4 -Q1 -p550 -o 8.8.8.7");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
8\.8\.8\.7 : xmt/rcv/%loss = 1/0/100%, outage\(ms\) = 55\d
\[\d+:\d+:\d+\]
8\.8\.8\.7 : xmt/rcv/%loss = 2/0/100%, outage\(ms\) = 110\d
8\.8\.8\.7 : xmt/rcv/%loss = 4/0/100%, outage\(ms\) = 220\d
});
}
# fping -Q n,cumulative -o
{
my $cmd = Test::Command->new(cmd => "fping -c4 -Q1,cumulative -p550 -o 8.8.8.7");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{\[\d+:\d+:\d+\]
8\.8\.8\.7 : xmt/rcv/%loss = 1/0/100%, outage\(ms\) = 55\d
\[\d+:\d+:\d+\]
8\.8\.8\.7 : xmt/rcv/%loss = 3/0/100%, outage\(ms\) = 165\d
8\.8\.8\.7 : xmt/rcv/%loss = 4/0/100%, outage\(ms\) = 220\d
});
}

@ -1,6 +1,6 @@
#!/usr/bin/perl -w
use Test::Command tests => 18;
use Test::Command tests => 27;
use Test::More;
# -R random bytes
@ -19,10 +19,10 @@ $cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 3/3/0%.*});
}
SKIP: {
if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 3;
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping6 -q -R -c3 -p100 ::1");
my $cmd = Test::Command->new(cmd => "fping -q -R -c3 -p100 ::1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{::1 : xmt/rcv/%loss = 3/3/0%.*});
@ -46,10 +46,10 @@ $cmd->stderr_like(qr{\s*
\s*1 ICMP Echo Replies received
\s*0 other ICMP received
\s*0.\d+ ms \(min round trip time\)
\s*0.\d+ ms \(avg round trip time\)
\s*0.\d+ ms \(max round trip time\)
\s*0.\d+ sec \(elapsed real time\)
\s*\d\.\d+ ms \(min round trip time\)
\s*\d\.\d+ ms \(avg round trip time\)
\s*\d\.\d+ ms \(max round trip time\)
\s*\d\.\d+ sec \(elapsed real time\)
});
}
@ -69,10 +69,10 @@ $cmd->stderr_like(qr{\s*
\s*0 ICMP Echo Replies received
\s*0 other ICMP received
\s*0.\d+ ms \(min round trip time\)
\s*0.\d+ ms \(avg round trip time\)
\s*0.\d+ ms \(max round trip time\)
\s*0.\d+ sec \(elapsed real time\)
\s*\d\.\d+ ms \(min round trip time\)
\s*\d\.\d+ ms \(avg round trip time\)
\s*\d\.\d+ ms \(max round trip time\)
\s*\d\.\d+ sec \(elapsed real time\)
});
}
@ -84,15 +84,42 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq("");
}
# fping6 -S
# fping -S (wrong source address)
{
my $cmd = Test::Command->new(cmd => "fping -S 192.0.2.47 127.0.0.1");
$cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{fping: cannot bind source address : .+\n});
}
# fping -S
SKIP: {
if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 3;
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping6 -S ::1 ::1");
my $cmd = Test::Command->new(cmd => "fping -S ::1 ::1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("::1 is alive\n");
$cmd->stderr_is_eq("");
}
# fping -t tested in test-4-options-a-b.pl
# fping -S (wrong IPv6 source address)
SKIP: {
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping -S 2001:db8::1 ::1");
$cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{fping: cannot bind source address : .+\n});
}
# fping -S
{
my $cmd = Test::Command->new(cmd => "fping -S bla");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_is_eq("fping: can't parse source address: bla\n");
}
# (note: fping -t also tested in test-4-options-a-b.pl)

@ -1,24 +0,0 @@
#!/usr/bin/perl -w
use Test::Command tests => 6;
# -u show targets that are unreachable
# -v show version
# fping -u
{
my $cmd = Test::Command->new(cmd => "fping -r0 -u 8.8.0.0 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("8.8.0.0\n");
$cmd->stderr_is_eq("");
}
# fping -v
{
my $cmd = Test::Command->new(cmd => "fping -v");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{ping: Version 3\.\d+(-rc\d+)?
fping: comments to david\@schweikert\.ch
});
$cmd->stderr_is_eq("");
}

@ -0,0 +1,48 @@
#!/usr/bin/perl -w
use Test::Command tests => 15;
# -u show targets that are unreachable
# -v show version
# -x shows if >=N hosts are reachable or not
# -X exits true immediately when N hosts are found
# fping -u
{
my $cmd = Test::Command->new(cmd => "fping -r0 -u 8.8.0.0 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("8.8.0.0\n");
$cmd->stderr_is_eq("");
}
# fping -v
{
my $cmd = Test::Command->new(cmd => "fping -v");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{ping: Version [45]\.\d+(-rc\d+)?});
$cmd->stderr_is_eq("");
}
# fping -x
{
my $cmd = Test::Command->new(cmd => "fping -x 1 8.8.0.0 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("Enough hosts reachable (required: 1, reachable: 1)\n");
$cmd->stderr_is_eq("");
}
# fping -x
{
my $cmd = Test::Command->new(cmd => "fping -x 2 8.8.0.0 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("Not enough hosts reachable (required: 2, reachable: 1)\n");
$cmd->stderr_is_eq("");
}
# fping -X
{
my $cmd = Test::Command->new(cmd => "fping -X 1 --generate 127.0.0.0/29");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("Enough hosts reachable (required: 1, reachable: 1)\n");
$cmd->stderr_is_eq("");
}

@ -1,32 +0,0 @@
#!/usr/bin/perl -w
use Test::Command;
use Test::More;
if( $^O eq 'darwin' ) {
plan skip_all => 'Test irrelevant on MacOS';
exit 0;
}
plan tests => 6;
# run without privileges
my $fping_bin = `which fping`; chomp $fping_bin;
my $fping6_bin = `which fping6`; chomp $fping6_bin;
system("cp $fping_bin /tmp/fping.copy; chmod +x /tmp/fping.copy");
system("cp $fping6_bin /tmp/fping6.copy; chmod +x /tmp/fping6.copy");
# fping
{
my $cmd = Test::Command->new(cmd => "/tmp/fping.copy 127.0.0.1");
$cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{: can't create socket \(must run as root\?\) : .*\n});
}
# fping6
{
my $cmd = Test::Command->new(cmd => "/tmp/fping6.copy ::1");
$cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{: can't create raw socket \(must run as root\?\) : .*\n});
}

@ -0,0 +1,57 @@
#!/usr/bin/perl -w
use English;
use Test::Command;
use Test::More;
if( $^O eq 'darwin' ) {
plan skip_all => 'Test irrelevant on MacOS';
exit 0;
}
sub get_ping_gid_range {
open FD, "/proc/sys/net/ipv4/ping_group_range" or return undef;
chomp(my $line = <FD>);
my @range = split(/\s+/, $line);
close FD;
return @range;
}
my @gids = split(' ', $EGID);
my @allowed = get_ping_gid_range();
# Make a copy of the binary so that we get rid of setuid bit
my $fping_bin = `which fping`; chomp $fping_bin;
system("cp $fping_bin /tmp/fping.copy; chmod +x /tmp/fping.copy");
# Determine what test to run, based on whether unprivileged
# pings are allowed.
if(scalar grep { $_ >= $allowed[0] && $_ <= $allowed[1] } @gids) {
diag('test unprivileged mode');
test_unprivileged_works();
}
else {
test_privileged_fails();
}
sub test_unprivileged_works {
plan tests => 3;
{
my $cmd = Test::Command->new(cmd => "fping 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq("");
}
}
sub test_privileged_fails {
plan tests => 3;
{
my $cmd = Test::Command->new(cmd => "/tmp/fping.copy 127.0.0.1");
$cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{: can't create socket \(must run as root\?\)});
}
}

@ -1,10 +1,27 @@
#!/usr/bin/perl -w
use Test::Command tests => 33;
use Test::Command tests => 84;
use Test::More;
for my $arg (qw(b B c C H i O p Q r t)) {
my $cmd = Test::Command->new(cmd => "fping -$arg xxx");
# some options require a numeric argument
for my $arg (qw(b B c C H i O p Q r t x X)) {
for my $test_input (qw(xxx '')) {
my $cmd = Test::Command->new(cmd => "fping -$arg $test_input");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{Usage:});
}
}
# fping -k, only supported on Linux, requires a number
SKIP: {
if($^O ne 'linux') {
skip '-k option is only supported on Linux', 6;
}
for my $test_input (qw(xxx '')) {
my $cmd = Test::Command->new(cmd => "fping -k $test_input 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{Usage:});
}
}

@ -1,6 +1,6 @@
#!/usr/bin/perl -w
use Test::Command tests => 6;
use Test::Command tests => 3;
# fping
{
@ -9,11 +9,3 @@ $cmd->exit_is_num(2);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{^nosuchname\.example\.com: .*not (known|found)});
}
# fping6
{
my $cmd = Test::Command->new(cmd => "fping6 nosuchname.example.com");
$cmd->exit_is_num(2);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{^nosuchname\.example\.com: .*not (known|found)});
}

@ -9,19 +9,18 @@ if(!gethostbyname("www.google.com")) {
exit 0;
}
plan tests => 18;
plan tests => 30;
my $re_num = qr{\d+(?:\.\d+)?};
# fping
{
my $cmd = Test::Command->new(cmd => "fping -q -i 10 -p 20 -c 3 -t200 8.8.8.8 4.2.2.5 www.france-telecom.fr www.google.com");
my $cmd = Test::Command->new(cmd => "fping -q -i 10 -p 20 -c 3 -t200 8.8.8.8 www.france-telecom.fr www.google.com");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{8\.8\.8\.8\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num
4\.2\.2\.5\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num
www\.france-telecom\.fr\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num
www\.google\.com\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num
$cmd->stderr_like(qr{8\.8\.8\.8\s*: xmt/rcv/%loss = [123]/[123]/\d+%, min/avg/max = $re_num/$re_num/$re_num
www\.france-telecom\.fr\s*: xmt/rcv/%loss = [123]/[123]/\d+%, min/avg/max = $re_num/$re_num/$re_num
www\.google\.com\s*: xmt/rcv/%loss = [123]/[123]/\d+%, min/avg/max = $re_num/$re_num/$re_num
});
}
@ -29,45 +28,69 @@ www\.google\.com\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num
{
my $cmd = Test::Command->new(cmd => "fping -A -n 8.8.8.8");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("google-public-dns-a.google.com (8.8.8.8) is alive\n");
$cmd->stdout_is_eq("dns.google (8.8.8.8) is alive\n");
$cmd->stderr_is_eq("");
}
# fping -A -n
# fping -4 -A -n
{
my $cmd = Test::Command->new(cmd => "fping -4 -A -n dns.google");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{^dns.google \(8\.8\.(4\.4|8\.8)\) is alive\n$});
$cmd->stderr_is_eq("");
}
# fping -4 --addr --rdns
{
my $cmd = Test::Command->new(cmd => "fping -4 --addr --rdns www.apple.com");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{^\S+\.akamaitechnologies\.com \(\d+\.\d+\.\d+\.\d+\) is alive\n$});
$cmd->stderr_is_eq("");
}
# fping -4 --addr --name
{
my $cmd = Test::Command->new(cmd => "fping -A -n google-public-dns-a.google.com");
my $cmd = Test::Command->new(cmd => "fping -4 --addr --name www.google.com");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("google-public-dns-a.google.com (8.8.8.8) is alive\n");
$cmd->stdout_like(qr{^www\.google\.com \(\d+\.\d+\.\d+\.\d+\) is alive\n$});
$cmd->stderr_is_eq("");
}
# fping6 -A -n
# fping -A -n (IPv6)
SKIP: {
if(system("/sbin/ifconfig | grep inet6.*Scope:Global") != 0) {
skip 'No IPv6 on this host', 3;
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping6 -n -A 2001:4860:4860::8888");
my $cmd = Test::Command->new(cmd => "fping -6 -n -A dns.google");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("google-public-dns-a.google.com (2001:4860:4860::8888) is alive\n");
$cmd->stdout_like(qr{^dns.google \(2001:4860:4860::88(44|88)\) is alive\n$});
$cmd->stderr_is_eq("");
}
# fping -m
#SKIP: {
# if(system("/sbin/ifconfig | grep inet6.*Scope:Global") != 0) {
# skip 'No IPv6 on this host', 3;
# }
# my $cmd = Test::Command->new(cmd => "fping -A -m google-public-dns-a.google.com");
# $cmd->exit_is_num(0);
# $cmd->stdout_is_eq("2001:4860:4860::8888 is alive\n8.8.8.8 is alive\n");
# $cmd->stderr_is_eq("");
#}
SKIP: {
if($ENV{SKIP_IPV6}) {
skip 'Skip IPv6 tests', 3;
}
my $cmd = Test::Command->new(cmd => "fping -A -m dns.google");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{^.* is alive\n.* is alive\n.* is alive\n.* is alive\n});
$cmd->stderr_is_eq("");
}
# fping -m -A
{
my $cmd = Test::Command->new(cmd => "fping -4 -A -m www.cloudflare.com");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{\d+\.\d+\.\d+\.\d+ is alive\n\d+\.\d+\.\d+\.\d+ is alive\n});
$cmd->stderr_is_eq("");
}
# fping -n
{
my $cmd = Test::Command->new(cmd => "fping -n 8.8.8.8");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n");
$cmd->stdout_is_eq("dns.google is alive\n");
$cmd->stderr_is_eq("");
}

@ -9,27 +9,27 @@ plan tests => 3;
{
my $cmd = Test::Command->new(cmd => "fping -c 2 -Q 1 -N 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{CHART fping\.127_0_0_1_packets '' 'FPing Packets for host 127\.0\.0\.1' packets '127_0_0_1' fping\.packets line 110020 1
$cmd->stdout_like(qr{CHART fping\.127_0_0_1_packets '' 'FPing Packets' packets '127.0.0.1' fping\.packets line 110020 1
DIMENSION xmt sent absolute 1 1
DIMENSION rcv received absolute 1 1
BEGIN fping\.127_0_0_1_packets
SET xmt = 1
SET rcv = 1
END
CHART fping\.127_0_0_1_quality '' 'FPing Quality for host 127\.0\.0\.1' percentage '127_0_0_1' fping\.quality area 110010 1
CHART fping\.127_0_0_1_quality '' 'FPing Quality' percentage '127.0.0.1' fping\.quality area 110010 1
DIMENSION returned '' absolute 1 1
BEGIN fping\.127_0_0_1_quality
SET returned = 100
END
CHART fping\.127_0_0_1_latency '' 'FPing Latency for host 127\.0\.0\.1' ms '127_0_0_1' fping\.latency area 110000 1
DIMENSION min minimum absolute 10 1000
DIMENSION max maximum absolute 10 1000
DIMENSION avg average absolute 10 1000
CHART fping\.127_0_0_1_latency '' 'FPing Latency' ms '127.0.0.1' fping\.latency area 110000 1
DIMENSION min minimum absolute 1 1000000
DIMENSION max maximum absolute 1 1000000
DIMENSION avg average absolute 1 1000000
BEGIN fping\.127_0_0_1_latency
SET min = \d{1,2}
SET avg = \d{1,2}
SET max = \d{1,2}
SET min = \d+
SET avg = \d+
SET max = \d+
END}
);
$cmd->stderr_like(qr{127.0.0.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = 0.\d+/0.\d+/0.\d+});
$cmd->stderr_like(qr{127.0.0.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+});
}

@ -7,4 +7,4 @@ use Test::Command tests => 3;
my $cmd1 = Test::Command->new(cmd => "fping -a -g 2001:db8:120:4161::4/64");
$cmd1->exit_is_num(1);
$cmd1->stdout_is_eq("");
$cmd1->stderr_is_eq("Error: -g works only with IPv4 addresses\n");
$cmd1->stderr_is_eq("fping: -g works only with IPv4 addresses\n");

@ -6,6 +6,11 @@
set -e
set -x
# skip on macos
if [[ "$OSTYPE" == "darwin"* ]]; then
exit 0
fi
make dist
VERSION=$(ls fping-*.tar.gz | sed -e 's/^fping-//' | sed -e 's/\.tar\.gz$//')
if [ -z "$VERSION" ]; then

@ -3,43 +3,75 @@ dnl Process this file with autoconf to produce a configure script.
dnl Minimum Autoconf version required.
AC_PREREQ(2.59)
AC_INIT([fping],[3.16])
AC_INIT([fping],[5.2])
dnl make ipv4 and ipv6 options
m4_ifdef([AC_AUTOCONF_VERSION],[AC_USE_SYSTEM_EXTENSIONS], [AC_GNU_SOURCE])
# Detect Operatingsystem
AC_CANONICAL_TARGET
only_clock_realtime=no
case "${target}" in
*darwin*)
only_clock_realtime=yes
;;
*freebsd*)
only_clock_realtime=yes
;;
*openbsd*)
only_clock_realtime=yes
;;
esac
dnl --disable-ipv4
AC_ARG_ENABLE([ipv4],
[ --enable-ipv4 Build IPv4 capable fping],
[case "${enableval}" in
yes) ipv4=true ;;
no) ipv4=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-ipv4]) ;;
esac],[ipv4=true])
AM_CONDITIONAL([IPV4], [test x$ipv4 = xtrue])
AS_HELP_STRING([--disable-ipv4], [Disable support for pinging IPv4 hosts]))
AM_CONDITIONAL([IPV4], [test "x$enable_ipv4" != "xno"])
AM_COND_IF([IPV4], [AC_DEFINE([IPV4], [1], [IPv4 enabled])])
dnl --disable-ipv6
AC_ARG_ENABLE([ipv6],
[ --enable-ipv6 Build IPv6 capable fping6],
[case "${enableval}" in
yes) ipv6=true ;;
no) ipv6=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-ipv6]) ;;
esac],[ipv6=false])
AM_CONDITIONAL([IPV6], [test x$ipv6 = xtrue])
if test x$ipv4 = xfalse && test x$ipv6 = xfalse; then
AC_MSG_ERROR([You must enable at least one of IPv4 and IPv6.])
fi
AS_HELP_STRING([--disable-ipv6], [Disable support for pinging IPv6 hosts]))
AS_IF([test "x$enable_ipv6" != "xno"], [
dnl Test if IPv6 is supported
AC_CHECK_HEADERS([netinet/icmp6.h], [have_ipv6="yes"], [], [[
#include <netinet/in.h>
#include <sys/types.h>
]])
])
dnl Can't disable both IPv4 and IPv6
AS_IF([test "x$enable_ipv4" = "xno" -a "x$enable_ipv6" = "xno"], [
AC_MSG_ERROR([Need to enable IPv4 or IPv6. Can't disable both!)])
])
dnl IPv6 required, but not supported?
AS_IF([test \( "x$enable_ipv6" = "xyes" -o "x$enable_ipv4" = "xno" \) -a "x$have_ipv6" != "xyes" ], [
AC_MSG_ERROR([IPv6 not supported on this platform (netinet/icmp6.h header not found)])
])
AM_CONDITIONAL([IPV6], [test "x$have_ipv6" = "xyes"])
AM_COND_IF([IPV6], [AC_DEFINE([IPV6], [1], [IPv6 enabled])])
AC_ARG_ENABLE([timestamp],
AS_HELP_STRING([--disable-timestamp], [Disable kernel-based packet timestaping (SO_TIMESTAMP)]))
AS_HELP_STRING([--disable-timestamp], [Disable kernel-based packet timestaping (SO_TIMESTAMPNS)]))
AS_IF([test "x$enable_timestamp" != "xno"], [
AC_CHECK_DECL([SO_TIMESTAMP], [AC_DEFINE(HAVE_SO_TIMESTAMP, [1], [set define])], [have_so_timestamp="no"], [#include <sys/types.h>
AC_CHECK_DECL([SO_TIMESTAMPNS], [AC_DEFINE(HAVE_SO_TIMESTAMPNS, [1], [SO_TIMESTAMPNS is defined])], [have_so_timestamp="no"], [#include <sys/types.h>
#include <sys/socket.h>])
])
dnl Test if --enable-timestamp is explicitely enabled and make an error if this platform doesn't support it
AS_IF([test "x$enable_timestamp" = "xyes" -a "x$have_so_timestamp" = "xno"], [
AC_MSG_ERROR([--enable-timestamp not supported on this platform])
])
AS_IF([test "x$only_clock_realtime" = "xyes"], [AC_DEFINE(ONLY_CLOCK_REALTIME, [1], [ONLY_CLOCK_REALTIME is defined])])
AC_ARG_ENABLE([safe-limits],
AS_HELP_STRING([--enable-safe-limits], [Restrict timing parameters (-i, -p) within "safe" limits]))
AS_IF([test "x$enable_safe_limits" = "xyes"], [
AC_DEFINE(FPING_SAFE_LIMITS, [1], [safe limits should be enforced])])
AC_ARG_ENABLE([debug],
AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=no@:>@]), [enable_debug=$enableval], [enable_debug=no])
AS_IF([test "x$enable_debug" = "xyes"], [
AC_DEFINE([DEBUG], [1], [Define if debugging is enabled])])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_MAINTAINER_MODE
@ -49,6 +81,7 @@ dnl Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
m4_version_prereq([2.70],,[AC_PROG_CC_STDC])
AC_PROG_CPP
AC_PROG_INSTALL
@ -62,6 +95,13 @@ AC_CHECK_FUNC(connect)
if test $ac_cv_func_connect = no; then
AC_CHECK_LIB(socket, connect)
fi
AC_CHECK_FUNC(sigaction)
if test $ac_cv_func_sigaction = yes; then
AC_DEFINE([USE_SIGACTION],[1],[Define if sigaction is available.])
fi
AC_CHECK_FUNCS([strftime], [],
[AC_MSG_ERROR([strftime function is required but not found])])
AH_TOP([
#ifndef CONFIG_H
@ -80,7 +120,7 @@ AH_BOTTOM([
])
dnl Checks for header files.
AC_CHECK_HEADERS(unistd.h sys/file.h stdlib.h sys/select.h getopt.h)
AC_CHECK_HEADERS([unistd.h sys/file.h stdlib.h sys/select.h])
AC_CONFIG_FILES([Makefile
doc/Makefile

@ -0,0 +1,16 @@
FROM ubuntu:20.04
# Base
RUN apt-get update && apt-get install -y \
build-essential \
automake \
m4
# Add source code
COPY ./ /app
# Compile
WORKDIR /app
RUN autoreconf --install
RUN ./configure && make && make install
ENTRYPOINT ["fping"]

@ -1,8 +1,8 @@
Summary: send ICMP echo probes to multiple hosts
Name: fping
Version: 3.4
Version: 4.2
Release: 1
License: BSD with advertising
License: Freely redistributable without restriction
Group: Applications/System
Source0: http://fping.org/dist/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
@ -47,14 +47,15 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root,-)
%attr(4755, root, root) /usr/sbin/fping
%attr(4755, root, root) /usr/sbin/fping6
%doc README COPYING ChangeLog
%doc README.md COPYING CHANGELOG.md
/usr/share/man/man8/fping.8.gz
/usr/share/man/man8/fping6.8.gz
%post
if [ -x /usr/sbin/setcap ]; then
/bin/chmod 0755 /usr/sbin/fping*
/usr/sbin/setcap cap_net_raw+ep /usr/sbin/fping*
/usr/sbin/setcap cap_net_raw,cap_net_admin+ep /usr/sbin/fping
/usr/sbin/setcap cap_net_raw,cap_net_admin+ep /usr/sbin/fping6
fi
%changelog

@ -1,7 +1,3 @@
Unreleased (version 3 branch)
* Fix portability issue with GNU Hurd
* Fix C89 portability issue
2017-02-09 David Schweikert <david@schweikert.ch>
* Version 3.16
* (feature) Support kernel-timestamping of received packets (#46)

@ -1,17 +1,6 @@
man_MANS =
man_MANS = fping.8
if IPV4
man_MANS += fping.8
endif
if IPV6
man_MANS += fping6.8
endif
EXTRA_DIST = fping.8 fping6.8 fping.pod README.1992
EXTRA_DIST = fping.8 fping.pod README.1992 CHANGELOG.pre-v4
fping.8: fping.pod
pod2man -c "" -s 8 -r "fping" $< >$@
fping6.8: fping.pod
pod2man -c "" -s 8 -r "fping" -n fping6 $< >$@

@ -5,7 +5,6 @@ fping - send ICMP ECHO_REQUEST packets to network hosts
=head1 SYNOPSIS
B<fping> [ I<options> ] [ I<systems...> ]
B<fping6> [ I<options> ] [ I<systems...> ]
=head1 DESCRIPTION
@ -20,25 +19,31 @@ of targets to check; if a target does not respond within a certain time limit
and/or retry limit it is designated as unreachable. B<fping> also supports
sending a specified number of pings to a target, or looping indefinitely (as in
B<ping> ). Unlike B<ping>, B<fping> is meant to be used in scripts, so its
output is designed to be easy to parse.
The binary named B<fping6> is the same as B<fping>, except that it uses IPv6
addresses instead of IPv4.
output is designed to be easy to parse. Current statistics can be obtained without
termination of process with signal SIGQUIT (^\ from the keyboard on most systems).
=head1 OPTIONS
=over 5
=item B<-a>
=item B<-4>, B<--ipv4>
Restrict name resolution and IPs to IPv4 addresses.
=item B<-6>, B<--ipv6>
Restrict name resolution and IPs to IPv6 addresses.
=item B<-a>, B<--alive>
Show systems that are alive.
=item B<-A>
=item B<-A>, B<--addr>
Display targets by address rather than DNS name. Combined with -d, the output
will be both the ip and (if available) the hostname.
=item B<-b> I<n>
=item B<-b>, B<--size>=I<BYTES>
Number of bytes of ping data to send. The minimum size (normally 12) allows
room for the data that B<fping> needs to do its work (sequence number,
@ -48,7 +53,7 @@ Default is 56, as in B<ping>. Maximum is the theoretical maximum IP datagram
size (64K), though most systems limit this to a smaller, system-dependent
number.
=item B<-B> I<n>
=item B<-B>, B<--backoff>=I<N>
Backoff factor. In the default mode, B<fping> sends several requests to a
target before giving up, waiting longer for a reply on each successive request.
@ -56,46 +61,57 @@ This parameter is the value by which the wait time (B<-t>) is multiplied on each
successive request; it must be entered as a floating-point number (x.y). The
default is 1.5.
=item B<-c> I<n>
=item B<-c>, B<--count>=I<N>
Number of request packets to send to each target. In this mode, a line is
displayed for each received response (this can suppressed with B<-q> or B<-Q>).
Also, statistics about responses for each target are displayed when all
requests have been sent (or when interrupted).
requests have been sent (or when interrupted). This option overrides B<-a>
or B<-u>.
=item B<-C> I<n>
=item B<-C>, B<--vcount>=I<N>
Similar to B<-c>, but the per-target statistics are displayed in a format
designed for automated response-time statistics gathering. For example:
% fping -C 5 -q somehost
$ fping -C 5 -q somehost
somehost : 91.7 37.0 29.2 - 36.8
shows the response time in milliseconds for each of the five requests, with the
C<-> indicating that no response was received to the fourth request.
C<-> indicating that no response was received to the fourth request. This
option overrides B<-a> or B<-u>.
=item B<-d>
=item B<-d>, B<--rdns>
Use DNS to lookup address of return ping packet. This allows you to give fping
a list of IP addresses as input and print hostnames in the output.
Use DNS to lookup address of ping target. This allows you to give fping
a list of IP addresses as input and print hostnames in the output. This is similar
to option B<-n>/B<--name>, but will force a reverse-DNS lookup even if you give
hostnames as target (NAME->IP->NAME).
=item B<-D>
=item B<-D>, B<--timestamp>
Add Unix timestamps in front of output lines generated with in looping or counting
modes (B<-l>, B<-c>, or B<-C>).
=item B<-e>
Subcommand: B<--timestamp-format>=I<ctime|iso|rfc3339>
Show elapsed (round-trip) time of packets.
Allow to change the timestamp format of the B<-D> option to the following format types.
=item B<-f>
I<ctime> = "%c" (Example: Mon Jun 10 07:50:00 2024)
Read list of targets from a file. This option can only be used by the root
user. Regular users should pipe in the file via stdin:
I<iso> = "%Y-%m-%dT%T%z" (Example: 2024-06-10T07:50:00+0200)
% fping < targets_file
I<rfc3339> = "%Y-%m-%d %H:%M:%S" (Example: 2024-06-10 07:50:00)
=item B<-g> I<addr/mask>
=item B<-e>, B<--elapsed>
Show elapsed (round-trip) time of packets.
=item B<-f>, B<--file>
Read list of targets from a file.
=item B<-g>, B<--generate> I<addr/mask>
Generate a target list from a supplied IP netmask, or a starting and ending IP.
Specify the netmask or start/end in the targets portion of the command line. If
@ -103,123 +119,147 @@ a network with netmask is given, the network and broadcast addresses will be
excluded. ex. To ping the network 192.168.1.0/24, the specified command line
could look like either:
fping -g 192.168.1.0/24
$ fping -g 192.168.1.0/24
or
fping -g 192.168.1.1 192.168.1.254
$ fping -g 192.168.1.1 192.168.1.254
=item B<-h>
=item B<-h>, B<--help>
Print usage message.
=item B<-i> I<n>
=item B<-H>, B<--ttl>=I<N>
Set the IP TTL field (time to live hops).
=item B<-i>, B<--interval>=I<MSEC>
The minimum amount of time (in milliseconds) between sending a ping packet
to any target (default is 25, minimum is 1).
to any target (default is 10, minimum is 1).
=item B<-I>, B<--iface>=I<IFACE>
Set the interface (requires SO_BINDTODEVICE support).
=item B<-k>, B<--fwmark>=I<FWMARK>
Set FWMARK on ping packets for policy-based routing. Requires Linux kernel
2.6.25<=, and root privileges or cap_net_admin.
=item B<-l>
=item B<-l>, B<--loop>
Loop sending packets to each target indefinitely. Can be interrupted with
Ctrl-C; statistics about responses for each target are then displayed.
=item B<-m>
=item B<-m>, B<--all>
Send pings to each of a target host's multiple IP addresses (use of option '-A'
is recommended).
=item B<-M>
=item B<-M>, B<--dontfrag>
Set the "Don't Fragment" bit in the IP header (used to determine/test the MTU).
=item B<-n>
=item B<-n>, B<--name>
Same as -d.
If targets are specified as IP addresses, do a reverse-DNS lookup on them
to print hostnames in the output.
=item B<-N>
=item B<-N>, B<--netdata>
Format output for netdata (-l -Q are required). See: L<http://my-netdata.io/>
Format output for netdata (-l -Q are required). See: L<https://netdata.cloud/>
=item B<-o>
=item B<-o>, B<--outage>
Calculate "outage time" based on the number of lost pings and the interval used (useful for network convergence tests).
=item B<-O> I<n>
=item B<-O>, B<--tos>=I<N>
Set the typ of service flag (TOS). I<n> can be either decimal or hexadecimal
Set the typ of service flag (TOS). I<N> can be either decimal or hexadecimal
(0xh) format.
=item B<-p> <n>
=item B<-p>, B<--period>=I<MSEC>
In looping or counting modes (B<-l>, B<-c>, or B<-C>), this parameter sets
the time in milliseconds that B<fping> waits between successive packets to
an individual target. Default is 1000 and minimum is 10.
=item B<-q>
=item B<-q>, B<--quiet>
Quiet. Don't show per-probe results, but only the final summary. Also don't
show ICMP error messages.
=item B<-Q> I<n>
=item B<-Q>, B<--squiet>=I<SECS[,cumulative]>
Like B<-q>, but show summary results every n seconds.
Like B<-q>, but additionally show interval summary results every I<SECS>
seconds. With I<cumulative>, show summary results since start instead of
for the last interval, unless option B<-N> is used, too.
=item B<-r> I<n>
=item B<-r>, B<--retry>=I<N>
Retry limit (default 3). This is the number of times an attempt at pinging
a target will be made, not including the first try.
=item B<-R>
=item B<-R>, B<--random>
Instead of using all-zeros as the packet data, generate random bytes.
Use to defeat, e.g., link data compression.
=item B<-s>
=item B<-s>, B<--stats>
Print cumulative statistics upon exit.
=item B<-S> I<addr>
=item B<-S>, B<--src>=I<addr>
Set source address.
=item B<-I> I<if>
=item B<-t>, B<--timeout>=I<MSEC>
Set the interface (requires SO_BINDTODEVICE support)
Initial target timeout in milliseconds. In the default, non-loop mode, the
default timeout is 500ms, and it represents the amount of time that B<fping>
waits for a response to its first request. Successive timeouts are multiplied
by the backoff factor specified with B<-B>.
=item B<-t> I<n>
In loop/count mode, the default timeout is automatically adjusted to match
the "period" value (but not more than 2000ms). You can still adjust the timeout
value with this option, if you wish to, but note that setting a value larger
than "period" produces inconsistent results, because the timeout value can
be respected only for the last ping.
Initial target timeout in milliseconds (default 500). In the default mode, this
is the amount of time that B<fping> waits for a response to its first request.
Successive timeouts are multiplied by the backoff factor specified with B<-B>.
Note that this option has no effect looping or counting modes (B<-l>, B<-c>, or
B<-C>).
Also note that any received replies that are larger than the timeout value, will
be discarded.
=item B<-T> I<n>
Ignored (for compatibility with fping 2.4).
=item B<-u>
=item B<-u>, B<--unreach>
Show targets that are unreachable.
=item B<-v>
=item B<-v>, B<--version>
Print B<fping> version information.
=item B<-H> I<n>
=item B<-x>, B<--reachable>=I<N>
Set the IP TTL field (time to live hops).
Given a list of hosts, this mode checks if number of reachable hosts is >= N
and exits true in that case.
=item B<-X>, B<--fast-reachable>=I<N>
Given a list of hosts, this mode immediately exits true once N alive hosts
have been found.
=back
=head1 EXAMPLES
Generate ~1000 pings per second to a host until canceled, printing statistics
on the fly at one second intervals, and printing statistics at the end:
Generate 20 pings to two hosts in ca. 1 second (i.e. one ping every 50 ms to
each host), and report every ping RTT at the end:
# fping -s -l -i 1 -p 1 -T 1 -Q 1 127.0.0.1
Note that ping intervals less than 1ms can only be used as root.
$ fping --quiet --interval=1 --vcount=20 --period=50 127.0.0.1 127.0.0.2
=head1 AUTHORS
@ -247,14 +287,19 @@ B<fping website: L<http://www.fping.org>>
=head1 DIAGNOSTICS
Exit status is 0 if all the hosts are reachable, 1 if some hosts
Exit status is 0 if all the hosts (or the number of hosts specified with B<-x>
or B<-X>) are reachable, 1 if some (or too many with B<-x> or B<-X>) hosts
were unreachable, 2 if any IP addresses were not found, 3 for invalid command
line arguments, and 4 for a system call failure.
=head1 RESTRICTIONS
In order to avoid users mistakingly flooding the network, the following values
are not allowed for non-root users:
The number of addresses that can be generated using the C<-g>, C<--generate>
option is limited to 131070 (the number of host addresses in one 15-bit IPv4
prefix).
If fping was configured with C<--enable-safe-limits>, the following values are
not allowed for non-root users:
=over 4

@ -1,2 +1,3 @@
BasedOnStyle: WebKit
BreakBeforeBraces: Stroustrup
PointerAlignment: Right

@ -1,18 +1,11 @@
AM_CFLAGS = -Wall -Wextra -Wno-sign-compare
prog =
sbin_PROGRAMS = fping
fping_SOURCES = fping.c seqmap.c socket4.c fping.h options.h seqmap.h optparse.c optparse.h
fping_DEPENDENCIES = ../config.h
if IPV4
prog += fping
endif
if IPV6
prog += fping6
fping_SOURCES += socket6.c
fping_CFLAGS = $(AM_CFLAGS) -DIPV6
endif
sbin_PROGRAMS = ${prog}
fping_SOURCES = fping.c seqmap.c socket.c socket4.c fping.h options.h seqmap.h
fping_DEPENDENCIES = ../config.h
fping6_SOURCES = fping.c seqmap.c socket.c socket6.c fping.h options.h seqmap.h
fping6_DEPENDENCIES = ../config.h
fping6_CFLAGS = $(AM_CFLAGS) -DIPV6

File diff suppressed because it is too large Load Diff

@ -7,24 +7,33 @@
#include <sys/types.h>
#include <netinet/in.h>
#ifndef IPV6
#define FPING_INADDR struct in_addr
#define FPING_ICMPHDR struct icmp
/* this requires variadic macros, part of C99 */
#if (defined(DEBUG) || defined(_DEBUG))
extern int64_t current_time_ns;
extern int trace_flag;
#define dbg_printf(fmt, ...) do { if (trace_flag) { fprintf(stderr, "[%10.5f] ", (double)(current_time_ns / 1000)/1000000); fprintf(stderr, fmt, __VA_ARGS__); } } while (0)
#else
#define FPING_INADDR struct in6_addr
#define FPING_ICMPHDR struct icmp6_hdr
#define dbg_printf(fmt, ...)
#endif
/* fping.c */
void crash_and_burn( char *message );
void errno_crash_and_burn( char *message );
int in_cksum( unsigned short *p, int n );
int random_data_flag;
extern int nonzero_payload_flag;
/* socket.c */
int open_ping_socket();
void init_ping_buffer(size_t ping_data_size);
void socket_set_src_addr(int s, FPING_INADDR src_addr);
int socket_sendto_ping(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
int open_ping_socket_ipv4(int *socktype);
void init_ping_buffer_ipv4(size_t ping_data_size);
void socket_set_src_addr_ipv4(int s, struct in_addr *src_addr, int *ident);
int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
#ifdef IPV6
int open_ping_socket_ipv6(int *socktype);
void init_ping_buffer_ipv6(size_t ping_data_size);
void socket_set_src_addr_ipv6(int s, struct in6_addr *src_addr, int *ident);
int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
#endif
#endif

@ -0,0 +1 @@
ctags -R --fields=+S /usr/include ..

@ -20,7 +20,7 @@
/* constants */
#ifndef DEFAULT_INTERVAL
#define DEFAULT_INTERVAL 25 /* default time between packets (msec) */
#define DEFAULT_INTERVAL 10 /* default time between packets (msec) */
#endif
#ifndef DEFAULT_PERHOST_INTERVAL /* default time between packets */
@ -29,6 +29,7 @@
#ifndef DEFAULT_TIMEOUT
#define DEFAULT_TIMEOUT 500 /* individual host timeouts */
#define AUTOTUNE_TIMEOUT_MAX 2000
#endif

@ -0,0 +1,266 @@
#include "optparse.h"
#define MSG_INVALID "invalid option"
#define MSG_MISSING "option requires an argument"
#define MSG_TOOMANY "option takes no arguments"
static int
opterror(struct optparse *options, const char *message, const char *data)
{
unsigned p = 0;
while (*message)
options->errmsg[p++] = *message++;
const char *sep = " -- '";
while (*sep)
options->errmsg[p++] = *sep++;
while (p < sizeof(options->errmsg) - 2 && *data)
options->errmsg[p++] = *data++;
options->errmsg[p++] = '\'';
options->errmsg[p++] = '\0';
return '?';
}
void optparse_init(struct optparse *options, char **argv)
{
options->argv = argv;
options->permute = 1;
options->optind = 1;
options->subopt = 0;
options->optarg = 0;
options->errmsg[0] = '\0';
}
static inline int
is_dashdash(const char *arg)
{
return arg != 0 && arg[0] == '-' && arg[1] == '-' && arg[2] == '\0';
}
static inline int
is_shortopt(const char *arg)
{
return arg != 0 && arg[0] == '-' && arg[1] != '-' && arg[1] != '\0';
}
static inline int
is_longopt(const char *arg)
{
return arg != 0 && arg[0] == '-' && arg[1] == '-' && arg[2] != '\0';
}
static void
permute(struct optparse *options, int index)
{
char *nonoption = options->argv[index];
for (int i = index; i < options->optind - 1; i++)
options->argv[i] = options->argv[i + 1];
options->argv[options->optind - 1] = nonoption;
}
static int
argtype(const char *optstring, char c)
{
if (c == ':')
return -1;
for (; *optstring && c != *optstring; optstring++);
if (!*optstring)
return -1;
int count = OPTPARSE_NONE;
if (optstring[1] == ':')
count += optstring[2] == ':' ? 2 : 1;
return count;
}
int optparse(struct optparse *options, const char *optstring)
{
options->errmsg[0] = '\0';
options->optopt = 0;
options->optarg = 0;
char *option = options->argv[options->optind];
if (option == 0) {
return -1;
} else if (is_dashdash(option)) {
options->optind++; /* consume "--" */
return -1;
} else if (!is_shortopt(option)) {
if (options->permute) {
int index = options->optind;
options->optind++;
int r = optparse(options, optstring);
permute(options, index);
options->optind--;
return r;
} else {
return -1;
}
}
option += options->subopt + 1;
options->optopt = option[0];
int type = argtype(optstring, option[0]);
char *next = options->argv[options->optind + 1];
switch (type) {
case -1: {
options->optind++;
char str[2] = {option[0]};
return opterror(options, MSG_INVALID, str);
}
case OPTPARSE_NONE:
if (option[1]) {
options->subopt++;
} else {
options->subopt = 0;
options->optind++;
}
return option[0];
case OPTPARSE_REQUIRED:
options->subopt = 0;
options->optind++;
if (option[1]) {
options->optarg = option + 1;
} else if (next != 0) {
options->optarg = next;
options->optind++;
} else {
options->optarg = 0;
char str[2] = {option[0]};
return opterror(options, MSG_MISSING, str);
}
return option[0];
case OPTPARSE_OPTIONAL:
options->subopt = 0;
options->optind++;
if (option[1])
options->optarg = option + 1;
else
options->optarg = 0;
return option[0];
}
return 0;
}
char *optparse_arg(struct optparse *options)
{
options->subopt = 0;
char *option = options->argv[options->optind];
if (option != 0)
options->optind++;
return option;
}
static inline int
longopts_end(const struct optparse_long *longopts, int i)
{
return !longopts[i].longname && !longopts[i].shortname;
}
static void
optstring_from_long(const struct optparse_long *longopts, char *optstring)
{
char *p = optstring;
for (int i = 0; !longopts_end(longopts, i); i++) {
if (longopts[i].shortname) {
*p++ = longopts[i].shortname;
for (int a = 0; a < (int)longopts[i].argtype; a++)
*p++ = ':';
}
}
*p = '\0';
}
/* Unlike strcmp(), handles options containing "=". */
static int
longopts_match(const char *longname, const char *option)
{
if (longname == 0)
return 0;
const char *a = option, *n = longname;
for (; *a && *n && *a != '='; a++, n++)
if (*a != *n)
return 0;
return *n == '\0' && (*a == '\0' || *a == '=');
}
/* Return the part after "=", or NULL. */
static char *
longopts_arg(char *option)
{
for (; *option && *option != '='; option++);
if (*option == '=')
return option + 1;
else
return 0;
}
static int
long_fallback(struct optparse *options,
const struct optparse_long *longopts,
int *longindex)
{
char optstring[96 * 3 + 1]; /* 96 ASCII printable characters */
optstring_from_long(longopts, optstring);
int result = optparse(options, optstring);
if (longindex != 0) {
*longindex = -1;
if (result != -1)
for (int i = 0; !longopts_end(longopts, i); i++)
if (longopts[i].shortname == options->optopt)
*longindex = i;
}
return result;
}
int
optparse_long(struct optparse *options,
const struct optparse_long *longopts,
int *longindex)
{
char *option = options->argv[options->optind];
if (option == 0) {
return -1;
} else if (is_dashdash(option)) {
options->optind++; /* consume "--" */
return -1;
} else if (is_shortopt(option)) {
return long_fallback(options, longopts, longindex);
} else if (!is_longopt(option)) {
if (options->permute) {
int index = options->optind;
options->optind++;
int r = optparse_long(options, longopts, longindex);
permute(options, index);
options->optind--;
return r;
} else {
return -1;
}
}
/* Parse as long option. */
options->errmsg[0] = '\0';
options->optopt = 0;
options->optlongname = 0;
options->optarg = 0;
option += 2; /* skip "--" */
options->optind++;
for (int i = 0; !longopts_end(longopts, i); i++) {
const char *name = longopts[i].longname;
if (longopts_match(name, option)) {
options->optlongname = option;
if (longindex)
*longindex = i;
options->optopt = longopts[i].shortname;
char *arg = longopts_arg(option);
if (longopts[i].argtype == OPTPARSE_NONE && arg != 0) {
return opterror(options, MSG_TOOMANY, name);
} if (arg != 0) {
options->optarg = arg;
} else if (longopts[i].argtype == OPTPARSE_REQUIRED) {
options->optarg = options->argv[options->optind++];
if (options->optarg == 0)
return opterror(options, MSG_MISSING, name);
}
return options->optopt;
}
}
return opterror(options, MSG_INVALID, option);
}

@ -0,0 +1,103 @@
#ifndef OPTPARSE_H
#define OPTPARSE_H
/**
* Optparse -- portable, reentrant, embeddable, getopt-like option parser
*
* The POSIX getopt() option parser has three fatal flaws. These flaws
* are solved by Optparse.
*
* 1) Parser state is stored entirely in global variables, some of
* which are static and inaccessible. This means only one thread can
* use getopt(). It also means it's not possible to recursively parse
* nested sub-arguments while in the middle of argument parsing.
* Optparse fixes this by storing all state on a local struct.
*
* 2) The POSIX standard provides no way to properly reset the parser.
* This means for portable code that getopt() is only good for one
* run, over one argv with one optstring. It also means subcommand
* options cannot be processed with getopt(). Most implementations
* provide a method to reset the parser, but it's not portable.
* Optparse provides an optparse_arg() function for stepping over
* subcommands and continuing parsing of options with another
* optstring. The Optparse struct itself can be passed around to
* subcommand handlers for additional subcommand option parsing. A
* full reset can be achieved by with an additional optparse_init().
*
* 3) Error messages are printed to stderr. This can be disabled with
* opterr, but the messages themselves are still inaccessible.
* Optparse solves this by writing an error message in its errmsg
* field. The downside to Optparse is that this error message will
* always be in English rather than the current locale.
*
* Optparse should be familiar with anyone accustomed to getopt(), and
* it could be a nearly drop-in replacement. The optstring is the same
* and the fields have the same names as the getopt() global variables
* (optarg, optind, optopt).
*
* Optparse also supports GNU-style long options with optparse_long().
* The interface is slightly different and simpler than getopt_long().
*
* By default, argv is permuted as it is parsed, moving non-option
* arguments to the end. This can be disabled by setting the `permute`
* field to 0 after initialization.
*/
struct optparse {
char **argv;
int permute;
int optind;
int optopt;
char *optlongname;
char *optarg;
char errmsg[64];
int subopt;
};
enum optparse_argtype { OPTPARSE_NONE, OPTPARSE_REQUIRED, OPTPARSE_OPTIONAL };
struct optparse_long {
const char *longname;
int shortname;
enum optparse_argtype argtype;
};
/**
* Initializes the parser state.
*/
void optparse_init(struct optparse *options, char **argv);
/**
* Read the next option in the argv array.
* @param optstring a getopt()-formatted option string.
* @return the next option character, -1 for done, or '?' for error
*
* Just like getopt(), a character followed by no colons means no
* argument. One colon means the option has a required argument. Two
* colons means the option takes an optional argument.
*/
int optparse(struct optparse *options, const char *optstring);
/**
* Handles GNU-style long options in addition to getopt() options.
* This works a lot like GNU's getopt_long(). The last option in
* longopts must be all zeros, marking the end of the array. The
* longindex argument may be NULL.
*/
int
optparse_long(struct optparse *options,
const struct optparse_long *longopts,
int *longindex);
/**
* Used for stepping over non-option arguments.
* @return the next non-option argument, or NULL for no more arguments
*
* Argument parsing can continue with optparse() after using this
* function. That would be used to parse the options for the
* subcommand returned by optparse_arg(). This function allows you to
* ignore the value of optind.
*/
char *optparse_arg(struct optparse *options);
#endif

@ -35,17 +35,20 @@
* https://github.com/schweikert/fping/issues/48
*/
#include "config.h"
#include "seqmap.h"
#include "limits.h"
#include "options.h"
#include "fping.h"
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
/* description of the data structure used:
*
* - we assume that no more than SEQMAP_MAXSEQ (65535) pings are sent in
* the timeout interval (SEQMAP_TIMEOUT_IN_S)
* the timeout interval (SEQMAP_TIMEOUT_IN_NS)
* - we store the values in an array with SEQMAP_MAXSEQ elements
* - current sequence number % SEQMAP_MAXSEQ gives the current index
* - when entering a value, we check that the current entry is expired
@ -54,7 +57,7 @@
static SEQMAP_VALUE* seqmap_map = NULL;
static unsigned int seqmap_next_id = 0;
#define SEQMAP_TIMEOUT_IN_S 10
#define SEQMAP_TIMEOUT_IN_NS 10000000000
#define SEQMAP_UNASSIGNED_HOST_NR UINT_MAX
void seqmap_init()
@ -65,7 +68,7 @@ void seqmap_init()
}
}
unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct timeval* now)
unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, int64_t timestamp)
{
unsigned int current_id;
SEQMAP_VALUE* next_value;
@ -78,26 +81,27 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct ti
/* check if expired (note that unused seqmap values will have fields set to
* 0, so will be seen as expired */
next_value = &seqmap_map[seqmap_next_id];
if (next_value->ping_ts.tv_sec != 0 && (now->tv_sec - next_value->ping_ts.tv_sec) < SEQMAP_TIMEOUT_IN_S) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%d, host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
SEQMAP_TIMEOUT_IN_S, host_nr, ping_count, seqmap_next_id);
if (next_value->ping_ts != 0 && timestamp - next_value->ping_ts < SEQMAP_TIMEOUT_IN_NS) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%" PRId64 ", host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
SEQMAP_TIMEOUT_IN_NS, host_nr, ping_count, seqmap_next_id);
exit(4);
}
/* store the value */
next_value->host_nr = host_nr;
next_value->ping_count = ping_count;
next_value->ping_ts.tv_sec = now->tv_sec;
next_value->ping_ts.tv_usec = now->tv_usec;
next_value->ping_ts = timestamp;
/* increase next id */
current_id = seqmap_next_id;
seqmap_next_id = (seqmap_next_id + 1) % SEQMAP_MAXSEQ;
dbg_printf("seqmap_add(host: %d, index: %d) -> %d\n", host_nr, ping_count, current_id);
return current_id;
}
SEQMAP_VALUE* seqmap_fetch(unsigned int id, struct timeval* now)
SEQMAP_VALUE* seqmap_fetch(unsigned int id, int64_t now)
{
SEQMAP_VALUE* value;
@ -108,9 +112,13 @@ SEQMAP_VALUE* seqmap_fetch(unsigned int id, struct timeval* now)
value = &seqmap_map[id];
/* verify that value is not expired */
if (now->tv_sec - value->ping_ts.tv_sec >= SEQMAP_TIMEOUT_IN_S) {
if (now - value->ping_ts >= SEQMAP_TIMEOUT_IN_NS) {
dbg_printf("seqmap_fetch(%d) -> host: %d, index: %d -> DISCARDED %ld\n", id, value->host_nr, value->ping_count,
now - value->ping_ts);
return NULL;
}
dbg_printf("seqmap_fetch(%d) -> host: %d, index: %d\n", id, value->host_nr, value->ping_count);
return value;
}

@ -2,19 +2,20 @@
#define SEQMAP_H
#include <sys/time.h>
#include <stdint.h>
typedef struct seqmap_value
{
unsigned int host_nr;
unsigned int ping_count;
struct timeval ping_ts;
int64_t ping_ts;
} SEQMAP_VALUE;
#define SEQMAP_MAXSEQ 65535
void seqmap_init();
unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct timeval *now);
SEQMAP_VALUE *seqmap_fetch(unsigned int id, struct timeval *now);
unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, int64_t now);
SEQMAP_VALUE *seqmap_fetch(unsigned int id, int64_t now);
#endif

@ -1,79 +0,0 @@
/*
* fping: fast-ping, file-ping, favorite-ping, funky-ping
*
* Ping a list of target hosts in a round robin fashion.
* A better ping overall.
*
* fping website: http://www.fping.org
*
* Current maintainer of fping: David Schweikert
* Please send suggestions and patches to: david@schweikert.ch
*
*
* Original author: Roland Schemers <schemers@stanford.edu>
* IPv6 Support: Jeroen Massar <jeroen@unfix.org / jeroen@ipng.nl>
* Improved main loop: David Schweikert <david@schweikert.ch>
* Debian Merge, TOS settings: Tobi Oetiker <tobi@oetiker.ch>
* Bugfixes, byte order & senseful seq.-numbers: Stephan Fuhrmann (stephan.fuhrmann AT 1und1.de)
*
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Stanford University. The name of the University may not be used
* to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "config.h"
#include "fping.h"
int open_ping_socket_ipv4();
int open_ping_socket_ipv6();
void init_ping_buffer_ipv4(size_t ping_data_size);
void init_ping_buffer_ipv6(size_t ping_data_size);
void socket_set_src_addr_ipv4(int s, FPING_INADDR src_addr);
void socket_set_src_addr_ipv6(int s, FPING_INADDR src_addr);
int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
int open_ping_socket()
{
#ifndef IPV6
return open_ping_socket_ipv4();
#else
return open_ping_socket_ipv6();
#endif
}
void init_ping_buffer(size_t ping_data_size)
{
#ifndef IPV6
return init_ping_buffer_ipv4(ping_data_size);
#else
return init_ping_buffer_ipv6(ping_data_size);
#endif
}
void socket_set_src_addr(int s, FPING_INADDR src_addr)
{
#ifndef IPV6
socket_set_src_addr_ipv4(s, src_addr);
#else
socket_set_src_addr_ipv6(s, src_addr);
#endif
}
int socket_sendto_ping(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
{
#ifndef IPV6
return socket_sendto_ping_ipv4(s, saddr, saddr_len, icmp_seq_nr, icmp_id_nr);
#else
return socket_sendto_ping_ipv6(s, saddr, saddr_len, icmp_seq_nr, icmp_id_nr);
#endif
}

@ -44,10 +44,10 @@
#include <string.h>
#include <sys/socket.h>
char* ping_buffer = 0;
size_t ping_pkt_size;
char* ping_buffer_ipv4 = 0;
size_t ping_pkt_size_ipv4;
int open_ping_socket_ipv4()
int open_ping_socket_ipv4(int *socktype)
{
struct protoent* proto;
int s;
@ -57,12 +57,14 @@ int open_ping_socket_ipv4()
crash_and_burn("icmp: unknown protocol");
/* create raw socket for ICMP calls (ping) */
s = socket(AF_INET, SOCK_RAW, proto->p_proto);
*socktype = SOCK_RAW;
s = socket(AF_INET, *socktype, proto->p_proto);
if (s < 0) {
/* try non-privileged icmp (works on Mac OSX without privileges, for example) */
s = socket(AF_INET, SOCK_DGRAM, proto->p_proto);
*socktype = SOCK_DGRAM;
s = socket(AF_INET, *socktype, proto->p_proto);
if (s < 0) {
errno_crash_and_burn("can't create socket (must run as root?)");
return -1;
}
}
@ -83,21 +85,31 @@ int open_ping_socket_ipv4()
void init_ping_buffer_ipv4(size_t ping_data_size)
{
/* allocate ping buffer */
ping_pkt_size = ping_data_size + ICMP_MINLEN;
ping_buffer = (char*)calloc(1, ping_pkt_size);
if (!ping_buffer)
ping_pkt_size_ipv4 = ping_data_size + ICMP_MINLEN;
ping_buffer_ipv4 = (char*)calloc(1, ping_pkt_size_ipv4);
if (!ping_buffer_ipv4)
crash_and_burn("can't malloc ping packet");
}
void socket_set_src_addr_ipv4(int s, FPING_INADDR src_addr)
void socket_set_src_addr_ipv4(int s, struct in_addr* src_addr, int *ident)
{
struct sockaddr_in sa;
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr = src_addr;
socklen_t len = sizeof(sa);
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
memset(&sa, 0, len);
sa.sin_family = AF_INET;
sa.sin_addr = *src_addr;
if (bind(s, (struct sockaddr*)&sa, len) < 0)
errno_crash_and_burn("cannot bind source address");
if (ident) {
memset(&sa, 0, len);
if (getsockname(s, (struct sockaddr *)&sa, &len) < 0)
errno_crash_and_burn("can't get ICMP socket identity");
if (sa.sin_port)
*ident = sa.sin_port;
}
}
unsigned short calcsum(unsigned short* buffer, int length)
@ -121,24 +133,28 @@ int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len,
{
struct icmp* icp;
int n;
size_t i;
icp = (struct icmp*)ping_buffer;
icp = (struct icmp*)ping_buffer_ipv4;
icp->icmp_type = ICMP_ECHO;
icp->icmp_code = 0;
icp->icmp_cksum = 0;
icp->icmp_seq = htons(icmp_seq_nr);
icp->icmp_id = htons(icmp_id_nr);
if (random_data_flag) {
for (n = ((void*)&icp->icmp_data - (void*)icp); n < ping_pkt_size; ++n) {
ping_buffer[n] = random() & 0xFF;
icp->icmp_id = icmp_id_nr;
if (nonzero_payload_flag) {
// for (n = ((char*)&icp->icmp_data - (char*)icp); n < ping_pkt_size_ipv4; ++n) {
// ping_buffer_ipv4[n] = random() & 0xFF;
// }
for(n = (char*) &icp->icmp_data - (char*)icp, i = 0xA; n < ping_pkt_size_ipv4; ++n, i += 1) {
ping_buffer_ipv4[n] = i & 0xFF;
}
}
icp->icmp_cksum = calcsum((unsigned short*)icp, ping_pkt_size);
icp->icmp_cksum = calcsum((unsigned short*)icp, ping_pkt_size_ipv4);
n = sendto(s, icp, ping_pkt_size, 0, saddr, saddr_len);
n = sendto(s, icp, ping_pkt_size_ipv4, 0, saddr, saddr_len);
return n;
}

@ -43,25 +43,27 @@
#include <netinet/icmp6.h>
char* ping_buffer = 0;
size_t ping_pkt_size;
char* ping_buffer_ipv6 = 0;
size_t ping_pkt_size_ipv6;
int open_ping_socket_ipv6()
int open_ping_socket_ipv6(int *socktype)
{
struct protoent* proto;
int s;
/* confirm that ICMP is available on this machine */
/* confirm that ICMP6 is available on this machine */
if ((proto = getprotobyname("ipv6-icmp")) == NULL)
crash_and_burn("icmp: unknown protocol");
crash_and_burn("ipv6-icmp: unknown protocol");
/* create raw socket for ICMP calls (ping) */
s = socket(AF_INET6, SOCK_RAW, proto->p_proto);
/* create raw socket for ICMP6 calls (ping) */
*socktype = SOCK_RAW;
s = socket(AF_INET6, *socktype, proto->p_proto);
if (s < 0) {
/* try non-privileged icmp (works on Mac OSX without privileges, for example) */
s = socket(AF_INET6, SOCK_DGRAM, proto->p_proto);
/* try non-privileged icmp6 (works on Mac OSX without privileges, for example) */
*socktype = SOCK_DGRAM;
s = socket(AF_INET6, *socktype, proto->p_proto);
if (s < 0) {
errno_crash_and_burn("can't create raw socket (must run as root?)");
return -1;
}
}
@ -82,43 +84,54 @@ int open_ping_socket_ipv6()
void init_ping_buffer_ipv6(size_t ping_data_size)
{
/* allocate ping buffer */
ping_pkt_size = ping_data_size + sizeof(struct icmp6_hdr);
ping_buffer = (char*)calloc(1, ping_pkt_size);
if (!ping_buffer)
ping_pkt_size_ipv6 = ping_data_size + sizeof(struct icmp6_hdr);
ping_buffer_ipv6 = (char*)calloc(1, ping_pkt_size_ipv6);
if (!ping_buffer_ipv6)
crash_and_burn("can't malloc ping packet");
}
void socket_set_src_addr_ipv6(int s, FPING_INADDR src_addr)
void socket_set_src_addr_ipv6(int s, struct in6_addr* src_addr, int *ident)
{
struct sockaddr_in6 sa;
socklen_t len = sizeof(sa);
memset(&sa, 0, sizeof(sa));
sa.sin6_family = AF_INET6;
sa.sin6_addr = src_addr;
sa.sin6_addr = *src_addr;
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
errno_crash_and_burn("cannot bind source address");
if (ident) {
memset(&sa, 0, len);
if (getsockname(s, (struct sockaddr *)&sa, &len) < 0)
errno_crash_and_burn("can't get ICMP6 socket identity");
if (sa.sin6_port)
*ident = sa.sin6_port;
}
}
int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
{
struct icmp6_hdr* icp;
int n;
size_t i;
icp = (struct icmp6_hdr*)ping_buffer;
icp = (struct icmp6_hdr*)ping_buffer_ipv6;
icp->icmp6_type = ICMP6_ECHO_REQUEST;
icp->icmp6_code = 0;
icp->icmp6_seq = htons(icmp_seq_nr);
icp->icmp6_id = htons(icmp_id_nr);
icp->icmp6_id = icmp_id_nr;
if (random_data_flag) {
for (n = sizeof(struct icmp6_hdr); n < ping_pkt_size; ++n) {
ping_buffer[n] = random() & 0xFF;
if (nonzero_payload_flag) {
for (n = sizeof(struct icmp6_hdr), i = 0xA; n < ping_pkt_size_ipv6; ++n, i+=1) {
ping_buffer_ipv6[n] = i & 0xFF;
}
}
icp->icmp6_cksum = 0; /* The IPv6 stack calculates the checksum for us... */
n = sendto(s, icp, ping_pkt_size, 0, saddr, saddr_len);
n = sendto(s, icp, ping_pkt_size_ipv6, 0, saddr, saddr_len);
return n;
}

@ -1 +0,0 @@
gcc -DHAVE_CONFIG_H -D_BSD_SOURCE -D_POSIX_SOURCE -I.. -Wall -std=c89 -pedantic -c -o fping.o fping.c
Loading…
Cancel
Save