From f65d335ecfa2e364b0842b8ad233537a9b08d604 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 4 Apr 2014 22:22:48 +0200 Subject: [PATCH 01/30] More tests --- ci/test-5-options-c-e.pl | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 ci/test-5-options-c-e.pl diff --git a/ci/test-5-options-c-e.pl b/ci/test-5-options-c-e.pl new file mode 100755 index 0000000..c2c0a56 --- /dev/null +++ b/ci/test-5-options-c-e.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 12; +use Test::More; +use Time::HiRes qw(gettimeofday tv_interval); + +# -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 + +# fping -c n +{ +my $cmd = Test::Command->new(cmd => "fping -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->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+ +}); +} + +# fping -C n +{ +my $cmd = Test::Command->new(cmd => "fping -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->stderr_like(qr{localhost : 0\.\d+ 0\.\d+ +127\.0\.0\.1 : 0\.\d+ 0\.\d+ +}); +} + +# fping -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->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = 0\.\d+/0\.\d+/0\.\d+ +}); +} + +# 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->stderr_is_eq(""); +} From 3cf9a8a3cd29c1110070fd90fe293f2705e14b62 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 4 Apr 2014 22:23:32 +0200 Subject: [PATCH 02/30] Fix confusing error message with -g and IPv6 addresses (fixes #58) --- ChangeLog | 4 ++++ ci/test-issue-58.pl | 10 ++++++++++ src/fping.c | 24 +++++++++++++----------- 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100755 ci/test-issue-58.pl diff --git a/ChangeLog b/ChangeLog index 131e9d7..a79c611 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +UNRELEASED + * More tests added + * Fix confusing error message with -g and IPv6 addresses (#58, reported by Axel Beckert) + 2014-03-08 David Schweikert * Version 3.9 * Fix random output on socket error (reported by Aleksandrs Saveljevs, #56) diff --git a/ci/test-issue-58.pl b/ci/test-issue-58.pl new file mode 100755 index 0000000..df3e601 --- /dev/null +++ b/ci/test-issue-58.pl @@ -0,0 +1,10 @@ +#!/usr/bin/perl -w + +# regression testing for github issue #58 + +use Test::Command tests => 3; + +my $cmd1 = Test::Command->new(cmd => "src/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"); diff --git a/src/fping.c b/src/fping.c index 1ac9b7a..03e98b0 100644 --- a/src/fping.c +++ b/src/fping.c @@ -794,7 +794,7 @@ int main( int argc, char **argv ) } if( !num_hosts ) - exit( 2 ); + exit(1); if(src_addr_present) { socket_set_src_addr(s, src_addr); @@ -880,10 +880,6 @@ void add_cidr(char *addr) *addr_end = '\0'; mask_str = addr_end + 1; mask = atoi(mask_str); - if(mask < 1 || mask > 30) { - fprintf(stderr, "Error: netmask must be between 1 and 30 (is: %s)\n", mask_str); - exit(2); - } /* parse address (IPv4 only) */ memset(&addr_hints, 0, sizeof(struct addrinfo)); @@ -892,14 +888,20 @@ void add_cidr(char *addr) ret = getaddrinfo(addr, NULL, &addr_hints, &addr_res); if(ret) { fprintf(stderr, "Error: can't parse address %s: %s\n", addr, gai_strerror(ret)); - exit(2); + exit(1); } if(addr_res->ai_family != AF_INET) { fprintf(stderr, "Error: -g works only with IPv4 addresses\n"); - exit(2); + exit(1); } net_addr = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr); + /* check mask */ + if(mask < 1 || mask > 30) { + fprintf(stderr, "Error: netmask must be between 1 and 30 (is: %s)\n", mask_str); + exit(1); + } + /* convert mask integer from 1 to 32 to a bitmask */ bitmask = ((unsigned long) 0xFFFFFFFF) << (32-mask); @@ -934,11 +936,11 @@ void add_range(char *start, char *end) ret = getaddrinfo(start, NULL, &addr_hints, &addr_res); if(ret) { fprintf(stderr, "Error: can't parse address %s: %s\n", start, gai_strerror(ret)); - exit(2); + exit(1); } if(addr_res->ai_family != AF_INET) { fprintf(stderr, "Error: -g works only with IPv4 addresses\n"); - exit(2); + exit(1); } start_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr); @@ -949,11 +951,11 @@ void add_range(char *start, char *end) ret = getaddrinfo(end, NULL, &addr_hints, &addr_res); if(ret) { fprintf(stderr, "Error: can't parse address %s: %s\n", end, gai_strerror(ret)); - exit(2); + exit(1); } if(addr_res->ai_family != AF_INET) { fprintf(stderr, "Error: -g works only with IPv4 addresses\n"); - exit(2); + exit(1); } end_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr); From d4e0a6c89b00f2835d2f4a13271375d6c18bf196 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 4 Apr 2014 22:29:33 +0200 Subject: [PATCH 03/30] build all branches with travis-ci --- .travis.yml | 3 --- ci/deploy-bintray.sh | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3cb7d1c..4b301cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,6 @@ env: - secure: "CoI8hwHH1yfQoQxIfWGRS0WfTyScox+5aJn0fDDgz2uKrrIxmBvIw/WKX8wcSiV6fLmLuwgNkKqSM3hdO4qaG+JxfWcuEiZZHm+kxSGMkWbGb/fvAI+gHg8ldKyYttcIX71O5rlZiC2QpNKQi2v18S6pI5p8eqnx7DYx4YrmguQ=" compiler: - gcc -branches: - only: - - master before_install: - sudo apt-get install libcap2-bin install: diff --git a/ci/deploy-bintray.sh b/ci/deploy-bintray.sh index 1dfef48..2c34a08 100755 --- a/ci/deploy-bintray.sh +++ b/ci/deploy-bintray.sh @@ -10,6 +10,12 @@ if [ "$CC" != "gcc" ]; then exit 0 fi +# do this only for the master branch +if [ "$TRAVIS_BRANCH" != "master" ]; then + echo "skipped upload branch $TRAVIS_BRANCH isn't master" + 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 From 86f0b1e38098ad4b7e735ee7ef10cda071d43bdc Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Mon, 28 Apr 2014 19:24:36 +0200 Subject: [PATCH 04/30] Allow option '-f' also for non-root (since setuid privileges are dropped) --- ChangeLog | 1 + src/fping.c | 22 ++-------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index a79c611..da9a6fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ UNRELEASED * More tests added * Fix confusing error message with -g and IPv6 addresses (#58, reported by Axel Beckert) + * Allow option '-f' also for non-root (since setuid privileges are dropped) 2014-03-08 David Schweikert * Version 3.9 diff --git a/src/fping.c b/src/fping.c index 03e98b0..b6f320e 100644 --- a/src/fping.c +++ b/src/fping.c @@ -369,7 +369,8 @@ int main( int argc, char **argv ) s = open_ping_socket(); if((uid = getuid())) { - seteuid( getuid() ); + /* drop privileges */ + setuid( getuid() ); } prog = argv[0]; @@ -509,27 +510,8 @@ int main( int argc, char **argv ) exit( 0 ); case 'f': -#ifdef ENABLE_F_OPTION filename = optarg; - generate_flag = 0; break; -#else - if( getuid() ) - { - printf( "%s: this option can only be used by root.\n", argv[0] ); - printf( "%s: fping will read from stdin by default.\n", argv[0] ); - exit( 3 ); - - }/* IF */ - else - { - filename = optarg; - generate_flag = 0; - - }/* ELSE */ - - break; -#endif /* ENABLE_F_OPTION */ case 'g': /* use IP list generation */ From c524813889d6c594c9baf3b859ecc73ad9d86f10 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Mon, 28 Apr 2014 19:28:29 +0200 Subject: [PATCH 05/30] Add test for -f option --- ci/test-6-options-f-h.pl | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 ci/test-6-options-f-h.pl diff --git a/ci/test-6-options-f-h.pl b/ci/test-6-options-f-h.pl new file mode 100755 index 0000000..7756ae4 --- /dev/null +++ b/ci/test-6-options-f-h.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 9; +use Test::More; +use Time::HiRes qw(gettimeofday tv_interval); +use File::Temp; + +# -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. ../src/fping -g 192.168.1.0 192.168.1.255 or ../src/fping -g 192.168.1.0/24) +# -H n Set the IP TTL value (Time To Live hops) + +my $tmpfile = File::Temp->new(); +print $tmpfile "127.0.0.1\n127.0.0.2\n"; +close($tmpfile); + +# fping without option (-> equivalent to 'fping -f -') +{ +my $cmd = Test::Command->new(cmd => "cat ".$tmpfile->filename." | fping"); +$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 - +{ +my $cmd = Test::Command->new(cmd => "cat ".$tmpfile->filename." | fping -f -"); +$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 file +{ +my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile->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(""); +} From ab006a5113b18c3e2cc9691879452b307303dc39 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Wed, 30 Apr 2014 22:56:21 +0200 Subject: [PATCH 06/30] more tests --- ci/test-6-options-f-h.pl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ci/test-6-options-f-h.pl b/ci/test-6-options-f-h.pl index 7756ae4..7ca7e8c 100755 --- a/ci/test-6-options-f-h.pl +++ b/ci/test-6-options-f-h.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 9; +use Test::Command tests => 15; use Test::More; use Time::HiRes qw(gettimeofday tv_interval); use File::Temp; @@ -38,3 +38,19 @@ $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 -g +{ +my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1/30"); +$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 -H +{ +my $cmd = Test::Command->new(cmd => "fping -H 1 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("127.0.0.1 is alive\n"); +$cmd->stderr_is_eq(""); +} From d35f7072b5facd741dca16a7f925f575b475d950 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Thu, 1 May 2014 15:03:33 +0200 Subject: [PATCH 07/30] more tests --- ci/test-7-options-i-m.pl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 ci/test-7-options-i-m.pl diff --git a/ci/test-7-options-i-m.pl b/ci/test-7-options-i-m.pl new file mode 100755 index 0000000..63fcd31 --- /dev/null +++ b/ci/test-7-options-i-m.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 7; +use Test::More; +use Time::HiRes qw(gettimeofday tv_interval); +use File::Temp; + +# -i n interval between sending ping packets (in millisec) (default 25) +# -l loop sending pings forever +# -m ping multiple interfaces on target host + +# fping -i n +{ +my $cmd = Test::Command->new(cmd => "fping -i 100 127.0.0.1 127.0.0.2"); +$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 -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\) +}); +} + +# fping -m +{ +my $cmd = Test::Command->new(cmd => "fping -m localhost"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("127.0.0.1 is alive\n"); +$cmd->stderr_is_eq(""); +} From 51cc41a2c13e14387905c58aa25a6d54612295af Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Thu, 1 May 2014 15:16:34 +0200 Subject: [PATCH 08/30] more tests --- ci/test-8-options-n-q.pl | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 ci/test-8-options-n-q.pl diff --git a/ci/test-8-options-n-q.pl b/ci/test-8-options-n-q.pl new file mode 100755 index 0000000..a0df4fd --- /dev/null +++ b/ci/test-8-options-n-q.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 9; +use Test::More; +use Time::HiRes qw(gettimeofday tv_interval); +use File::Temp; + +# -n show targets by name (-d is equivalent) +# -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 + +# fping -n +{ +my $cmd = Test::Command->new(cmd => "fping -n 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("localhost is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -q +{ +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+ +}); +} + +# fping -Q +{ +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+ +}); +} + + From a7f351fb8e862f0a88bf73bd228e90688f882552 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Thu, 1 May 2014 15:21:35 +0200 Subject: [PATCH 09/30] re-order options in usage information --- src/fping.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fping.c b/src/fping.c index b6f320e..92154f1 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2687,6 +2687,9 @@ void usage(int is_error) fprintf(out, " (ex. %s -g 192.168.1.0 192.168.1.255 or %s -g 192.168.1.0/24)\n", prog, prog ); fprintf(out, " -H n Set the IP TTL value (Time To Live hops)\n"); fprintf(out, " -i n interval between sending ping packets (in millisec) (default %d)\n", interval / 100 ); +#ifdef SO_BINDTODEVICE + fprintf(out, " -I if bind to a particular interface\n"); +#endif fprintf(out, " -l loop sending pings forever\n" ); fprintf(out, " -m ping multiple interfaces on target host\n" ); fprintf(out, " -n show targets by name (-d is equivalent)\n" ); @@ -2696,9 +2699,6 @@ void usage(int is_error) fprintf(out, " -Q n same as -q, but show summary every n seconds\n" ); fprintf(out, " -r n number of retries (default %d)\n", DEFAULT_RETRY ); fprintf(out, " -s print final stats\n" ); -#ifdef SO_BINDTODEVICE - fprintf(out, " -I if bind to a particular interface\n"); -#endif fprintf(out, " -S addr set source address\n" ); fprintf(out, " -t n individual target initial timeout (in millisec) (default %d)\n", timeout / 100 ); fprintf(out, " -T n ignored (for compatibility with fping 2.4)\n"); From 9a5c6589b296a2ba00b4642564ab68baa8bf8374 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Thu, 1 May 2014 15:21:45 +0200 Subject: [PATCH 10/30] re-order options in usage information --- ci/test-2-help.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test-2-help.pl b/ci/test-2-help.pl index 802988d..8f84e4d 100755 --- a/ci/test-2-help.pl +++ b/ci/test-2-help.pl @@ -22,6 +22,7 @@ Usage: fping [options] [targets...] (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 if bind to a particular interface -l loop sending pings forever -m ping multiple interfaces on target host -n show targets by name (-d is equivalent) @@ -31,7 +32,6 @@ Usage: fping [options] [targets...] -Q n same as -q, but show summary every n seconds -r n number of retries (default 3) -s print final stats - -I if bind to a particular interface -S addr set source address -t n individual target initial timeout (in millisec) (default 500) -T n ignored (for compatibility with fping 2.4) From 3ec68c8a3f3409b41b7a80bff18904c357dcf73a Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Thu, 1 May 2014 15:22:21 +0200 Subject: [PATCH 11/30] test fixes --- ci/test-7-options-i-m.pl | 2 +- ci/test-issue-58.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test-7-options-i-m.pl b/ci/test-7-options-i-m.pl index 63fcd31..33c6cc3 100755 --- a/ci/test-7-options-i-m.pl +++ b/ci/test-7-options-i-m.pl @@ -29,6 +29,6 @@ $cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% l { my $cmd = Test::Command->new(cmd => "fping -m localhost"); $cmd->exit_is_num(0); -$cmd->stdout_is_eq("127.0.0.1 is alive\n"); +$cmd->stdout_is_eq("localhost is alive\n"); $cmd->stderr_is_eq(""); } diff --git a/ci/test-issue-58.pl b/ci/test-issue-58.pl index df3e601..46c7010 100755 --- a/ci/test-issue-58.pl +++ b/ci/test-issue-58.pl @@ -4,7 +4,7 @@ use Test::Command tests => 3; -my $cmd1 = Test::Command->new(cmd => "src/fping -a -g 2001:db8:120:4161::4/64"); +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"); From ea026f3ba4ce4b96034cfba494d08f0f19b2109f Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 14:37:20 +0200 Subject: [PATCH 12/30] test fixes --- ci/test-7-options-i-m.pl | 4 ++-- ci/test-8-options-n-q.pl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/test-7-options-i-m.pl b/ci/test-7-options-i-m.pl index 33c6cc3..279c740 100755 --- a/ci/test-7-options-i-m.pl +++ b/ci/test-7-options-i-m.pl @@ -27,8 +27,8 @@ $cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% l # fping -m { -my $cmd = Test::Command->new(cmd => "fping -m localhost"); +my $cmd = Test::Command->new(cmd => "fping -m google-public-dns-a.google.com is alive"); $cmd->exit_is_num(0); -$cmd->stdout_is_eq("localhost is alive\n"); +$cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); $cmd->stderr_is_eq(""); } diff --git a/ci/test-8-options-n-q.pl b/ci/test-8-options-n-q.pl index a0df4fd..28e599f 100755 --- a/ci/test-8-options-n-q.pl +++ b/ci/test-8-options-n-q.pl @@ -13,9 +13,9 @@ use File::Temp; # fping -n { -my $cmd = Test::Command->new(cmd => "fping -n 127.0.0.1"); +my $cmd = Test::Command->new(cmd => "fping -n 8.8.8.8"); $cmd->exit_is_num(0); -$cmd->stdout_is_eq("localhost is alive\n"); +$cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); $cmd->stderr_is_eq(""); } From bdca2c4b07575f086050fc6173490af840252026 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 14:43:42 +0200 Subject: [PATCH 13/30] test fixes --- ci/test-7-options-i-m.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test-7-options-i-m.pl b/ci/test-7-options-i-m.pl index 279c740..0cfe2d3 100755 --- a/ci/test-7-options-i-m.pl +++ b/ci/test-7-options-i-m.pl @@ -27,7 +27,7 @@ $cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% l # fping -m { -my $cmd = Test::Command->new(cmd => "fping -m google-public-dns-a.google.com is alive"); +my $cmd = Test::Command->new(cmd => "fping -m google-public-dns-a.google.com"); $cmd->exit_is_num(0); $cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); $cmd->stderr_is_eq(""); From c1fe95f7b768677ab971d3b8f0b4ec60d20690b6 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 23:02:01 +0200 Subject: [PATCH 14/30] more tests --- ci/test-9-option-r-t.pl | 48 +++++++++++++++++++++++++++++++++++++++++ doc/fping.pod | 9 ++++---- 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100755 ci/test-9-option-r-t.pl diff --git a/ci/test-9-option-r-t.pl b/ci/test-9-option-r-t.pl new file mode 100755 index 0000000..3b30d1f --- /dev/null +++ b/ci/test-9-option-r-t.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 6; +use Test::More; +use Time::HiRes qw(gettimeofday tv_interval); +use File::Temp; + +# -r n number of retries (default 3) +# -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) + +# fping -r tested in test-4-options-a-b.pl + +# fping -s +{ +my $cmd = Test::Command->new(cmd => "fping -s 127.0.0.1"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("127.0.0.1 is alive\n"); +$cmd->stderr_like(qr{\s* +\s*1 targets +\s*1 alive +\s*0 unreachable +\s*0 unknown addresses +\s* +\s*0 timeouts \(waiting for response\) +\s*1 ICMP Echos sent +\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\) +}); +} + +# fping -S +{ +my $cmd = Test::Command->new(cmd => "fping -S 127.0.0.1 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 -t tested in test-4-options-a-b.pl diff --git a/doc/fping.pod b/doc/fping.pod index e3296f9..4a6f4ca 100644 --- a/doc/fping.pod +++ b/doc/fping.pod @@ -49,10 +49,11 @@ number. =item B<-B> I -In the default mode, B sends several requests to a target before giving -up, waiting longer for a reply on each successive request. This parameter is -the value by which the wait time is multiplied on each successive request; it -must be entered as a floating-point number (x.y). The default is 1.5. +Backoff factor. In the default mode, B sends several requests to a +target before giving up, waiting longer for a reply on each successive request. +This parameter is the value by which the wait time 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 From 75101dd843336e737e7e51ad0b959c54ec2dc206 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 23:10:46 +0200 Subject: [PATCH 15/30] more tests --- ci/test-10-option-u-v.pl | 24 ++++++++++++++++++++++++ ci/test-2-help.pl | 2 +- ci/test-5-options-c-e.pl | 2 -- ci/test-6-options-f-h.pl | 2 -- ci/test-7-options-i-m.pl | 3 --- ci/test-8-options-n-q.pl | 14 ++++++++++---- ci/test-9-option-r-t.pl | 3 --- src/fping.c | 2 +- 8 files changed, 36 insertions(+), 16 deletions(-) create mode 100755 ci/test-10-option-u-v.pl diff --git a/ci/test-10-option-u-v.pl b/ci/test-10-option-u-v.pl new file mode 100755 index 0000000..f5ef83b --- /dev/null +++ b/ci/test-10-option-u-v.pl @@ -0,0 +1,24 @@ +#!/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+ +fping: comments to david\@schweikert\.ch +}); +$cmd->stderr_is_eq(""); +} diff --git a/ci/test-2-help.pl b/ci/test-2-help.pl index 8f84e4d..72459a7 100755 --- a/ci/test-2-help.pl +++ b/ci/test-2-help.pl @@ -26,6 +26,7 @@ Usage: fping [options] [targets...] -l loop sending pings forever -m ping multiple interfaces on target host -n show targets by name (-d is equivalent) + -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) @@ -36,7 +37,6 @@ Usage: fping [options] [targets...] -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 - -O n set the type of service (tos) flag on the ICMP packets -v show version targets list of targets to check (if no -f specified) diff --git a/ci/test-5-options-c-e.pl b/ci/test-5-options-c-e.pl index c2c0a56..ec84817 100755 --- a/ci/test-5-options-c-e.pl +++ b/ci/test-5-options-c-e.pl @@ -1,8 +1,6 @@ #!/usr/bin/perl -w use Test::Command tests => 12; -use Test::More; -use Time::HiRes qw(gettimeofday tv_interval); # -c n count of pings to send to each target (default 1) # -C n same as -c, report results in verbose format diff --git a/ci/test-6-options-f-h.pl b/ci/test-6-options-f-h.pl index 7ca7e8c..6168b5a 100755 --- a/ci/test-6-options-f-h.pl +++ b/ci/test-6-options-f-h.pl @@ -1,8 +1,6 @@ #!/usr/bin/perl -w use Test::Command tests => 15; -use Test::More; -use Time::HiRes qw(gettimeofday tv_interval); use File::Temp; # -f file read list of targets from a file ( - means stdin) (only if no -g specified) diff --git a/ci/test-7-options-i-m.pl b/ci/test-7-options-i-m.pl index 0cfe2d3..74ab9f2 100755 --- a/ci/test-7-options-i-m.pl +++ b/ci/test-7-options-i-m.pl @@ -1,9 +1,6 @@ #!/usr/bin/perl -w use Test::Command tests => 7; -use Test::More; -use Time::HiRes qw(gettimeofday tv_interval); -use File::Temp; # -i n interval between sending ping packets (in millisec) (default 25) # -l loop sending pings forever diff --git a/ci/test-8-options-n-q.pl b/ci/test-8-options-n-q.pl index 28e599f..2737dd3 100755 --- a/ci/test-8-options-n-q.pl +++ b/ci/test-8-options-n-q.pl @@ -1,11 +1,9 @@ #!/usr/bin/perl -w -use Test::Command tests => 9; -use Test::More; -use Time::HiRes qw(gettimeofday tv_interval); -use File::Temp; +use Test::Command tests => 12; # -n show targets by name (-d is equivalent) +# -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) @@ -19,6 +17,14 @@ $cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); $cmd->stderr_is_eq(""); } +# fping -O +{ +my $cmd = Test::Command->new(cmd => "fping -O 2 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 -q { my $cmd = Test::Command->new(cmd => "fping -q -p 100 -c 3 127.0.0.1"); diff --git a/ci/test-9-option-r-t.pl b/ci/test-9-option-r-t.pl index 3b30d1f..1d16a7f 100755 --- a/ci/test-9-option-r-t.pl +++ b/ci/test-9-option-r-t.pl @@ -1,9 +1,6 @@ #!/usr/bin/perl -w use Test::Command tests => 6; -use Test::More; -use Time::HiRes qw(gettimeofday tv_interval); -use File::Temp; # -r n number of retries (default 3) # -s print final stats diff --git a/src/fping.c b/src/fping.c index 92154f1..6237090 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2693,6 +2693,7 @@ void usage(int is_error) fprintf(out, " -l loop sending pings forever\n" ); fprintf(out, " -m ping multiple interfaces on target host\n" ); fprintf(out, " -n show targets by name (-d is equivalent)\n" ); + fprintf(out, " -O n set the type of service (tos) flag on the ICMP packets\n" ); fprintf(out, " -p n interval between ping packets to one target (in millisec)\n" ); fprintf(out, " (in looping and counting modes, default %d)\n", perhost_interval / 100 ); fprintf(out, " -q quiet (don't show per-target/per-ping results)\n" ); @@ -2703,7 +2704,6 @@ void usage(int is_error) fprintf(out, " -t n individual target initial timeout (in millisec) (default %d)\n", timeout / 100 ); fprintf(out, " -T n ignored (for compatibility with fping 2.4)\n"); fprintf(out, " -u show targets that are unreachable\n" ); - fprintf(out, " -O n set the type of service (tos) flag on the ICMP packets\n" ); fprintf(out, " -v show version\n" ); fprintf(out, " targets list of targets to check (if no -f specified)\n" ); fprintf(out, "\n"); From f35f4a8cc4a483ed9e166bd1d4c63f3a23de8f79 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 23:19:09 +0200 Subject: [PATCH 16/30] more tests --- ci/test-9-option-r-t.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ci/test-9-option-r-t.pl b/ci/test-9-option-r-t.pl index 1d16a7f..6756624 100755 --- a/ci/test-9-option-r-t.pl +++ b/ci/test-9-option-r-t.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 6; +use Test::Command tests => 9; # -r n number of retries (default 3) # -s print final stats @@ -41,5 +41,12 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n"); $cmd->stderr_is_eq(""); } +# fping6 -S +{ +my $cmd = Test::Command->new(cmd => "fping6 -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 From 1d576326baad8174b81339e65655036d61c6668e Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 23:26:16 +0200 Subject: [PATCH 17/30] more tests --- ci/test-11-nopriv.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ci/test-11-nopriv.pl diff --git a/ci/test-11-nopriv.pl b/ci/test-11-nopriv.pl new file mode 100644 index 0000000..7f90f0e --- /dev/null +++ b/ci/test-11-nopriv.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl -w + +use Test::Command 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_is_eq("(null): can't create socket (must run as root?) : Permission denied\n"); +} + +# fping6 +{ +my $cmd = Test::Command->new(cmd => "/tmp/fping6.copy ::1"); +$cmd->exit_is_num(4); +$cmd->stdout_is_eq(""); +$cmd->stderr_is_eq("(null): can't create raw socket (must run as root?) : Protocol not supported\n"); +} From c9f276b3cd74ba7f2760720f29d6b38f7e91ab89 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 23:39:39 +0200 Subject: [PATCH 18/30] more tests --- ci/test-11-nopriv.pl | 0 ci/test-12-option-type.pl | 10 ++++++++++ src/fping.c | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) mode change 100644 => 100755 ci/test-11-nopriv.pl create mode 100755 ci/test-12-option-type.pl diff --git a/ci/test-11-nopriv.pl b/ci/test-11-nopriv.pl old mode 100644 new mode 100755 diff --git a/ci/test-12-option-type.pl b/ci/test-12-option-type.pl new file mode 100755 index 0000000..d6e3211 --- /dev/null +++ b/ci/test-12-option-type.pl @@ -0,0 +1,10 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 33; + +for my $arg (qw(i B c C H i O p Q r t)) { + my $cmd = Test::Command->new(cmd => "fping -$arg xxx"); + $cmd->exit_is_num(1); + $cmd->stdout_is_eq(""); + $cmd->stderr_like(qr{Usage:}); +} diff --git a/src/fping.c b/src/fping.c index 6237090..b62983c 100644 --- a/src/fping.c +++ b/src/fping.c @@ -392,7 +392,8 @@ int main( int argc, char **argv ) break; case 'r': - retry = ( unsigned int )atoi( optarg ); + if(!(retry = ( unsigned int )atoi( optarg ))) + usage(1); break; case 'i': @@ -550,6 +551,9 @@ int main( int argc, char **argv ) perror("setting type of service octet IP_TOS"); } } + else { + usage(1); + } break; default: fprintf(stderr, "see 'fping -h' for usage information\n"); From 3aa530c2ff0b7cabd0a5d767c4e22cc217817143 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 23:41:54 +0200 Subject: [PATCH 19/30] more tests --- ci/test-11-nopriv.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test-11-nopriv.pl b/ci/test-11-nopriv.pl index 7f90f0e..5b24a32 100755 --- a/ci/test-11-nopriv.pl +++ b/ci/test-11-nopriv.pl @@ -13,7 +13,7 @@ system("cp $fping6_bin /tmp/fping6.copy; chmod +x /tmp/fping6.copy"); my $cmd = Test::Command->new(cmd => "/tmp/fping.copy 127.0.0.1"); $cmd->exit_is_num(4); $cmd->stdout_is_eq(""); -$cmd->stderr_is_eq("(null): can't create socket (must run as root?) : Permission denied\n"); +$cmd->stderr_like(qr{\(null\): can't create socket \(must run as root\?\) : .*\n}); } # fping6 @@ -21,5 +21,5 @@ $cmd->stderr_is_eq("(null): can't create socket (must run as root?) : Permission my $cmd = Test::Command->new(cmd => "/tmp/fping6.copy ::1"); $cmd->exit_is_num(4); $cmd->stdout_is_eq(""); -$cmd->stderr_is_eq("(null): can't create raw socket (must run as root?) : Protocol not supported\n"); +$cmd->stderr_like(qr{\(null\): can't create raw socket \(must run as root\?\) : .*\n}); } From b779e14db63b92d346b82d503fb91c2c3c78cbf0 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Fri, 2 May 2014 23:51:49 +0200 Subject: [PATCH 20/30] test fix --- src/fping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fping.c b/src/fping.c index b62983c..d79d2eb 100644 --- a/src/fping.c +++ b/src/fping.c @@ -392,7 +392,7 @@ int main( int argc, char **argv ) break; case 'r': - if(!(retry = ( unsigned int )atoi( optarg ))) + if (!sscanf(optarg,"%i",&retry)) usage(1); break; From e79444f09a36e70f54a3bf370bf29aa01d9c72d7 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sat, 3 May 2014 00:06:07 +0200 Subject: [PATCH 21/30] more tests --- ci/test-12-option-type.pl | 4 ++-- src/fping.c | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ci/test-12-option-type.pl b/ci/test-12-option-type.pl index d6e3211..f3c8c2f 100755 --- a/ci/test-12-option-type.pl +++ b/ci/test-12-option-type.pl @@ -1,8 +1,8 @@ #!/usr/bin/perl -w -use Test::Command tests => 33; +use Test::Command tests => 36; -for my $arg (qw(i B c C H i O p Q r t)) { +for my $arg (qw(i b B c C H i O p Q r t)) { my $cmd = Test::Command->new(cmd => "fping -$arg xxx"); $cmd->exit_is_num(1); $cmd->stdout_is_eq(""); diff --git a/src/fping.c b/src/fping.c index d79d2eb..cf8d5db 100644 --- a/src/fping.c +++ b/src/fping.c @@ -424,9 +424,7 @@ int main( int argc, char **argv ) break; case 'b': - errno = 0; - ping_data_size = (unsigned int) strtol(optarg, (char **)NULL, 10); - if( errno ) + if (!sscanf(optarg,"%i",&ping_data_size)) usage(1); break; From 2b5d9ef7952f4e03bd78ccc67d364b035e6a7989 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 21:16:11 +0200 Subject: [PATCH 22/30] remove support for NIS groups, do not retry twice DNS lookup on DNS lookup problem --- ChangeLog | 2 ++ src/fping.c | 37 +------------------------------------ src/options.h | 3 --- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index da9a6fd..dd70efd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ UNRELEASED * More tests added * Fix confusing error message with -g and IPv6 addresses (#58, reported by Axel Beckert) * Allow option '-f' also for non-root (since setuid privileges are dropped) + * Remove support for NIS groups + * Do not retry twice DNS lookup on DNS lookup problem 2014-03-08 David Schweikert * Version 3.9 diff --git a/src/fping.c b/src/fping.c index cf8d5db..43cac42 100644 --- a/src/fping.c +++ b/src/fping.c @@ -1986,45 +1986,10 @@ void add_name( char *name ) host_ent = gethostbyname( name ); if( host_ent == NULL ) { - if( h_errno == TRY_AGAIN ) - { - u_sleep( DNS_TIMEOUT ); - host_ent = gethostbyname( name ); - - }/* IF */ - - if( host_ent == NULL ) - { -#ifdef NIS_GROUPS - - /* maybe it's the name of a NIS netgroup */ - char *machine, *user_ignored, *domain_ignored; - setnetgrent( name ); - if( getnetgrent( &machine, &user_ignored, &domain_ignored ) == 0 ) - { - endnetgrent(); - print_warning("%s address not found\n", name ); - - num_noaddress++; - return; - - }/* IF */ - else - add_name(machine); - - while( getnetgrent( &machine, &user_ignored, &domain_ignored ) ) - add_name(machine); - - endnetgrent(); - return; -#else print_warning("%s address not found\n", name ); - num_noaddress++; return ; -#endif /* NIS_GROUPS */ - }/* IF */ - }/* IF */ + } if(host_ent->h_addrtype != AF_INET) { print_warning("%s: IPv6 address returned by gethostbyname (options inet6 in resolv.conf?)\n", name ); diff --git a/src/options.h b/src/options.h index 3c99d80..bbc93d1 100644 --- a/src/options.h +++ b/src/options.h @@ -49,6 +49,3 @@ #ifndef DNS_TIMEOUT #define DNS_TIMEOUT 1000 /* time in micro_sec for dns retry */ #endif - -/* NIS_GROUPS allows input name to be an NIS netgroup name */ -/* #define NIS_GROUPS=1 */ From c4c3068bbb62cb332d9ac093950a6f5a9218c74a Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 21:22:28 +0200 Subject: [PATCH 23/30] more tests --- ci/test-13-unknown-host.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 ci/test-13-unknown-host.pl diff --git a/ci/test-13-unknown-host.pl b/ci/test-13-unknown-host.pl new file mode 100755 index 0000000..734bd09 --- /dev/null +++ b/ci/test-13-unknown-host.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 6; + +# fping +{ +my $cmd = Test::Command->new(cmd => "fping nosuchname.example.com"); +$cmd->exit_is_num(1); +$cmd->stdout_is_eq(""); +$cmd->stderr_is_eq("nosuchname.example.com address not found\n"); +} + +# fping6 +{ +my $cmd = Test::Command->new(cmd => "fping6 nosuchname.example.com"); +$cmd->exit_is_num(1); +$cmd->stdout_is_eq(""); +$cmd->stderr_is_eq("nosuchname.example.com: Name or service not known\n"); +} From 7b8899043d3cf92fb9133585fd43152c1c07102c Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 21:36:37 +0200 Subject: [PATCH 24/30] more tests --- ci/test-6-options-f-h.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ci/test-6-options-f-h.pl b/ci/test-6-options-f-h.pl index 6168b5a..8b252cc 100755 --- a/ci/test-6-options-f-h.pl +++ b/ci/test-6-options-f-h.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 15; +use Test::Command tests => 18; use File::Temp; # -f file read list of targets from a file ( - means stdin) (only if no -g specified) @@ -37,7 +37,15 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n"); $cmd->stderr_is_eq(""); } -# fping -g +# fping -g (range) +{ +my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1 127.0.0.5"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n127.0.0.3 is alive\n127.0.0.4 is alive\n127.0.0.5 is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -g (cidr) { my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1/30"); $cmd->exit_is_num(0); From a07e244a571db6bdeae69f523ab21427b2db7c5a Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 21:41:31 +0200 Subject: [PATCH 25/30] more tests --- ci/test-9-option-r-t.pl | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ci/test-9-option-r-t.pl b/ci/test-9-option-r-t.pl index 6756624..afb1b24 100755 --- a/ci/test-9-option-r-t.pl +++ b/ci/test-9-option-r-t.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 9; +use Test::Command tests => 12; # -r n number of retries (default 3) # -s print final stats @@ -33,6 +33,29 @@ $cmd->stderr_like(qr{\s* }); } +# fping -s (no host reachable) +{ +my $cmd = Test::Command->new(cmd => "fping -r0 -t100 -s 8.8.0.0"); +$cmd->exit_is_num(1); +$cmd->stdout_is_eq("8.8.0.0 is unreachable\n"); +$cmd->stderr_like(qr{\s* +\s*1 targets +\s*0 alive +\s*1 unreachable +\s*0 unknown addresses +\s* +\s*1 timeouts \(waiting for response\) +\s*1 ICMP Echos sent +\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\) +}); +} + # fping -S { my $cmd = Test::Command->new(cmd => "fping -S 127.0.0.1 127.0.0.1"); From fe12f0dbabeb351423edec1a7df87b6086064ec0 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 21:54:59 +0200 Subject: [PATCH 26/30] more tests --- ci/test-14-ping-internet-hosts.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 ci/test-14-ping-internet-hosts.pl diff --git a/ci/test-14-ping-internet-hosts.pl b/ci/test-14-ping-internet-hosts.pl new file mode 100755 index 0000000..249f02c --- /dev/null +++ b/ci/test-14-ping-internet-hosts.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl -w + +use Test::Command tests => 3; + +# 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"); +$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 = \d+\.\d+/\d+\.\d+/\d+\.\d+ +4\.2\.2\.5\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = \d+\.\d+/\d+\.\d+/\d+\.\d+ +www\.france-telecom\.fr\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = \d+\.\d+/\d+\.\d+/\d+\.\d+ +www\.google\.com\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = \d+\.\d+/\d+\.\d+/\d+\.\d+ +}); +} From 314b8debd9c62dfb126fd7376afb5f76dad51b5e Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 22:04:10 +0200 Subject: [PATCH 27/30] more tests --- ci/test-4-options-a-b.pl | 58 ++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/ci/test-4-options-a-b.pl b/ci/test-4-options-a-b.pl index 200a7f1..c41ec02 100755 --- a/ci/test-4-options-a-b.pl +++ b/ci/test-4-options-a-b.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 14; +use Test::Command tests => 20; use Test::More; use Time::HiRes qw(gettimeofday tv_interval); @@ -10,30 +10,54 @@ use Time::HiRes qw(gettimeofday tv_interval); # -B f set exponential backoff factor to f # fping -a -my $cmd1 = Test::Command->new(cmd => "fping -a 127.0.0.1 127.0.0.2"); -$cmd1->exit_is_num(0); -$cmd1->stdout_is_eq("127.0.0.1\n127.0.0.2\n"); -$cmd1->stderr_is_eq(""); +{ +my $cmd = Test::Command->new(cmd => "fping -a 127.0.0.1 127.0.0.2"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("127.0.0.1\n127.0.0.2\n"); +$cmd->stderr_is_eq(""); +} # fping -A -my $cmd2 = Test::Command->new(cmd => "fping -A 127.0.0.1"); -$cmd2->exit_is_num(0); -$cmd2->stdout_is_eq("127.0.0.1 is alive\n"); -$cmd2->stderr_is_eq(""); +{ +my $cmd = Test::Command->new(cmd => "fping -A localhost"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("127.0.0.1 is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -A -n +{ +my $cmd = Test::Command->new(cmd => "fping -A -n localhost"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("localhost (127.0.0.1) is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping6 -A -n +{ +my $cmd = Test::Command->new(cmd => "fping6 -n -A ip6-localhost"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("ip6-localhost (::1) is alive\n"); +$cmd->stderr_is_eq(""); +} # fping -b -my $cmd3 = Test::Command->new(cmd => "fping -b 1000 127.0.0.1"); -$cmd3->exit_is_num(0); -$cmd3->stdout_is_eq("127.0.0.1 is alive\n"); -$cmd3->stderr_is_eq(""); +{ +my $cmd = Test::Command->new(cmd => "fping -b 1000 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 -B +{ my $t0 = [gettimeofday]; -my $cmd4 = Test::Command->new(cmd => "fping -t 100 -r 3 -B 2 8.8.8.7"); -$cmd4->exit_is_num(1); -$cmd4->stdout_is_eq("8.8.8.7 is unreachable\n"); -$cmd4->stderr_is_eq(""); +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_is_eq(""); my $elapsed = tv_interval($t0); # 0.1 + 0.2 + 0.4 + 0.8 = 1.5 cmp_ok($elapsed, '>=', 1.5); cmp_ok($elapsed, '<', 1.7); +} From 4d6861c2c35a31ca9d79fc65c1ca72f5e1a7eb34 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 22:09:48 +0200 Subject: [PATCH 28/30] more tests --- ci/test-4-options-a-b.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test-4-options-a-b.pl b/ci/test-4-options-a-b.pl index c41ec02..150231f 100755 --- a/ci/test-4-options-a-b.pl +++ b/ci/test-4-options-a-b.pl @@ -35,9 +35,9 @@ $cmd->stderr_is_eq(""); # fping6 -A -n { -my $cmd = Test::Command->new(cmd => "fping6 -n -A ip6-localhost"); +my $cmd = Test::Command->new(cmd => "fping6 -n -A 2001:4860:4860::8888"); $cmd->exit_is_num(0); -$cmd->stdout_is_eq("ip6-localhost (::1) is alive\n"); +$cmd->stdout_is_eq("google-public-dns-a.google.com (2001:4860:4860::8888) is alive\n"); $cmd->stderr_is_eq(""); } From 609f4f17c4b896b86fe06bffc1d640b7d22e83c4 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 22:22:53 +0200 Subject: [PATCH 29/30] Better document -B backoff-factor and when it can be used (#33, Oleksiy Zagorskyi), fixes #33 --- ChangeLog | 1 + doc/fping.pod | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd70efd..1dd5dc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ UNRELEASED * Allow option '-f' also for non-root (since setuid privileges are dropped) * Remove support for NIS groups * Do not retry twice DNS lookup on DNS lookup problem + * Better document -B backoff-factor and when it can be used (#33, Oleksiy Zagorskyi) 2014-03-08 David Schweikert * Version 3.9 diff --git a/doc/fping.pod b/doc/fping.pod index 4a6f4ca..8fba001 100644 --- a/doc/fping.pod +++ b/doc/fping.pod @@ -51,8 +51,8 @@ number. Backoff factor. In the default mode, B sends several requests to a target before giving up, waiting longer for a reply on each successive request. -This parameter is the value by which the wait time is multiplied on each -successive request; it must be entered as a floating-point number (x.y). The +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 @@ -166,7 +166,9 @@ Set the interface (requires SO_BINDTODEVICE support) Initial target timeout in milliseconds (default 500). In the default mode, this is the amount of time that B waits for a response to its first request. -Successive timeouts are multiplied by the backoff factor. +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>). =item B<-T> I From 3aed2604bb105eefdb84a649e6157d68c6bbd417 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Sun, 4 May 2014 22:25:06 +0200 Subject: [PATCH 30/30] prepare v3.10 --- ChangeLog | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1dd5dc9..7ead554 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ -UNRELEASED - * More tests added +2014-05-03 David Schweikert + * Version 3.10 * Fix confusing error message with -g and IPv6 addresses (#58, reported by Axel Beckert) * Allow option '-f' also for non-root (since setuid privileges are dropped) - * Remove support for NIS groups * Do not retry twice DNS lookup on DNS lookup problem + * Remove support for NIS groups * Better document -B backoff-factor and when it can be used (#33, Oleksiy Zagorskyi) + * More tests added 2014-03-08 David Schweikert * Version 3.9