ipv4/ipv6 unification fixes

pull/89/merge
David Schweikert 8 years ago
parent 3c53d9be3f
commit 12971e5409

@ -0,0 +1,5 @@
- implement -4
- implement -6
- test -4
- test -6
- fix -m

@ -11,9 +11,8 @@ fi
autoreconf -i autoreconf -i
./configure --enable-ipv4 --enable-ipv6 --prefix=/opt/fping ./configure --enable-ipv4 --enable-ipv6 --prefix=/opt/fping
make CFLAGS="-g -fprofile-arcs -ftest-coverage" make CFLAGS="-g -fprofile-arcs -ftest-coverage"
## setcap currently doesn't worn 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("");

@ -19,7 +19,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\)

@ -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)});
}

@ -41,12 +41,12 @@ $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 -n -A 2001:4860:4860::8888");
$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("");

@ -8,4 +8,6 @@ fping_DEPENDENCIES = ../config.h
if IPV6 if IPV6
fping_SOURCES += socket6.c fping_SOURCES += socket6.c
fping_CFLAGS = $(AM_CFLAGS) -DIPV6 fping_CFLAGS = $(AM_CFLAGS) -DIPV6
install-exec-hook:
ln -s fping$(EXEEXT) $(DESTDIR)$(sbindir)/fping6
endif endif

@ -235,18 +235,15 @@ HOST_ENTRY *ev_last;
char *prog; char *prog;
int ident; /* our pid */ int ident; /* our pid */
int socket4 = 0; int socket4 = 0;
#ifndef IPV6
int hints_ai_family = AF_INET;
#else
int hints_ai_family = AF_UNSPEC;
#endif
#ifndef IPV6 #ifndef IPV6
int *allsocket[2] = { &socket4, NULL }; int *allsocket[2] = { &socket4, NULL };
int hints_ai_family = AF_INET;
#else #else
int socket6 = 0; int socket6 = 0;
int *allsocket[3] = { &socket4, &socket6, NULL }; int *allsocket[3] = { &socket4, &socket6, NULL };
int hints_ai_family = AF_UNSPEC;
#endif #endif
unsigned int debugging = 0; unsigned int debugging = 0;
/* times get *100 because all times are calculated in 10 usec units, not ms */ /* times get *100 because all times are calculated in 10 usec units, not ms */
@ -379,17 +376,25 @@ int main( int argc, char **argv )
/* get command line options */ /* get command line options */
while( ( c = getopt( argc, argv, "ADMNRadeghlmnoqsuvzB:C:H:I:O:Q:S:T:b:c:f:i:p:r:t:" ) ) != EOF ) while( ( c = getopt( argc, argv, "46ADMNRadeghlmnoqsuvzB:C:H:I:O:Q:S:T:b:c:f:i:p:r:t:" ) ) != EOF )
{ {
switch( c ) switch( c )
{ {
case '4':
hints_ai_family = AF_INET;
// FIXME: check that -4 and -6 not used together
break;
case '6':
hints_ai_family = AF_INET6;
// FIXME: check that -4 and -6 not used together
break;
case 'M': case 'M':
#ifdef IP_MTU_DISCOVER #ifdef IP_MTU_DISCOVER
{ {
int val = IP_PMTUDISC_DO; int val = IP_PMTUDISC_DO;
int *sp; int **sp;
for(sp=allsocket[0]; *sp; sp++) { for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val))) { if (setsockopt(**sp, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val))) {
perror("setsockopt IP_MTU_DISCOVER"); perror("setsockopt IP_MTU_DISCOVER");
} }
} }
@ -560,9 +565,9 @@ int main( int argc, char **argv )
case 'I': case 'I':
#ifdef SO_BINDTODEVICE #ifdef SO_BINDTODEVICE
{ {
int *sp; int **sp;
for(sp=allsocket[0]; *sp; sp++) { for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, SOL_SOCKET, SO_BINDTODEVICE, optarg, strlen(optarg))) { if (setsockopt(**sp, SOL_SOCKET, SO_BINDTODEVICE, optarg, strlen(optarg))) {
perror("binding to specific interface (SO_BINTODEVICE)"); perror("binding to specific interface (SO_BINTODEVICE)");
} }
} }
@ -579,9 +584,9 @@ int main( int argc, char **argv )
case 'O': case 'O':
if (sscanf(optarg,"%i",&tos)){ if (sscanf(optarg,"%i",&tos)){
int *sp; int **sp;
for(sp=allsocket[0]; *sp; sp++) { for(sp=&allsocket[0]; *sp; sp++) {
if ( setsockopt(*sp, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) { if ( setsockopt(**sp, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) {
perror("setting type of service octet IP_TOS"); perror("setting type of service octet IP_TOS");
} }
} }
@ -735,9 +740,9 @@ int main( int argc, char **argv )
/* set the TTL, if the -H option was set (otherwise ttl will be = 0) */ /* set the TTL, if the -H option was set (otherwise ttl will be = 0) */
if(ttl > 0) { if(ttl > 0) {
int *sp; int **sp;
for(sp=allsocket[0]; *sp; sp++) { for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) { if (setsockopt(**sp, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) {
perror("setting time to live"); perror("setting time to live");
} }
} }
@ -746,9 +751,9 @@ int main( int argc, char **argv )
#if HAVE_SO_TIMESTAMP #if HAVE_SO_TIMESTAMP
{ {
int opt = 1; int opt = 1;
int *sp; int **sp;
for(sp=allsocket[0]; *sp; sp++) { for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) { if (setsockopt(**sp, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
perror("setting SO_TIMESTAMP option"); perror("setting SO_TIMESTAMP option");
} }
} }

Loading…
Cancel
Save