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
./configure --enable-ipv4 --enable-ipv6 --prefix=/opt/fping
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/fping6
## setcap debugging:
#pwd
#df -k .
@ -26,6 +25,4 @@ make CFLAGS="-g -fprofile-arcs -ftest-coverage"
# use setuid, since setcap is not available
sudo chown root src/fping
sudo chown root src/fping6
sudo chmod u+s src/fping
sudo chmod u+s src/fping6

@ -1,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:"

@ -17,7 +17,7 @@ SKIP: {
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("");

@ -19,7 +19,7 @@ $cmd->stderr_is_eq("");
# fping -A
{
my $cmd = Test::Command->new(cmd => "fping -A localhost");
my $cmd = Test::Command->new(cmd => "fping -4 -A localhost");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("127.0.0.1 is alive\n");
$cmd->stderr_is_eq("");

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

@ -22,7 +22,7 @@ SKIP: {
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%.*});
@ -84,12 +84,12 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n");
$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("");

@ -7,13 +7,11 @@ if( $^O eq 'darwin' ) {
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
{
@ -22,11 +20,3 @@ $cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{: can't create socket \(must run as root\?\) : .*\n});
}
# fping6
{
my $cmd = Test::Command->new(cmd => "/tmp/fping6.copy ::1");
$cmd->exit_is_num(4);
$cmd->stdout_is_eq("");
$cmd->stderr_like(qr{: can't create raw socket \(must run as root\?\) : .*\n});
}

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

@ -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("");
}
# 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 -n -A 2001:4860:4860::8888");
$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("");

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

@ -235,18 +235,15 @@ HOST_ENTRY *ev_last;
char *prog;
int ident; /* our pid */
int socket4 = 0;
#ifndef IPV6
int hints_ai_family = AF_INET;
#else
int hints_ai_family = AF_UNSPEC;
#endif
#ifndef IPV6
int *allsocket[2] = { &socket4, NULL };
int hints_ai_family = AF_INET;
#else
int socket6 = 0;
int *allsocket[3] = { &socket4, &socket6, NULL };
int hints_ai_family = AF_UNSPEC;
#endif
unsigned int debugging = 0;
/* 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 */
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 )
{
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':
#ifdef IP_MTU_DISCOVER
{
int val = IP_PMTUDISC_DO;
int *sp;
for(sp=allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val))) {
int **sp;
for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(**sp, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val))) {
perror("setsockopt IP_MTU_DISCOVER");
}
}
@ -560,9 +565,9 @@ int main( int argc, char **argv )
case 'I':
#ifdef SO_BINDTODEVICE
{
int *sp;
for(sp=allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, SOL_SOCKET, SO_BINDTODEVICE, optarg, strlen(optarg))) {
int **sp;
for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(**sp, SOL_SOCKET, SO_BINDTODEVICE, optarg, strlen(optarg))) {
perror("binding to specific interface (SO_BINTODEVICE)");
}
}
@ -579,9 +584,9 @@ int main( int argc, char **argv )
case 'O':
if (sscanf(optarg,"%i",&tos)){
int *sp;
for(sp=allsocket[0]; *sp; sp++) {
if ( setsockopt(*sp, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) {
int **sp;
for(sp=&allsocket[0]; *sp; sp++) {
if ( setsockopt(**sp, IPPROTO_IP, IP_TOS, &tos, sizeof(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) */
if(ttl > 0) {
int *sp;
for(sp=allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) {
int **sp;
for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(**sp, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) {
perror("setting time to live");
}
}
@ -746,9 +751,9 @@ int main( int argc, char **argv )
#if HAVE_SO_TIMESTAMP
{
int opt = 1;
int *sp;
for(sp=allsocket[0]; *sp; sp++) {
if (setsockopt(*sp, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
int **sp;
for(sp=&allsocket[0]; *sp; sp++) {
if (setsockopt(**sp, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
perror("setting SO_TIMESTAMP option");
}
}

Loading…
Cancel
Save