Skip to content

Commit

Permalink
fping and fping6 unification, fixes #80
Browse files Browse the repository at this point in the history
  • Loading branch information
schweikert committed Feb 9, 2017
1 parent 3b5c426 commit 2f95647
Show file tree
Hide file tree
Showing 24 changed files with 649 additions and 570 deletions.
21 changes: 21 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
Unreleased
* INCOMPATIBILITY WARNING:
fping and fping6 are now unified into one binary. This means that, for
example, doing 'fping www.google.com' is going to ping the IPv6 IP of
www.google.com on IPv6-enabled hosts.

If you need exact compatibility with old versions, you can configure,
compile, 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

Or, alternatively, you could write two wrappers 'fping' and 'fping6',
that set respectively the options '-4' and '-6' when calling the original
fping binary.

* Version 4.0
* (feature) Unified 'fping' and 'fping6' into one binary (#80)
* (feature) --enable-ipv6 is now default
* (feature) New option '-4' to force IPv4
* (feature) New option '-6' to force IPv6

2017-02-09 David Schweikert <david@schweikert.ch>
* Version 3.16
* (feature) Support kernel-timestamping of received packets (#46)
Expand Down
3 changes: 0 additions & 3 deletions ci/build-2-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ autoreconf -i
make CFLAGS="-g -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 .
Expand All @@ -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 change: 0 additions & 1 deletion ci/prepare-linux.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

sudo setcap cap_net_raw+ep src/fping
sudo setcap cap_net_raw+ep src/fping6

if [[ ! $PATH =~ fping/src ]]; then
echo "# WARNING: must set PATH:"
Expand Down
2 changes: 1 addition & 1 deletion ci/test-01-basics.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 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("");
Expand Down
2 changes: 2 additions & 0 deletions ci/test-02-help.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
$cmd1->stdout_is_eq(<<END);
Usage: fping [options] [targets...]
-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)
Expand Down
8 changes: 4 additions & 4 deletions ci/test-03-forbidden.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -38,11 +38,11 @@ END
$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");
Expand Down
47 changes: 45 additions & 2 deletions ci/test-04-options-a-b.pl
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
#!/usr/bin/perl -w

use Test::Command tests => 14;
use Test::Command tests => 29;
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 -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(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 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");
Expand All @@ -19,7 +62,7 @@

# 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("");
Expand Down
4 changes: 2 additions & 2 deletions ci/test-05-options-c-e.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# 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\)
Expand All @@ -24,7 +24,7 @@

# 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\)
Expand Down
2 changes: 1 addition & 1 deletion ci/test-06-options-f-h.pl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
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 -H
Expand Down
6 changes: 3 additions & 3 deletions ci/test-09-option-r-t.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 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%.*});
Expand Down Expand Up @@ -84,12 +84,12 @@
$cmd->stderr_is_eq("");
}

# fping6 -S
# fping -S
SKIP: {
if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 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("");
Expand Down
12 changes: 1 addition & 11 deletions ci/test-11-nopriv.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
plan skip_all => 'Test irrelevant on MacOS';
exit 0;
}
plan tests => 6;
plan tests => 3;

# 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
{
Expand All @@ -22,11 +20,3 @@
$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});
}
10 changes: 1 addition & 9 deletions ci/test-13-unknown-host.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w

use Test::Command tests => 6;
use Test::Command tests => 3;

# fping
{
Expand All @@ -9,11 +9,3 @@
$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)});
}
28 changes: 14 additions & 14 deletions ci/test-14-ping-internet-hosts.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
exit 0;
}

plan tests => 18;
plan tests => 21;

my $re_num = qr{\d+(?:\.\d+)?};

Expand All @@ -33,35 +33,35 @@
$cmd->stderr_is_eq("");
}

# fping -A -n
# fping -4 -A -n
{
my $cmd = Test::Command->new(cmd => "fping -A -n google-public-dns-a.google.com");
my $cmd = Test::Command->new(cmd => "fping -4 -A -n google-public-dns-a.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->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;
}
my $cmd = Test::Command->new(cmd => "fping6 -n -A 2001:4860:4860::8888");
my $cmd = Test::Command->new(cmd => "fping -6 -n -A google-public-dns-a.google.com");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("google-public-dns-a.google.com (2001:4860:4860::8888) 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(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("");
}

# fping -n
{
Expand Down
2 changes: 1 addition & 1 deletion ci/test-issue-58.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
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");
47 changes: 25 additions & 22 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@ 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],[3.16-rc2])

dnl make ipv4 and ipv6 options
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>
]])
])
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_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_TIMESTAMP], [AC_DEFINE(HAVE_SO_TIMESTAMP, [1], [SO_TIMESTAMP 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
Expand Down Expand Up @@ -80,7 +83,7 @@ AH_BOTTOM([
])

dnl Checks for header files.
AC_CHECK_HEADERS(unistd.h sys/file.h stdlib.h sys/select.h)
AC_CHECK_HEADERS([unistd.h sys/file.h stdlib.h sys/select.h])

AC_CONFIG_FILES([Makefile
doc/Makefile
Expand Down
Loading

0 comments on commit 2f95647

Please sign in to comment.