fping and fping6 unification, fixes #80

pull/89/merge
David Schweikert 8 years ago
parent 3b5c426985
commit 2f95647566

@ -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> 2017-02-09 David Schweikert <david@schweikert.ch>
* Version 3.16 * Version 3.16
* (feature) Support kernel-timestamping of received packets (#46) * (feature) Support kernel-timestamping of received packets (#46)

@ -13,7 +13,6 @@ autoreconf -i
make CFLAGS="-g -fprofile-arcs -ftest-coverage" make CFLAGS="-g -fprofile-arcs -ftest-coverage"
## setcap currently doesn't work anymore on travis-ci ## setcap currently doesn't work anymore on travis-ci
#sudo setcap cap_net_raw+ep src/fping #sudo setcap cap_net_raw+ep src/fping
#sudo setcap cap_net_raw+ep src/fping6
## setcap debugging: ## setcap debugging:
#pwd #pwd
#df -k . #df -k .
@ -26,6 +25,4 @@ make CFLAGS="-g -fprofile-arcs -ftest-coverage"
# use setuid, since setcap is not available # use setuid, since setcap is not available
sudo chown root src/fping sudo chown root src/fping
sudo chown root src/fping6
sudo chmod u+s src/fping sudo chmod u+s src/fping
sudo chmod u+s src/fping6

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

@ -17,7 +17,7 @@ SKIP: {
if(system("/sbin/ifconfig | grep inet6") != 0) { if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 3; 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->exit_is_num(0);
$cmd->stdout_is_eq("::1 is alive\n"); $cmd->stdout_is_eq("::1 is alive\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");

@ -11,6 +11,8 @@ $cmd1->exit_is_num(0);
$cmd1->stdout_is_eq(<<END); $cmd1->stdout_is_eq(<<END);
Usage: fping [options] [targets...] Usage: fping [options] [targets...]
-4 only use IPv4 addresses
-6 only use IPv6 addresses
-a show targets that are alive -a show targets that are alive
-A show targets by address -A show targets by address
-b n amount of ping data to send, in bytes (default 56) -b n amount of ping data to send, in bytes (default 56)

@ -24,7 +24,7 @@ END
my $cmd5 = Test::Command->new(cmd => "fping -H 300 127.0.0.1"); my $cmd5 = Test::Command->new(cmd => "fping -H 300 127.0.0.1");
$cmd5->exit_is_num(1); $cmd5->exit_is_num(1);
$cmd5->stdout_is_eq(""); $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 # fping -a -u
my $cmd6 = Test::Command->new(cmd => "fping -a -u 127.0.0.1"); 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->stdout_is_eq("");
$cmd7->stderr_is_eq("fping: specify only one of c, l\n"); $cmd7->stderr_is_eq("fping: specify only one of c, l\n");
# fping -b 65489 # fping -b 65509
my $cmd8 = Test::Command->new(cmd => "fping -b 65489 127.0.0.1"); my $cmd8 = Test::Command->new(cmd => "fping -b 65509 127.0.0.1");
$cmd8->exit_is_num(1); $cmd8->exit_is_num(1);
$cmd8->stdout_is_eq(""); $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 # fping -B 0.9
my $cmd9 = Test::Command->new(cmd => "fping -B 0.9 127.0.0.1"); my $cmd9 = Test::Command->new(cmd => "fping -B 0.9 127.0.0.1");

@ -1,14 +1,57 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use Test::Command tests => 14; use Test::Command tests => 29;
use Test::More; use Test::More;
use Time::HiRes qw(gettimeofday tv_interval); 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 that are alive
# -A show targets by address # -A show targets by address
# -b n amount of ping data to send, in bytes (default 56) # -b n amount of ping data to send, in bytes (default 56)
# -B f set exponential backoff factor to f # -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 # fping -a
{ {
my $cmd = Test::Command->new(cmd => "fping -a 127.0.0.1 127.0.0.2"); my $cmd = Test::Command->new(cmd => "fping -a 127.0.0.1 127.0.0.2");
@ -19,7 +62,7 @@ $cmd->stderr_is_eq("");
# fping -A # 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->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.1 is alive\n"); $cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");

@ -9,7 +9,7 @@ use Test::Command tests => 12;
# fping -c n # 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->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\) $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\) 127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
@ -24,7 +24,7 @@ $cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = 0\.\d+/0\
# fping -C n # 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->exit_is_num(0);
$cmd->stdout_like(qr{localhost : \[0\], 84 bytes, 0\.\d+ ms \(0\.\d+ avg, 0% loss\) $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\) 127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)

@ -66,7 +66,7 @@ $cmd->stderr_is_eq("");
my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/33"); my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/33");
$cmd->exit_is_num(1); $cmd->exit_is_num(1);
$cmd->stdout_is_eq(""); $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 # fping -H

@ -22,7 +22,7 @@ SKIP: {
if(system("/sbin/ifconfig | grep inet6") != 0) { if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 3; 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->exit_is_num(0);
$cmd->stdout_is_eq(""); $cmd->stdout_is_eq("");
$cmd->stderr_like(qr{::1 : xmt/rcv/%loss = 3/3/0%.*}); $cmd->stderr_like(qr{::1 : xmt/rcv/%loss = 3/3/0%.*});
@ -84,12 +84,12 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");
} }
# fping6 -S # fping -S
SKIP: { SKIP: {
if(system("/sbin/ifconfig | grep inet6") != 0) { if(system("/sbin/ifconfig | grep inet6") != 0) {
skip 'No IPv6 on this host', 3; 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->exit_is_num(0);
$cmd->stdout_is_eq("::1 is alive\n"); $cmd->stdout_is_eq("::1 is alive\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");

@ -7,13 +7,11 @@ if( $^O eq 'darwin' ) {
plan skip_all => 'Test irrelevant on MacOS'; plan skip_all => 'Test irrelevant on MacOS';
exit 0; exit 0;
} }
plan tests => 6; plan tests => 3;
# run without privileges # run without privileges
my $fping_bin = `which fping`; chomp $fping_bin; 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 $fping_bin /tmp/fping.copy; chmod +x /tmp/fping.copy");
system("cp $fping6_bin /tmp/fping6.copy; chmod +x /tmp/fping6.copy");
# fping # fping
{ {
@ -22,11 +20,3 @@ $cmd->exit_is_num(4);
$cmd->stdout_is_eq(""); $cmd->stdout_is_eq("");
$cmd->stderr_like(qr{: can't create socket \(must run as root\?\) : .*\n}); $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});
}

@ -1,6 +1,6 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use Test::Command tests => 6; use Test::Command tests => 3;
# fping # fping
{ {
@ -9,11 +9,3 @@ $cmd->exit_is_num(2);
$cmd->stdout_is_eq(""); $cmd->stdout_is_eq("");
$cmd->stderr_like(qr{^nosuchname\.example\.com: .*not (known|found)}); $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,7 +9,7 @@ if(!gethostbyname("www.google.com")) {
exit 0; exit 0;
} }
plan tests => 18; plan tests => 21;
my $re_num = qr{\d+(?:\.\d+)?}; my $re_num = qr{\d+(?:\.\d+)?};
@ -33,35 +33,35 @@ $cmd->stdout_is_eq("google-public-dns-a.google.com (8.8.8.8) is alive\n");
$cmd->stderr_is_eq(""); $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->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("google-public-dns-a.google.com (8.8.8.8) is alive\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");
} }
# fping6 -A -n # fping -A -n (IPv6)
SKIP: { SKIP: {
if(system("/sbin/ifconfig | grep inet6.*Scope:Global") != 0) { if(system("/sbin/ifconfig | grep inet6.*Scope:Global") != 0) {
skip 'No IPv6 on this host', 3; 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->exit_is_num(0);
$cmd->stdout_is_eq("google-public-dns-a.google.com (2001:4860:4860::8888) is alive\n"); $cmd->stdout_is_eq("google-public-dns-a.google.com (2001:4860:4860::8888) is alive\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");
} }
# fping -m # fping -m
#SKIP: { SKIP: {
# if(system("/sbin/ifconfig | grep inet6.*Scope:Global") != 0) { if(system("/sbin/ifconfig | grep inet6.*Scope:Global") != 0) {
# skip 'No IPv6 on this host', 3; skip 'No IPv6 on this host', 3;
# } }
# my $cmd = Test::Command->new(cmd => "fping -A -m google-public-dns-a.google.com"); my $cmd = Test::Command->new(cmd => "fping -A -m google-public-dns-a.google.com");
# $cmd->exit_is_num(0); $cmd->exit_is_num(0);
# $cmd->stdout_is_eq("2001:4860:4860::8888 is alive\n8.8.8.8 is alive\n"); $cmd->stdout_is_eq("2001:4860:4860::8888 is alive\n8.8.8.8 is alive\n");
# $cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");
#} }
# fping -n # fping -n
{ {

@ -7,4 +7,4 @@ use Test::Command tests => 3;
my $cmd1 = Test::Command->new(cmd => "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->exit_is_num(1);
$cmd1->stdout_is_eq(""); $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");

@ -3,35 +3,38 @@ dnl Process this file with autoconf to produce a configure script.
dnl Minimum Autoconf version required. dnl Minimum Autoconf version required.
AC_PREREQ(2.59) 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], AC_ARG_ENABLE([ipv4],
[ --enable-ipv4 Build IPv4 capable fping], AS_HELP_STRING([--disable-ipv4], [Disable support for pinging IPv4 hosts]))
[case "${enableval}" in AM_CONDITIONAL([IPV4], [test "x$enable_ipv4" != "xno"])
yes) ipv4=true ;; AM_COND_IF([IPV4], [AC_DEFINE([IPV4], [1], [IPv4 enabled])])
no) ipv4=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-ipv4]) ;;
esac],[ipv4=true])
AM_CONDITIONAL([IPV4], [test x$ipv4 = xtrue])
dnl --disable-ipv6
AC_ARG_ENABLE([ipv6], AC_ARG_ENABLE([ipv6],
[ --enable-ipv6 Build IPv6 capable fping6], AS_HELP_STRING([--disable-ipv6], [Disable support for pinging IPv6 hosts]))
[case "${enableval}" in AS_IF([test "x$enable_ipv6" != "xno"], [
yes) ipv6=true ;; dnl Test if IPv6 is supported
no) ipv6=false ;; AC_CHECK_HEADERS([netinet/icmp6.h], [have_ipv6="yes"], [], [[
*) AC_MSG_ERROR([bad value ${enableval} for --enable-ipv6]) ;; #include <netinet/in.h>
esac],[ipv6=false]) ]])
AM_CONDITIONAL([IPV6], [test x$ipv6 = xtrue]) ])
dnl Can't disable both IPv4 and IPv6
if test x$ipv4 = xfalse && test x$ipv6 = xfalse; then AS_IF([test "x$enable_ipv4" = "xno" -a "x$enable_ipv6" = "xno"], [
AC_MSG_ERROR([You must enable at least one of IPv4 and IPv6.]) AC_MSG_ERROR([Need to enable IPv4 or IPv6. Can't disable both!)])
fi ])
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], 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_TIMESTAMP)]))
AS_IF([test "x$enable_timestamp" != "xno"], [ 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>]) #include <sys/socket.h>])
]) ])
dnl Test if --enable-timestamp is explicitely enabled and make an error if this platform doesn't support it dnl Test if --enable-timestamp is explicitely enabled and make an error if this platform doesn't support it
@ -80,7 +83,7 @@ AH_BOTTOM([
]) ])
dnl Checks for header files. 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 AC_CONFIG_FILES([Makefile
doc/Makefile doc/Makefile

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

@ -29,6 +29,15 @@ addresses instead of IPv4.
=over 5 =over 5
=item B<-4>
Restrict name resolution and IPs to IPv4 addresses.
=item B<-6>
Restrict name resolution and IPs to IPv6 addresses. If the program name is
'fping6' (via a sym-link, for example), then '-6' is implicitly added.
=item B<-a> =item B<-a>
Show systems that are alive. Show systems that are alive.

@ -1,18 +1,11 @@
AM_CFLAGS = -Wall -Wextra -Wno-sign-compare 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
fping_DEPENDENCIES = ../config.h
if IPV4
prog += fping
endif
if IPV6 if IPV6
prog += fping6 fping_SOURCES += socket6.c
fping_CFLAGS = $(AM_CFLAGS) -DIPV6
endif 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,14 +7,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#ifndef IPV6
#define FPING_INADDR struct in_addr
#define FPING_ICMPHDR struct icmp
#else
#define FPING_INADDR struct in6_addr
#define FPING_ICMPHDR struct icmp6_hdr
#endif
/* fping.c */ /* fping.c */
void crash_and_burn( char *message ); void crash_and_burn( char *message );
void errno_crash_and_burn( char *message ); void errno_crash_and_burn( char *message );
@ -22,9 +14,15 @@ int in_cksum( unsigned short *p, int n );
int random_data_flag; int random_data_flag;
/* socket.c */ /* socket.c */
int open_ping_socket(); int open_ping_socket_ipv4();
void init_ping_buffer(size_t ping_data_size); void init_ping_buffer_ipv4(size_t ping_data_size);
void socket_set_src_addr(int s, FPING_INADDR src_addr); void socket_set_src_addr_ipv4(int s, struct in_addr *src_addr);
int socket_sendto_ping(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id); 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();
void init_ping_buffer_ipv6(size_t ping_data_size);
void socket_set_src_addr_ipv6(int s, struct in6_addr *src_addr);
int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
#endif
#endif #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,8 +44,8 @@
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
char* ping_buffer = 0; char* ping_buffer_ipv4 = 0;
size_t ping_pkt_size; size_t ping_pkt_size_ipv4;
int open_ping_socket_ipv4() int open_ping_socket_ipv4()
{ {
@ -83,18 +83,18 @@ int open_ping_socket_ipv4()
void init_ping_buffer_ipv4(size_t ping_data_size) void init_ping_buffer_ipv4(size_t ping_data_size)
{ {
/* allocate ping buffer */ /* allocate ping buffer */
ping_pkt_size = ping_data_size + ICMP_MINLEN; ping_pkt_size_ipv4 = ping_data_size + ICMP_MINLEN;
ping_buffer = (char*)calloc(1, ping_pkt_size); ping_buffer_ipv4 = (char*)calloc(1, ping_pkt_size_ipv4);
if (!ping_buffer) if (!ping_buffer_ipv4)
crash_and_burn("can't malloc ping packet"); 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)
{ {
struct sockaddr_in sa; struct sockaddr_in sa;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_addr = src_addr; sa.sin_addr = *src_addr;
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0) if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
errno_crash_and_burn("cannot bind source address"); errno_crash_and_burn("cannot bind source address");
@ -122,7 +122,7 @@ int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len,
struct icmp* icp; struct icmp* icp;
int n; int n;
icp = (struct icmp*)ping_buffer; icp = (struct icmp*)ping_buffer_ipv4;
icp->icmp_type = ICMP_ECHO; icp->icmp_type = ICMP_ECHO;
icp->icmp_code = 0; icp->icmp_code = 0;
@ -131,14 +131,14 @@ int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len,
icp->icmp_id = htons(icmp_id_nr); icp->icmp_id = htons(icmp_id_nr);
if (random_data_flag) { if (random_data_flag) {
for (n = ((void*)&icp->icmp_data - (void*)icp); n < ping_pkt_size; ++n) { for (n = ((char*)&icp->icmp_data - (char*)icp); n < ping_pkt_size_ipv4; ++n) {
ping_buffer[n] = random() & 0xFF; ping_buffer_ipv4[n] = random() & 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; return n;
} }

@ -43,8 +43,8 @@
#include <netinet/icmp6.h> #include <netinet/icmp6.h>
char* ping_buffer = 0; char* ping_buffer_ipv6 = 0;
size_t ping_pkt_size; size_t ping_pkt_size_ipv6;
int open_ping_socket_ipv6() int open_ping_socket_ipv6()
{ {
@ -82,18 +82,18 @@ int open_ping_socket_ipv6()
void init_ping_buffer_ipv6(size_t ping_data_size) void init_ping_buffer_ipv6(size_t ping_data_size)
{ {
/* allocate ping buffer */ /* allocate ping buffer */
ping_pkt_size = ping_data_size + sizeof(struct icmp6_hdr); ping_pkt_size_ipv6 = ping_data_size + sizeof(struct icmp6_hdr);
ping_buffer = (char*)calloc(1, ping_pkt_size); ping_buffer_ipv6 = (char*)calloc(1, ping_pkt_size_ipv6);
if (!ping_buffer) if (!ping_buffer_ipv6)
crash_and_burn("can't malloc ping packet"); 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)
{ {
struct sockaddr_in6 sa; struct sockaddr_in6 sa;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sin6_family = AF_INET6; sa.sin6_family = AF_INET6;
sa.sin6_addr = src_addr; sa.sin6_addr = *src_addr;
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0) if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
errno_crash_and_burn("cannot bind source address"); errno_crash_and_burn("cannot bind source address");
@ -104,21 +104,21 @@ int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len,
struct icmp6_hdr* icp; struct icmp6_hdr* icp;
int n; int n;
icp = (struct icmp6_hdr*)ping_buffer; icp = (struct icmp6_hdr*)ping_buffer_ipv6;
icp->icmp6_type = ICMP6_ECHO_REQUEST; icp->icmp6_type = ICMP6_ECHO_REQUEST;
icp->icmp6_code = 0; icp->icmp6_code = 0;
icp->icmp6_seq = htons(icmp_seq_nr); icp->icmp6_seq = htons(icmp_seq_nr);
icp->icmp6_id = htons(icmp_id_nr); icp->icmp6_id = htons(icmp_id_nr);
if (random_data_flag) { if (random_data_flag) {
for (n = sizeof(struct icmp6_hdr); n < ping_pkt_size; ++n) { for (n = sizeof(struct icmp6_hdr); n < ping_pkt_size_ipv6; ++n) {
ping_buffer[n] = random() & 0xFF; ping_buffer_ipv6[n] = random() & 0xFF;
} }
} }
icp->icmp6_cksum = 0; /* The IPv6 stack calculates the checksum for us... */ 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; return n;
} }

@ -1 +1,5 @@
gcc -DHAVE_CONFIG_H -D_BSD_SOURCE -D_POSIX_SOURCE -I.. -Wall -std=c89 -pedantic -c -o fping.o fping.c #!/bin/sh
for f in fping.c socket4.c socket6.c seqmap.c; do
gcc -DHAVE_CONFIG_H -D_BSD_SOURCE -D_POSIX_SOURCE -I.. -Wall -std=c89 -pedantic -c -o /dev/null $f
done

Loading…
Cancel
Save