Compare commits
130
Commits
3.7
...
3.10-amiga
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b071caa89 | ||
|
|
202c38e84b | ||
|
|
26d8fb5108 | ||
|
|
32cd7febe0 | ||
|
|
005624f44f | ||
|
|
8fc9fa37c7 | ||
|
|
3d74b33f4c | ||
|
|
9949c92c2b | ||
|
|
0706f68bdf | ||
|
|
d01d280f84 | ||
|
|
625793935e | ||
|
|
c8c6e8db5d | ||
|
|
e2896d390f | ||
|
|
f6c3cbdf64 | ||
|
|
558c123e35 | ||
|
|
333a16bdbf | ||
|
|
b72256a8fc | ||
|
|
3313c3619d | ||
|
|
97705a649c | ||
|
|
964941f7fa | ||
|
|
99e498d8db | ||
|
|
21d568457f | ||
|
|
f02cebfd3a | ||
|
|
e7b6b7ecb6 | ||
|
|
23dbb92e0b | ||
|
|
075be180fe | ||
|
|
396a32017d | ||
|
|
d91066ceeb | ||
|
|
860fbadf6a | ||
|
|
c996044f2a | ||
|
|
8854e99994 | ||
|
|
9c3133fead | ||
|
|
3cc482f2d3 | ||
|
|
8f66bac4ec | ||
|
|
a1e9d8240b | ||
|
|
0f36dddffd | ||
|
|
e042466b9a | ||
|
|
3aed2604bb | ||
|
|
609f4f17c4 | ||
|
|
4d6861c2c3 | ||
|
|
314b8debd9 | ||
|
|
fe12f0dbab | ||
|
|
a07e244a57 | ||
|
|
7b8899043d | ||
|
|
c4c3068bbb | ||
|
|
2b5d9ef795 | ||
|
|
e79444f09a | ||
|
|
b779e14db6 | ||
|
|
3aa530c2ff | ||
|
|
c9f276b3cd | ||
|
|
1d576326ba | ||
|
|
f35f4a8cc4 | ||
|
|
75101dd843 | ||
|
|
c1fe95f7b7 | ||
|
|
bdca2c4b07 | ||
|
|
ea026f3ba4 | ||
|
|
3ec68c8a3f | ||
|
|
9a5c6589b2 | ||
|
|
a7f351fb8e | ||
|
|
51cc41a2c1 | ||
|
|
d35f7072b5 | ||
|
|
ab006a5113 | ||
|
|
c524813889 | ||
|
|
86f0b1e380 | ||
|
|
d4e0a6c89b | ||
|
|
3cf9a8a3cd | ||
|
|
f65d335ecf | ||
|
|
c6f37022a4 | ||
|
|
c786c34334 | ||
|
|
cd21d0bb91 | ||
|
|
b359c0e7a3 | ||
|
|
9d71f4e809 | ||
|
|
af0446b046 | ||
|
|
930af0fc54 | ||
|
|
00e3384d5c | ||
|
|
6fa8c4c175 | ||
|
|
8cda80898e | ||
|
|
56c431df13 | ||
|
|
def79d3590 | ||
|
|
0990bf1c61 | ||
|
|
a6721ac2d2 | ||
|
|
49f24acda6 | ||
|
|
37158fe9fe | ||
|
|
86ecd82263 | ||
|
|
382ab64e5c | ||
|
|
3f37397c58 | ||
|
|
8bd200905d | ||
|
|
91130ebd28 | ||
|
|
358ac75c21 | ||
|
|
c5e7e911b0 | ||
|
|
e2705a01c1 | ||
|
|
d9506b335f | ||
|
|
782524e489 | ||
|
|
956b851d47 | ||
|
|
e27fd71935 | ||
|
|
4989d94eb7 | ||
|
|
ff44de71b1 | ||
|
|
e7ace04516 | ||
|
|
18aa33e13a | ||
|
|
71bf72527b | ||
|
|
e07a6e9dfc | ||
|
|
71616ec77e | ||
|
|
42574667d6 | ||
|
|
2604b40743 | ||
|
|
e39e24e933 | ||
|
|
bd768a44f8 | ||
|
|
e9daacdf81 | ||
|
|
2f9cd95bbd | ||
|
|
219dbd893d | ||
|
|
7dd45384e4 | ||
|
|
f9c68a6dc7 | ||
|
|
540057dfd9 | ||
|
|
fdddda1c22 | ||
|
|
a2ac03c210 | ||
|
|
3eccad8ee1 | ||
|
|
c6d311a7d4 | ||
|
|
5851422798 | ||
|
|
57595638ec | ||
|
|
801051eeec | ||
|
|
806ad042b8 | ||
|
|
5dc8afb265 | ||
|
|
f27a89d40d | ||
|
|
b973451021 | ||
|
|
63c73e0697 | ||
|
|
5dd8c5de50 | ||
|
|
0decb829d8 | ||
|
|
3e8eb6c613 | ||
|
|
85abf34b0a | ||
|
|
bda0744d2c | ||
|
|
d6808efd81 |
@@ -1,11 +1,15 @@
|
||||
.*.swp
|
||||
*.tar.gz
|
||||
*~
|
||||
src/*.gcno
|
||||
src/*.gcda
|
||||
src/*.gcov
|
||||
.deps
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
compile
|
||||
config.guess
|
||||
config.h
|
||||
config.h.in
|
||||
@@ -22,3 +26,5 @@ src/fping6
|
||||
stamp-h1
|
||||
doc/fping.8
|
||||
doc/fping6.8
|
||||
ci/build
|
||||
*.kdev4
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
# travis-ci.org configuration
|
||||
#
|
||||
language: c
|
||||
env:
|
||||
global:
|
||||
- secure: "CoI8hwHH1yfQoQxIfWGRS0WfTyScox+5aJn0fDDgz2uKrrIxmBvIw/WKX8wcSiV6fLmLuwgNkKqSM3hdO4qaG+JxfWcuEiZZHm+kxSGMkWbGb/fvAI+gHg8ldKyYttcIX71O5rlZiC2QpNKQi2v18S6pI5p8eqnx7DYx4YrmguQ="
|
||||
compiler:
|
||||
- gcc
|
||||
before_install:
|
||||
- sudo apt-get install libcap2-bin
|
||||
- sudo apt-get install traceroute
|
||||
- traceroute google.com
|
||||
install:
|
||||
- ci/build-1-autotools.sh
|
||||
- curl -L http://cpanmin.us | perl - --sudo App::cpanminus
|
||||
- cpanm --sudo Test::Command
|
||||
script:
|
||||
- ci/build-2-install.sh
|
||||
- env PATH=`pwd`/src:$PATH prove ci/test-*.pl
|
||||
- ci/test-tarball.sh
|
||||
after_success:
|
||||
- ci/coveralls.sh
|
||||
- ci/deploy-bintray.sh
|
||||
@@ -1,5 +1,9 @@
|
||||
|
||||
/*
|
||||
* 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,
|
||||
@@ -11,5 +15,3 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,3 +1,29 @@
|
||||
UNRELEASED
|
||||
* Fix double entries with fping -u and unreachable hosts
|
||||
|
||||
2014-05-03 David Schweikert <david@schweikert.ch>
|
||||
* 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)
|
||||
* 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 <david@schweikert.ch>
|
||||
* Version 3.9
|
||||
* Fix random output on socket error (reported by Aleksandrs Saveljevs, #56)
|
||||
* Support ppc64le architecture by including alpha libtool version
|
||||
(reported by Amit Kumar Gupta and Aravinda B Thunug)
|
||||
* Fix compilation problem on FreeBSD (#57)
|
||||
* Initial test suite and continous intergration (with travis-ci.org / coveralls.io)
|
||||
* Don't output usage information on error
|
||||
|
||||
2013-11-08 David Schweikert <david@schweikert.ch>
|
||||
* Version 3.8
|
||||
* Fix segmentation fault introduced in version 3.7 with loop mode (reported
|
||||
by Vlad Glagolev, #55)
|
||||
|
||||
2013-11-04 David Schweikert <david@schweikert.ch>
|
||||
* Version 3.7
|
||||
* Allow running as non-root on Mac OS X by using non-privileged ICMP (#7)
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
fping 3 README
|
||||
--------------
|
||||
fping is a program to send ICMP echo probes to network hosts, similar to ping,
|
||||
but much better performing when pinging multiple hosts. fping has a long long
|
||||
story: Roland Schemers did publish a first version of it in 1992 and it has
|
||||
established itself since then as a standard tool.
|
||||
|
||||
Current maintainer:
|
||||
David Schweikert <david@schweikert.ch>
|
||||
|
||||
Website:
|
||||
http://fping.org/
|
||||
|
||||
Mailing-list:
|
||||
https://groups.google.com/group/fping-users
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
If you want to install fping from source, proceed as follows:
|
||||
|
||||
1. Run ./configure with the correct arguments
|
||||
(see: ./configure --help)
|
||||
|
||||
2. Run make; make install
|
||||
|
||||
3. Make fping either setuid, or, if under Linux:
|
||||
|
||||
sudo setcap cap_net_raw+ep fping
|
||||
|
||||
4. Have a look at the fping(8) manual for usage help
|
||||
(fping -h will also give a minimal help output)
|
||||
|
||||
|
||||
IPv6 support
|
||||
------------
|
||||
You can can compile fping with support for IPv6 addresses. A separate binary
|
||||
is used for that, called fping6. To build it, use ./configure --enable-ipv6
|
||||
(possibly combined with --enable-ipv4 to also build fping for IPv4). E.g.:
|
||||
|
||||
# ./configure --prefix=/usr/local --enable-ipv4 --enable-ipv6
|
||||
# make
|
||||
# make install
|
||||
# sudo setcap cap_net_raw+ep /usr/local/bin/fping*
|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
Original author: Roland Schemers (schemers@stanford.edu)
|
||||
Previous maintainer: RL "Bob" Morgan (morgan@stanford.edu)
|
||||
Initial IPv6 Support: Jeroen Massar (jeroen@unfix.org / jeroen@ipng.nl)
|
||||
Other contributors: see ChangeLog
|
||||
@@ -19,3 +19,6 @@ rm -f stamp-h1
|
||||
rm -f doc/Makefile.in
|
||||
rm -f src/Makefile.in
|
||||
rm -f doc/fping.8
|
||||
rm -f src/*.gcda
|
||||
rm -f src/*.gcno
|
||||
rm -f src/*.gcov
|
||||
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
AUTOCONF=http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
|
||||
AUTOMAKE=http://ftp.gnu.org/gnu/automake/automake-1.14.1.tar.gz
|
||||
LIBTOOL=http://alpha.gnu.org/gnu/libtool/libtool-2.4.2.418.tar.gz
|
||||
PREFIX=$(pwd)/ci/build
|
||||
PATH=$(pwd)/ci/build/bin:$PATH
|
||||
|
||||
if [ ! -d ci ]; then
|
||||
echo "you must run this in the root fping directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# remove standard versions
|
||||
sudo apt-get remove -qq autoconf automake autotools-dev libtool
|
||||
|
||||
# prepare build environment
|
||||
cd ci
|
||||
rm -rf build
|
||||
mkdir -p build/src
|
||||
cd build/src
|
||||
|
||||
# autoconf
|
||||
(
|
||||
AUTOCONF_FILE=$(basename $AUTOCONF)
|
||||
AUTOCONF_DIR=$(echo $AUTOCONF_FILE | sed -e 's/\.tar.*//')
|
||||
wget $AUTOCONF
|
||||
tar xf $AUTOCONF_FILE
|
||||
cd $AUTOCONF_DIR
|
||||
./configure --prefix=$PREFIX
|
||||
make install
|
||||
)
|
||||
|
||||
# automake
|
||||
(
|
||||
AUTOMAKE_FILE=$(basename $AUTOMAKE)
|
||||
AUTOMAKE_DIR=$(echo $AUTOMAKE_FILE | sed -e 's/\.tar.*//')
|
||||
wget $AUTOMAKE
|
||||
tar xf $AUTOMAKE_FILE
|
||||
cd $AUTOMAKE_DIR
|
||||
./configure --prefix=$PREFIX
|
||||
make install
|
||||
)
|
||||
|
||||
# libtool
|
||||
(
|
||||
LIBTOOL_FILE=$(basename $LIBTOOL)
|
||||
LIBTOOL_DIR=$(echo $LIBTOOL_FILE | sed -e 's/\.tar.*//')
|
||||
wget $LIBTOOL
|
||||
tar xf $LIBTOOL_FILE
|
||||
cd $LIBTOOL_DIR
|
||||
./configure --prefix=$PREFIX
|
||||
make install
|
||||
)
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
PATH=$(pwd)/ci/build/bin:$PATH
|
||||
|
||||
if [ ! -d ci ]; then
|
||||
echo "you must run this in the root fping directory" >&2
|
||||
exit 1
|
||||
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
|
||||
#sudo setcap cap_net_raw+ep src/fping
|
||||
#sudo setcap cap_net_raw+ep src/fping6
|
||||
## setcap debugging:
|
||||
#pwd
|
||||
#df -k .
|
||||
#which setcap
|
||||
#uname -a
|
||||
#mount
|
||||
#
|
||||
#sudo apt-get install strace
|
||||
#sudo strace setcap cap_net_raw+ep src/fping
|
||||
|
||||
# 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
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
|
||||
sudo pip install cpp-coveralls --use-mirrors
|
||||
|
||||
cd src
|
||||
|
||||
ls -l
|
||||
|
||||
gcov *.o
|
||||
cd ..
|
||||
coveralls --exclude ci --no-gcov
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# upload to bintray.com/schweikert
|
||||
|
||||
set -e
|
||||
|
||||
# do this only for the gcc run
|
||||
if [ "$CC" != "gcc" ]; then
|
||||
echo "skipped upload because $CC != gcc"
|
||||
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
|
||||
else
|
||||
REPO=beta
|
||||
fi
|
||||
curl -T fping-$VERSION.tar.gz -uschweikert:$BINTRAY_API_KEY https://api.bintray.com/content/schweikert/$REPO/fping/$VERSION/fping-$VERSION.tar.gz
|
||||
echo
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 9;
|
||||
|
||||
# ping 127.0.0.1
|
||||
my $cmd1 = Test::Command->new(cmd => "fping 127.0.0.1");
|
||||
$cmd1->exit_is_num(0);
|
||||
$cmd1->stdout_is_eq("127.0.0.1 is alive\n");
|
||||
$cmd1->stderr_is_eq("");
|
||||
|
||||
# ping ::1
|
||||
my $cmd2 = Test::Command->new(cmd => "fping6 ::1");
|
||||
$cmd2->exit_is_num(0);
|
||||
$cmd2->stdout_is_eq("::1 is alive\n");
|
||||
$cmd2->stderr_is_eq("");
|
||||
|
||||
# ping 3 times 127.0.0.1
|
||||
my $cmd3 = Test::Command->new(cmd => "fping -p 100 -C3 127.0.0.1");
|
||||
$cmd3->exit_is_num(0);
|
||||
$cmd3->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\)
|
||||
127\.0\.0\.1 : \[2\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% loss\)
|
||||
});
|
||||
$cmd3->stderr_like(qr{127\.0\.0\.1 : 0\.\d+ 0\.\d+ 0\.\d+\n});
|
||||
Executable
+24
@@ -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+(-rc\d+)?
|
||||
fping: comments to david\@schweikert\.ch
|
||||
});
|
||||
$cmd->stderr_is_eq("");
|
||||
}
|
||||
Executable
+25
@@ -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_like(qr{\(null\): 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{\(null\): can't create raw socket \(must run as root\?\) : .*\n});
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 36;
|
||||
|
||||
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("");
|
||||
$cmd->stderr_like(qr{Usage:});
|
||||
}
|
||||
Executable
+19
@@ -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");
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 3;
|
||||
|
||||
my $re_num = qr{\d+(?:\.\d+)?};
|
||||
|
||||
# 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 = $re_num/$re_num/$re_num
|
||||
4\.2\.2\.5\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num
|
||||
www\.france-telecom\.fr\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num
|
||||
www\.google\.com\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num
|
||||
});
|
||||
}
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 9;
|
||||
|
||||
my $I_HELP = " -I if bind to a particular interface\n";
|
||||
$I_HELP = '' if $^O eq 'darwin';
|
||||
|
||||
# fping -h
|
||||
my $cmd1 = Test::Command->new(cmd => "fping -h");
|
||||
$cmd1->exit_is_num(0);
|
||||
$cmd1->stdout_is_eq(<<END);
|
||||
|
||||
Usage: fping [options] [targets...]
|
||||
-a show targets that are alive
|
||||
-A show targets by address
|
||||
-b n amount of ping data to send, in bytes (default 56)
|
||||
-B f set exponential backoff factor to f
|
||||
-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
|
||||
-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. 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_HELP} -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)
|
||||
-Q n same as -q, but show summary every n seconds
|
||||
-r n number of retries (default 3)
|
||||
-R random packet data (to foil link data compression)
|
||||
-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)
|
||||
-u show targets that are unreachable
|
||||
-v show version
|
||||
targets list of targets to check (if no -f specified)
|
||||
|
||||
END
|
||||
$cmd1->stderr_is_eq("");
|
||||
|
||||
# fping -v
|
||||
my $cmd2 = Test::Command->new(cmd => "fping -v");
|
||||
$cmd2->exit_is_num(0);
|
||||
$cmd2->stdout_like(qr{fping: Version \S+
|
||||
fping: comments to david\@schweikert\.ch\n});
|
||||
$cmd2->stderr_is_eq("");
|
||||
|
||||
# fping with unknown option
|
||||
my $cmd3 = Test::Command->new(cmd => "fping -Z");
|
||||
$cmd3->exit_is_num(1);
|
||||
$cmd3->stdout_is_eq("");
|
||||
if($^O eq 'darwin') {
|
||||
$cmd3->stderr_is_eq("fping: illegal option -- Z\nsee 'fping -h' for usage information\n");
|
||||
}
|
||||
else {
|
||||
$cmd3->stderr_is_eq("fping: invalid option -- 'Z'\nsee 'fping -h' for usage information\n");
|
||||
}
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 33;
|
||||
|
||||
# fping -i 9
|
||||
my $cmd1 = Test::Command->new(cmd => "fping -i 9 -T10 -g 127.0.0.1/29");
|
||||
$cmd1->exit_is_num(1);
|
||||
$cmd1->stdout_is_eq("");
|
||||
$cmd1->stderr_is_eq(<<END);
|
||||
fping: these options are too risky for mere mortals.
|
||||
fping: You need i >= 10, p >= 20, r < 20, and t >= 50
|
||||
END
|
||||
|
||||
# fping -p 15
|
||||
my $cmd2 = Test::Command->new(cmd => "fping -c3 -p 15 127.0.0.1");
|
||||
$cmd2->exit_is_num(1);
|
||||
$cmd2->stdout_is_eq("");
|
||||
$cmd2->stderr_is_eq(<<END);
|
||||
fping: these options are too risky for mere mortals.
|
||||
fping: You need i >= 10, p >= 20, r < 20, and t >= 50
|
||||
END
|
||||
|
||||
# fping -r 30
|
||||
my $cmd3 = Test::Command->new(cmd => "fping -r 30 127.0.0.1");
|
||||
$cmd3->exit_is_num(1);
|
||||
$cmd3->stdout_is_eq("");
|
||||
$cmd3->stderr_is_eq(<<END);
|
||||
fping: these options are too risky for mere mortals.
|
||||
fping: You need i >= 10, p >= 20, r < 20, and t >= 50
|
||||
END
|
||||
|
||||
# fping -t 40
|
||||
my $cmd4 = Test::Command->new(cmd => "fping -t 40 127.0.0.1");
|
||||
$cmd4->exit_is_num(1);
|
||||
$cmd4->stdout_is_eq("");
|
||||
$cmd4->stderr_is_eq(<<END);
|
||||
fping: these options are too risky for mere mortals.
|
||||
fping: You need i >= 10, p >= 20, r < 20, and t >= 50
|
||||
END
|
||||
|
||||
# fping -H 300
|
||||
my $cmd5 = Test::Command->new(cmd => "fping -H 300 127.0.0.1");
|
||||
$cmd5->exit_is_num(1);
|
||||
$cmd5->stdout_is_eq("");
|
||||
$cmd5->stderr_is_eq("ttl 300 out of range\n");
|
||||
|
||||
# fping -a -u
|
||||
my $cmd6 = Test::Command->new(cmd => "fping -a -u 127.0.0.1");
|
||||
$cmd6->exit_is_num(1);
|
||||
$cmd6->stdout_is_eq("");
|
||||
$cmd6->stderr_is_eq("fping: specify only one of a, u\n");
|
||||
|
||||
# fping -c -l
|
||||
my $cmd7 = Test::Command->new(cmd => "fping -c3 -l 127.0.0.1");
|
||||
$cmd7->exit_is_num(1);
|
||||
$cmd7->stdout_is_eq("");
|
||||
$cmd7->stderr_is_eq("fping: specify only one of c, l\n");
|
||||
|
||||
# fping -b 65509
|
||||
my $cmd8 = Test::Command->new(cmd => "fping -b 65509 127.0.0.1");
|
||||
$cmd8->exit_is_num(1);
|
||||
$cmd8->stdout_is_eq("");
|
||||
$cmd8->stderr_is_eq("fping: data size 65509 not valid, must be between 0 and 65508\n");
|
||||
|
||||
# fping -B 0.9
|
||||
my $cmd9 = Test::Command->new(cmd => "fping -B 0.9 127.0.0.1");
|
||||
$cmd9->exit_is_num(1);
|
||||
$cmd9->stdout_is_eq("");
|
||||
$cmd9->stderr_is_eq("fping: backoff factor 0.9 not valid, must be between 1.0 and 5.0\n");
|
||||
|
||||
# fping -B 0.9
|
||||
my $cmd10 = Test::Command->new(cmd => "fping -B 5.1 127.0.0.1");
|
||||
$cmd10->exit_is_num(1);
|
||||
$cmd10->stdout_is_eq("");
|
||||
$cmd10->stderr_is_eq("fping: backoff factor 5.1 not valid, must be between 1.0 and 5.0\n");
|
||||
|
||||
# fping -C 11000
|
||||
my $cmd11 = Test::Command->new(cmd => "fping -C 11000 127.0.0.1");
|
||||
$cmd11->exit_is_num(1);
|
||||
$cmd11->stdout_is_eq("");
|
||||
$cmd11->stderr_is_eq("fping: count 11000 not valid, must be less than 10000\n");
|
||||
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 20;
|
||||
use Test::More;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
|
||||
# -a show targets that are alive
|
||||
# -A show targets by address
|
||||
# -b n amount of ping data to send, in bytes (default 56)
|
||||
# -B f set exponential backoff factor to f
|
||||
|
||||
# fping -a
|
||||
{
|
||||
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 $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 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("");
|
||||
}
|
||||
|
||||
# fping -b
|
||||
{
|
||||
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 $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.8);
|
||||
}
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 12;
|
||||
|
||||
# -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("");
|
||||
}
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 18;
|
||||
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("");
|
||||
}
|
||||
|
||||
# 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);
|
||||
$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("");
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 7;
|
||||
|
||||
# -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 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("");
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
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)
|
||||
# -Q n same as -q, but show summary every n seconds
|
||||
|
||||
# fping -n
|
||||
{
|
||||
my $cmd = Test::Command->new(cmd => "fping -n 8.8.8.8");
|
||||
$cmd->exit_is_num(0);
|
||||
$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");
|
||||
$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+
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use Test::Command tests => 12;
|
||||
|
||||
# -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 (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");
|
||||
$cmd->exit_is_num(0);
|
||||
$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
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
# regression testing for github issue #56
|
||||
|
||||
use Test::Command tests => 3;
|
||||
|
||||
my $cmd1 = Test::Command->new(cmd => "fping -t100 -p100 -C3 255.255.255.255");
|
||||
$cmd1->exit_is_num(1);
|
||||
$cmd1->stdout_is_eq("");
|
||||
$cmd1->stderr_is_eq("\n255.255.255.255 : - - -\n");
|
||||
Executable
+10
@@ -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 => "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");
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# make sure that the .tar.gz file contains everything necessary
|
||||
# to build fping
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
make dist
|
||||
VERSION=$(ls fping-*.tar.gz | sed -e 's/^fping-//' | sed -e 's/\.tar\.gz$//')
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "tar.gz file not found." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# unarchive
|
||||
TMPDIR=$(mktemp -d --tmpdir=ci)
|
||||
cd $TMPDIR
|
||||
tar xf ../../fping-$VERSION.tar.gz
|
||||
DIRNAME=$(ls)
|
||||
|
||||
# build
|
||||
cd $DIRNAME
|
||||
./configure --enable-ipv4 --enable-ipv6 --prefix=/opt/fping
|
||||
make
|
||||
sudo make install
|
||||
+1
-1
@@ -3,7 +3,7 @@ dnl Process this file with autoconf to produce a configure script.
|
||||
dnl Minimum Autoconf version required.
|
||||
AC_PREREQ(2.59)
|
||||
|
||||
AC_INIT([fping],[3.7])
|
||||
AC_INIT([fping],[3.10])
|
||||
|
||||
dnl make ipv4 and ipv6 options
|
||||
AC_ARG_ENABLE([ipv4],
|
||||
|
||||
+24
-6
@@ -35,7 +35,8 @@ Show systems that are alive.
|
||||
|
||||
=item B<-A>
|
||||
|
||||
Display targets by address rather than DNS name.
|
||||
Display targets by address rather than DNS name. Combined with -d, the output
|
||||
will be both the ip and (if available) the hostname.
|
||||
|
||||
=item B<-b> I<n>
|
||||
|
||||
@@ -49,10 +50,11 @@ number.
|
||||
|
||||
=item B<-B> I<n>
|
||||
|
||||
In the default mode, B<fping> 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<fping> 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 (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<n>
|
||||
|
||||
@@ -149,6 +151,11 @@ Like B<-q>, but show summary results every n seconds.
|
||||
Retry limit (default 3). This is the number of times an attempt at pinging
|
||||
a target will be made, not including the first try.
|
||||
|
||||
=item B<-R>
|
||||
|
||||
Instead of using all-zeros as the packet data, generate random bytes.
|
||||
Use to defeat, e.g., link data compression.
|
||||
|
||||
=item B<-s>
|
||||
|
||||
Print cumulative statistics upon exit.
|
||||
@@ -165,7 +172,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<fping> 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<n>
|
||||
|
||||
@@ -190,6 +199,15 @@ Set the IP TTL field (time to live hops).
|
||||
|
||||
=back
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
Generate ~1000 pings per second to a host until canceled, printing statistics
|
||||
on the fly at one second intervals, and printing statistics at the end:
|
||||
|
||||
# fping -s -l -i 1 -p 1 -T 1 -Q 1 127.0.0.1
|
||||
|
||||
Note that ping intervals less than 10ms can only be used as root.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
|
||||
[1mNAME[0m
|
||||
fping - send ICMP ECHO_REQUEST packets to network hosts
|
||||
|
||||
[1mSYNOPSIS[0m
|
||||
[1mfping [22m[ [4moptions[24m ] [ [4msystems...[24m ] [1mfping6 [22m[ [4moptions[24m ] [ [4msystems...[24m ]
|
||||
|
||||
[1mDESCRIPTION[0m
|
||||
[1mfping [22mis a program like [1mping [22mwhich uses the Internet Control Message
|
||||
Protocol (ICMP) echo request to determine if a target host is
|
||||
responding. [1mfping [22mdiffers from [1mping [22min that you can specify any number
|
||||
of targets on the command line, or specify a file containing the lists
|
||||
of targets to ping. Instead of sending to one target until it times
|
||||
out or replies, [1mfping [22mwill send out a ping packet and move on to the
|
||||
next target in a round-robin fashion. In the default mode, if a target
|
||||
replies, it is noted and removed from the list of targets to check; if
|
||||
a target does not respond within a certain time limit and/or retry
|
||||
limit it is designated as unreachable. [1mfping [22malso supports sending a
|
||||
specified number of pings to a target, or looping indefinitely (as in
|
||||
[1mping [22m). Unlike [1mping[22m, [1mfping [22mis meant to be used in scripts, so its
|
||||
output is designed to be easy to parse.
|
||||
|
||||
The binary named [1mfping6 [22mis the same as [1mfping[22m, except that it uses IPv6
|
||||
addresses instead of IPv4.
|
||||
|
||||
[1mOPTIONS[0m
|
||||
[1m-a [22mShow systems that are alive.
|
||||
|
||||
[1m-A [22mDisplay targets by address rather than DNS name.
|
||||
|
||||
[1m-b [4m[22mn[24m Number of bytes of ping data to send. The minimum size (normally
|
||||
12) allows room for the data that [1mfping [22mneeds to do its work
|
||||
(sequence number, timestamp). The reported received data size
|
||||
includes the IP header (normally 20 bytes) and ICMP header (8
|
||||
bytes), so the minimum total size is 40 bytes. Default is 56, as
|
||||
in [1mping[22m. Maximum is the theoretical maximum IP datagram size
|
||||
(64K), though most systems limit this to a smaller, system-
|
||||
dependent number.
|
||||
|
||||
[1m-B [4m[22mn[24m Backoff factor. In the default mode, [1mfping [22msends 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 ([1m-t[22m) is multiplied on each successive request; it must be
|
||||
entered as a floating-point number (x.y). The default is 1.5.
|
||||
|
||||
[1m-c [4m[22mn[24m Number of request packets to send to each target. In this mode, a
|
||||
line is displayed for each received response (this can suppressed
|
||||
with [1m-q [22mor [1m-Q[22m). Also, statistics about responses for each target
|
||||
are displayed when all requests have been sent (or when
|
||||
interrupted).
|
||||
|
||||
[1m-C [4m[22mn[24m Similar to [1m-c[22m, but the per-target statistics are displayed in a
|
||||
format designed for automated response-time statistics gathering.
|
||||
For example:
|
||||
|
||||
% fping -C 5 -q somehost
|
||||
somehost : 91.7 37.0 29.2 - 36.8
|
||||
|
||||
shows the response time in milliseconds for each of the five
|
||||
requests, with the "-" indicating that no response was received to
|
||||
the fourth request.
|
||||
|
||||
[1m-d [22mUse DNS to lookup address of return ping packet. This allows you
|
||||
to give fping a list of IP addresses as input and print hostnames
|
||||
in the output.
|
||||
|
||||
[1m-D [22mAdd Unix timestamps in front of output lines generated with in
|
||||
looping or counting modes ([1m-l[22m, [1m-c[22m, or [1m-C[22m).
|
||||
|
||||
[1m-e [22mShow elapsed (round-trip) time of packets.
|
||||
|
||||
[1m-f [22mRead list of targets from a file. This option can only be used by
|
||||
the root user. Regular users should pipe in the file via stdin:
|
||||
|
||||
% fping < targets_file
|
||||
|
||||
[1m-g [4m[22maddr/mask[0m
|
||||
Generate a target list from a supplied IP netmask, or a starting
|
||||
and ending IP. Specify the netmask or start/end in the targets
|
||||
portion of the command line. If a network with netmask is given,
|
||||
the network and broadcast addresses will be excluded. ex. To ping
|
||||
the network 192.168.1.0/24, the specified command line could look
|
||||
like either:
|
||||
|
||||
fping -g 192.168.1.0/24
|
||||
|
||||
or
|
||||
|
||||
fping -g 192.168.1.1 192.168.1.254
|
||||
|
||||
[1m-h [22mPrint usage message.
|
||||
|
||||
[1m-i [4m[22mn[24m The minimum amount of time (in milliseconds) between sending a
|
||||
ping packet to any target (default is 25).
|
||||
|
||||
[1m-l [22mLoop sending packets to each target indefinitely. Can be
|
||||
interrupted with Ctrl-C; statistics about responses for each
|
||||
target are then displayed.
|
||||
|
||||
[1m-m [22mSend pings to each of a target host's multiple interfaces.
|
||||
|
||||
[1m-n [22mSame as -d.
|
||||
|
||||
[1m-p [22m<n>
|
||||
In looping or counting modes ([1m-l[22m, [1m-c[22m, or [1m-C[22m), this parameter sets
|
||||
the time in milliseconds that [1mfping [22mwaits between successive
|
||||
packets to an individual target. Default is 1000.
|
||||
|
||||
[1m-q [22mQuiet. Don't show per-probe results, but only the final summary.
|
||||
Also don't show ICMP error messages.
|
||||
|
||||
[1m-Q [4m[22mn[24m Like [1m-q[22m, but show summary results every n seconds.
|
||||
|
||||
[1m-r [4m[22mn[24m Retry limit (default 3). This is the number of times an attempt at
|
||||
pinging a target will be made, not including the first try.
|
||||
|
||||
[1m-s [22mPrint cumulative statistics upon exit.
|
||||
|
||||
[1m-S [4m[22maddr[0m
|
||||
Set source address.
|
||||
|
||||
[1m-I [4m[22mif[0m
|
||||
Set the interface (requires SO_BINDTODEVICE support)
|
||||
|
||||
[1m-t [4m[22mn[24m Initial target timeout in milliseconds (default 500). In the
|
||||
default mode, this is the amount of time that [1mfping [22mwaits for a
|
||||
response to its first request. Successive timeouts are multiplied
|
||||
by the backoff factor specified with [1m-B[22m. Note that this option
|
||||
has no effect looping or counting modes ([1m-l[22m, [1m-c[22m, or [1m-C[22m).
|
||||
|
||||
[1m-T [4m[22mn[24m Ignored (for compatibility with fping 2.4).
|
||||
|
||||
[1m-u [22mShow targets that are unreachable.
|
||||
|
||||
[1m-O [4m[22mn[24m Set the typ of service flag (TOS). [4mn[24m can be either decimal or
|
||||
hexadecimal (0xh) format.
|
||||
|
||||
[1m-v [22mPrint [1mfping [22mversion information.
|
||||
|
||||
[1m-H [4m[22mn[24m Set the IP TTL field (time to live hops).
|
||||
|
||||
[1mAUTHORS[0m
|
||||
· Roland J. Schemers III, Stanford University, concept and versions
|
||||
1.x
|
||||
|
||||
· RL "Bob" Morgan, Stanford University, versions 2.x
|
||||
|
||||
· David Papp, versions 2.3x and up
|
||||
|
||||
· David Schweikert, versions 3.0 and up
|
||||
|
||||
[1mfping website: <http://www.fping.org>[0m
|
||||
|
||||
[1mDIAGNOSTICS[0m
|
||||
Exit status is 0 if all the hosts are reachable, 1 if some hosts were
|
||||
unreachable, 2 if any IP addresses were not found, 3 for invalid
|
||||
command line arguments, and 4 for a system call failure.
|
||||
|
||||
[1mRESTRICTIONS[0m
|
||||
If certain options are used (i.e, a low value for [1m-i [22mand [1m-t[22m, and a high
|
||||
value for [1m-r[22m) it is possible to flood the network. This program must be
|
||||
installed as setuid root in order to open up a raw socket, or must be
|
||||
run by root. In order to stop mere mortals from hosing the network,
|
||||
normal users can't specify the following:
|
||||
|
||||
· [1m-i [4m[22mn[24m, where [4mn[24m < 10 msec
|
||||
|
||||
· [1m-r [4m[22mn[24m, where [4mn[24m > 20
|
||||
|
||||
· [1m-t [4m[22mn[24m, where n < 250 msec
|
||||
|
||||
|
||||
2014-05-04
|
||||
@@ -0,0 +1,26 @@
|
||||
fping 3 README
|
||||
--------------
|
||||
|
||||
fping is a program to send ICMP echo probes to network hosts, similar to ping,
|
||||
but much better performing when pinging multiple hosts. fping has a long long
|
||||
story: Roland Schemers did publish a first version of it in 1992 and it has
|
||||
established itself since then as a standard tool.
|
||||
|
||||
Current maintainer:
|
||||
David Schweikert <david@schweikert.ch>
|
||||
|
||||
Website:
|
||||
http://fping.org/
|
||||
|
||||
Mailing-list:
|
||||
https://groups.google.com/group/fping-users
|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
AmigaOS maintainer Carsten Larsen (carsten.larsen@mail.com)
|
||||
Original author: Roland Schemers (schemers@stanford.edu)
|
||||
Previous maintainer: RL "Bob" Morgan (morgan@stanford.edu)
|
||||
Initial IPv6 Support: Jeroen Massar (jeroen@unfix.org / jeroen@ipng.nl)
|
||||
Other contributors: see ChangeLog
|
||||
@@ -1,16 +0,0 @@
|
||||
prog =
|
||||
|
||||
if IPV4
|
||||
prog += fping
|
||||
endif
|
||||
if IPV6
|
||||
prog += fping6
|
||||
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
|
||||
@@ -0,0 +1,36 @@
|
||||
# Portable Makefile generated by configure
|
||||
|
||||
all: fping
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -O2 -DAROS -I. -Iinclude -Wall -Werror
|
||||
LDLIBS = -lm
|
||||
|
||||
config.h: inet_getaddrinfo.h
|
||||
touch config.h
|
||||
|
||||
fping.o: fping.c config.h fping.h options.h seqmap.h
|
||||
|
||||
fping_amiga.o: fping_amiga.c config.h
|
||||
|
||||
inet_getaddrinfo.o: inet_getaddrinfo.c fping.h inet_getaddrinfo.h
|
||||
|
||||
inet_ntop.o: inet_ntop.c
|
||||
|
||||
inet_pton.o: inet_pton.c
|
||||
|
||||
seqmap.o: seqmap.c options.h seqmap.h
|
||||
|
||||
socket.o: socket.c config.h fping.h
|
||||
|
||||
socket4.o: socket4.c config.h fping.h
|
||||
|
||||
|
||||
fping: fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o
|
||||
${CC} ${CFLAGS} -s -o fping fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o ${LDLIBS}
|
||||
|
||||
clean:
|
||||
rm -f fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o fping
|
||||
|
||||
depend:
|
||||
@echo Dependencies already done
|
||||
@@ -0,0 +1,36 @@
|
||||
# Portable Makefile generated by configure
|
||||
|
||||
all: fping
|
||||
|
||||
CC = m68k-amigaos-gcc
|
||||
CFLAGS = -O2 -noixemul -DAOS3 -I. -I.. -Iinclude -Wall -Werror
|
||||
LDLIBS = -liberty -lm
|
||||
|
||||
config.h: inet_getaddrinfo.h
|
||||
touch config.h
|
||||
|
||||
fping.o: fping.c config.h fping.h options.h seqmap.h
|
||||
|
||||
fping_amiga.o: fping_amiga.c config.h
|
||||
|
||||
inet_getaddrinfo.o: inet_getaddrinfo.c fping.h inet_getaddrinfo.h
|
||||
|
||||
inet_ntop.o: inet_ntop.c
|
||||
|
||||
inet_pton.o: inet_pton.c
|
||||
|
||||
seqmap.o: seqmap.c options.h seqmap.h
|
||||
|
||||
socket.o: socket.c config.h fping.h
|
||||
|
||||
socket4.o: socket4.c config.h fping.h
|
||||
|
||||
|
||||
fping: fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o
|
||||
${CC} ${CFLAGS} -s -o fping fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o ${LDLIBS}
|
||||
|
||||
clean:
|
||||
rm -f fping.o fping_amiga.o inet_getaddrinfo.o inet_ntop.o inet_pton.o seqmap.o socket.o socket4.o fping
|
||||
|
||||
depend:
|
||||
@echo Dependencies already done
|
||||
@@ -0,0 +1,81 @@
|
||||
/* config.h. Generated from config.h.in by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include "inet_getaddrinfo.h"
|
||||
|
||||
#ifdef AROS
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
# define HAVE_INTTYPES_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
#ifdef AROS
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
# define HAVE_STDINT_H 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||
#define HAVE_SYS_FILE_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
/* #undef HAVE_SYS_SELECT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "fping"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "fping"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "fping 3.10"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "fping"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "3.10"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "3.10"
|
||||
|
||||
/* some OSes do not define this ... lets take a wild guess */
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
# define INADDR_NONE 0xffffffffU
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2015 Carsten Larsen
|
||||
# Copyright (c) 2014 Poul-Henning Kamp
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
HDRS='
|
||||
config.h
|
||||
fping.h
|
||||
inet_getaddrinfo.h
|
||||
options.h
|
||||
seqmap.h
|
||||
'
|
||||
|
||||
SRCS='
|
||||
fping.c
|
||||
fping_amiga.c
|
||||
inet_getaddrinfo.c
|
||||
inet_ntop.c
|
||||
inet_pton.c
|
||||
seqmap.c
|
||||
socket.c
|
||||
socket4.c
|
||||
'
|
||||
|
||||
if make -v 2>&1 | grep GNU > /dev/null 2>&1 ; then
|
||||
echo "make is GNU make."
|
||||
VALID=true
|
||||
#else
|
||||
# echo "Wrong version of make."
|
||||
# VALID=false
|
||||
fi
|
||||
|
||||
if $VALID ; then
|
||||
(
|
||||
echo '# Portable Makefile generated by configure'
|
||||
echo ''
|
||||
echo 'all: fping'
|
||||
echo ''
|
||||
if [ -n "$1" ] && [ $1 = "AMIGA" ] ; then
|
||||
echo 'CC = m68k-amigaos-gcc'
|
||||
echo "CFLAGS = -O2 -noixemul -DAOS3 -I. -I.. -Iinclude -Wall -Werror"
|
||||
echo "LDLIBS = -liberty -lm"
|
||||
elif [ -n "$1" ] && [ $1 = "AROS" ] ; then
|
||||
echo 'CC = gcc'
|
||||
echo "CFLAGS = -O2 -DAROS -I. -Iinclude -Wall -Werror"
|
||||
echo "LDLIBS = -lm"
|
||||
else
|
||||
echo "CFLAGS = -O2 -Wall -Werror"
|
||||
echo "LDLIBS = -lm"
|
||||
fi
|
||||
echo ''
|
||||
|
||||
for f in ${HDRS}
|
||||
do
|
||||
b=`basename $f .h`
|
||||
i=`sed -n -e '/#include.*"/{
|
||||
s/"$//
|
||||
s/.*"//
|
||||
p
|
||||
}' $f | sort -u`
|
||||
if [ "x${i}" != "x" ] ; then
|
||||
echo "${b}.h: " ${i}
|
||||
echo " touch ${b}.h"
|
||||
echo
|
||||
fi
|
||||
done
|
||||
|
||||
l=""
|
||||
for f in ${SRCS}
|
||||
do
|
||||
b=`basename $f .c`
|
||||
i=`sed -n -e '/#include.*"/{
|
||||
s/"$//
|
||||
s/.*"//
|
||||
p
|
||||
}' $f | sort -u`
|
||||
echo "${b}.o: ${b}.c" ${i}
|
||||
echo
|
||||
l="${l} ${b}.o"
|
||||
done
|
||||
|
||||
echo
|
||||
echo "fping: ${l}"
|
||||
echo " \${CC} \${CFLAGS} -s -o fping ${l} \${LDLIBS}"
|
||||
echo
|
||||
echo "clean:"
|
||||
echo " rm -f ${l} fping"
|
||||
echo
|
||||
echo "depend:"
|
||||
echo " @echo Dependencies already done"
|
||||
) > Makefile
|
||||
|
||||
echo "Makefile generated"
|
||||
fi
|
||||
+326
-374
File diff suppressed because it is too large
Load Diff
+16
@@ -4,8 +4,14 @@
|
||||
#define __APPLE_USE_RFC_3542 1
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef AOS3
|
||||
#include <clib/exec_protos.h>
|
||||
#include <clib/amitcp_protos.h>
|
||||
#endif
|
||||
|
||||
#ifndef IPV6
|
||||
#define FPING_SOCKADDR struct sockaddr_in
|
||||
#define FPING_INADDR struct in_addr
|
||||
@@ -24,4 +30,14 @@ void errno_crash_and_burn( char *message );
|
||||
int open_ping_socket();
|
||||
void socket_set_src_addr(int s, FPING_INADDR src_addr);
|
||||
|
||||
/* inet_ntop.c */
|
||||
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||
|
||||
/* inet_pton.c */
|
||||
int inet_pton(int af, const char *src, void *dst);
|
||||
|
||||
/* fping_amiga.c */
|
||||
int open_libs();
|
||||
extern struct Library *SocketBase;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Written by Carsten Larsen.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <clib/exec_protos.h>
|
||||
|
||||
#define OPEN_ERROR "Cannot open %s.\n"
|
||||
#define OPEN_VER_ERROR "Cannot open %s (%d.0)\n"
|
||||
#define DOSLIB_NAME "dos.library"
|
||||
#define DOSLIB_REV 37L
|
||||
#define BSDLIB_NAME "bsdsocket.library"
|
||||
#define BSDLIB_REV 03L
|
||||
|
||||
#include "config.h"
|
||||
const char *vers = "\0$VER: " PACKAGE_NAME " " PACKAGE_VERSION " (15.08.2015)";
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef AOS3
|
||||
uid_t getuid () {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setuid (uid_t id) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int h_errno;
|
||||
#endif
|
||||
|
||||
struct Library *DOSBase;
|
||||
struct Library *SocketBase;
|
||||
|
||||
void amiga_open_error(char *name)
|
||||
{
|
||||
printf(OPEN_ERROR, name);
|
||||
}
|
||||
|
||||
void amiga_open_lib_error(char *name, int version)
|
||||
{
|
||||
printf(OPEN_VER_ERROR, name, version);
|
||||
}
|
||||
|
||||
void close_libs()
|
||||
{
|
||||
if (DOSBase != NULL) {
|
||||
CloseLibrary(DOSBase);
|
||||
DOSBase = NULL;
|
||||
}
|
||||
|
||||
if (SocketBase != NULL) {
|
||||
CloseLibrary(SocketBase);
|
||||
SocketBase = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int open_libs()
|
||||
{
|
||||
atexit(close_libs);
|
||||
|
||||
if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) {
|
||||
amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV);
|
||||
return 5;
|
||||
}
|
||||
|
||||
if(!(SocketBase = OpenLibrary((STRPTR)BSDLIB_NAME, BSDLIB_REV))) {
|
||||
amiga_open_lib_error(BSDLIB_NAME, BSDLIB_REV);
|
||||
return 5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Carsten Larsen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SOCKET_AMITCP_H
|
||||
#define _SOCKET_AMITCP_H
|
||||
//--------------------------------------------------------------------------//
|
||||
#define AMITCP_BASE_NAME SocketBase
|
||||
#include "inline/amitcp.h"
|
||||
//--------------------------------------------------------------------------//
|
||||
#define socket Socket
|
||||
#define bind Bind
|
||||
#define listen Listen
|
||||
#define accept Accept
|
||||
#define connect Connect
|
||||
#define send Send
|
||||
#define sendto SendTo
|
||||
#define sendmsg SendMsg
|
||||
#define recv Recv
|
||||
#define recvfrom RecvFrom
|
||||
#define recvmsg RecvMsg
|
||||
#define select Select
|
||||
#define shutdown ShutDown
|
||||
#define setsockopt SetSockOpt
|
||||
#define getsockopt GetSockOpt
|
||||
#define getsockname GetSockName
|
||||
#define getpeername GetPeerName
|
||||
#define inet_addr Inet_Addr
|
||||
#define inet_network Inet_Network
|
||||
#define inet_ntoa Inet_NtoA
|
||||
#define gethostbyname GetHostByName
|
||||
#define gethostbyaddr GetHostByAddr
|
||||
#define getnetbyname GetNetByName
|
||||
#define getnetbyaddr GetNetByAddr
|
||||
#define getservbyname GetServByName
|
||||
#define getservbyport GetServByPort
|
||||
#define getprotobyname GetProtoByName
|
||||
#define getprotobynumber GetProtoByNumber
|
||||
#define getdtablesize GetDTableSize
|
||||
#define gethostname GetHostName
|
||||
#define gethostid GetHostId
|
||||
#define vsyslog SyslogA
|
||||
#define syslog Syslog
|
||||
//--------------------------------------------------------------------------//
|
||||
#define Accept TCP_Accept
|
||||
#define Bind TCP_Bind
|
||||
#define CloseSocket TCP_CloseSocket
|
||||
#define Connect TCP_Connect
|
||||
#define Dup2Socket TCP_Dup2Socket
|
||||
#define Errno TCP_Errno
|
||||
#define GetDTableSize TCP_GetDTableSize
|
||||
#define GetHostByAddr TCP_GetHostByAddr
|
||||
#define GetHostByName TCP_GetHostByName
|
||||
#define GetHostId TCP_GetHostId
|
||||
#define GetHostName TCP_GetHostName
|
||||
#define GetNetByAddr TCP_GetNetByAddr
|
||||
#define GetNetByName TCP_GetNetByName
|
||||
#define GetPeerName TCP_GetPeerName
|
||||
#define GetProtoByName TCP_GetProtoByName
|
||||
#define GetProtoByNumber TCP_GetProtoByNumber
|
||||
#define GetServByName TCP_GetServByName
|
||||
#define GetServByPort TCP_GetServByPort
|
||||
#define GetSockName TCP_GetSockName
|
||||
#define GetSockOpt TCP_GetSockOpt
|
||||
#define GetSocketEvents TCP_GetSocketEvents
|
||||
#define Inet_Addr TCP_Inet_Addr
|
||||
#define Inet_LnaOf TCP_Inet_LnaOf
|
||||
#define Inet_MakeAddr TCP_Inet_MakeAddr
|
||||
#define Inet_NetOf TCP_Inet_NetOf
|
||||
#define Inet_Network TCP_Inet_Network
|
||||
#define Inet_NtoA(x) TCP_Inet_NtoA((x).s_addr)
|
||||
#define IoctlSocket TCP_IoctlSocket
|
||||
#define Listen TCP_Listen
|
||||
#define ObtainSocket TCP_ObtainSocket
|
||||
#define Recv TCP_Recv
|
||||
#define RecvFrom TCP_RecvFrom
|
||||
#define RecvMsg TCP_RecvMsg
|
||||
#define ReleaseCopyOfSocket TCP_ReleaseCopyOfSocket
|
||||
#define ReleaseSocket TCP_ReleaseSocket
|
||||
#define Send TCP_Send
|
||||
#define SendMsg TCP_SendMsg
|
||||
#define SendTo TCP_SendTo
|
||||
#define SetErrnoPtr TCP_SetErrnoPtr
|
||||
#define SetSockOpt TCP_SetSockOpt
|
||||
#define SetSocketSignals TCP_SetSocketSignals
|
||||
#define ShutDown TCP_ShutDown
|
||||
#define Socket TCP_Socket
|
||||
#define SocketBaseTagList TCP_SocketBaseTagList
|
||||
#define SocketBaseTags TCP_SocketBaseTags
|
||||
#define SyslogA TCP_SyslogA
|
||||
#define WaitSelect TCP_WaitSelect
|
||||
#define Select(n,r,w,e,t) TCP_WaitSelect(n,r,w,e,t,0)
|
||||
//--------------------------------------------------------------------------//
|
||||
#endif
|
||||
@@ -0,0 +1,203 @@
|
||||
/* Automatically generated header! Do not edit! */
|
||||
|
||||
#ifndef _INLINE_AMITCP_H
|
||||
#define _INLINE_AMITCP_H
|
||||
|
||||
#ifndef __INLINE_MACROS_H
|
||||
#include <inline/macros.h>
|
||||
#endif /* !__INLINE_MACROS_H */
|
||||
|
||||
#ifndef AMITCP_BASE_NAME
|
||||
#define AMITCP_BASE_NAME lss->lx_BsdSocketBase
|
||||
#endif /* !AMITCP_BASE_NAME */
|
||||
|
||||
#define TCP_Accept(s, addr, addrlen) \
|
||||
LP3(0x30, LONG, TCP_Accept, LONG, s, d0, struct sockaddr *, addr, a0, int *, addrlen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Bind(s, name, namelen) \
|
||||
LP3(0x24, LONG, TCP_Bind, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_CloseSocket(d) \
|
||||
LP1(0x78, LONG, TCP_CloseSocket, LONG, d, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Connect(s, name, namelen) \
|
||||
LP3(0x36, LONG, TCP_Connect, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Dup2Socket(fd1, fd2) \
|
||||
LP2(0x108, LONG, TCP_Dup2Socket, LONG, fd1, d0, LONG, fd2, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Errno() \
|
||||
LP0(0xa2, LONG, TCP_Errno, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetDTableSize() \
|
||||
LP0(0x8a, LONG, TCP_GetDTableSize, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostByAddr(addr, len, type) \
|
||||
LP3(0xd8, struct hostent *, TCP_GetHostByAddr, const UBYTE *, addr, a0, LONG, len, d0, LONG, type, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostByName(name) \
|
||||
LP1(0xd2, struct hostent *, TCP_GetHostByName, const UBYTE *, name, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostId() \
|
||||
LP0(0x120, ULONG, TCP_GetHostId, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetHostName(hostname, size) \
|
||||
LP2(0x11a, LONG, TCP_GetHostName, STRPTR, hostname, a0, LONG, size, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetNetByAddr(net, type) \
|
||||
LP2(0xe4, struct netent *, TCP_GetNetByAddr, LONG, net, d0, LONG, type, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetNetByName(name) \
|
||||
LP1(0xde, struct netent *, TCP_GetNetByName, const UBYTE *, name, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetPeerName(s, hostname, namelen) \
|
||||
LP3(0x6c, LONG, TCP_GetPeerName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetProtoByName(name) \
|
||||
LP1(0xf6, struct protoent *, TCP_GetProtoByName, const UBYTE *, name, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetProtoByNumber(proto) \
|
||||
LP1(0xfc, struct protoent *, TCP_GetProtoByNumber, LONG, proto, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetServByName(name, proto) \
|
||||
LP2(0xea, struct servent *, TCP_GetServByName, const UBYTE *, name, a0, const UBYTE *, proto, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetServByPort(port, proto) \
|
||||
LP2(0xf0, struct servent *, TCP_GetServByPort, LONG, port, d0, const UBYTE *, proto, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetSockName(s, hostname, namelen) \
|
||||
LP3(0x66, LONG, TCP_GetSockName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetSockOpt(s, level, optname, optval, optlen) \
|
||||
LP5(0x60, LONG, TCP_GetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, void *, optval, a0, int *, optlen, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_GetSocketEvents(eventmaskp) \
|
||||
LP1(0x12c, LONG, TCP_GetSocketEvents, ULONG *, eventmaskp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_Addr(cp) \
|
||||
LP1(0xb4, ULONG, TCP_Inet_Addr, const UBYTE *, cp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_LnaOf(in) \
|
||||
LP1(0xba, ULONG, TCP_Inet_LnaOf, LONG, in, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_MakeAddr(net, host) \
|
||||
LP2(0xc6, ULONG, TCP_Inet_MakeAddr, ULONG, net, d0, ULONG, host, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_NetOf(in) \
|
||||
LP1(0xc0, ULONG, TCP_Inet_NetOf, LONG, in, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_Network(cp) \
|
||||
LP1(0xcc, ULONG, TCP_Inet_Network, const UBYTE *, cp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Inet_NtoA(in) \
|
||||
LP1(0xae, char *, TCP_Inet_NtoA, ULONG, in, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_IoctlSocket(d, request, argp) \
|
||||
LP3(0x72, LONG, TCP_IoctlSocket, LONG, d, d0, ULONG, request, d1, char *, argp, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Listen(s, backlog) \
|
||||
LP2(0x2a, LONG, TCP_Listen, LONG, s, d0, LONG, backlog, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ObtainSocket(id, domain, type, protocol) \
|
||||
LP4(0x90, LONG, TCP_ObtainSocket, LONG, id, d0, LONG, domain, d1, LONG, type, d2, LONG, protocol, d3, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Recv(s, buf, len, flags) \
|
||||
LP4(0x4e, LONG, TCP_Recv, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_RecvFrom(s, buf, len, flags, from, fromlen) \
|
||||
LP6(0x48, LONG, TCP_RecvFrom, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, struct sockaddr *, from, a1, int *, fromlen, a2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_RecvMsg(s, msg, flags) \
|
||||
LP3(0x114, LONG, TCP_RecvMsg, LONG, s, d0, struct msghdr *, msg, a0, LONG, flags, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ReleaseCopyOfSocket(fd, id) \
|
||||
LP2(0x9c, LONG, TCP_ReleaseCopyOfSocket, LONG, fd, d0, LONG, id, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ReleaseSocket(fd, id) \
|
||||
LP2(0x96, LONG, TCP_ReleaseSocket, LONG, fd, d0, LONG, id, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Send(s, msg, len, flags) \
|
||||
LP4(0x42, LONG, TCP_Send, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SendMsg(s, msg, flags) \
|
||||
LP3(0x10e, LONG, TCP_SendMsg, LONG, s, d0, const struct msghdr *, msg, a0, LONG, flags, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SendTo(s, msg, len, flags, to, tolen) \
|
||||
LP6(0x3c, LONG, TCP_SendTo, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, const struct sockaddr *, to, a1, LONG, tolen, d3, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SetErrnoPtr(errno_p, size) \
|
||||
LP2(0xa8, LONG, TCP_SetErrnoPtr, void *, errno_p, a0, LONG, size, d0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SetSockOpt(s, level, optname, optval, optlen) \
|
||||
LP5(0x5a, LONG, TCP_SetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, const void *, optval, a0, LONG, optlen, d3, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SetSocketSignals(SIGINTR, SIGIO, SIGURG) \
|
||||
LP3NR(0x84, TCP_SetSocketSignals, ULONG, SIGINTR, d0, ULONG, SIGIO, d1, ULONG, SIGURG, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_ShutDown(s, how) \
|
||||
LP2(0x54, LONG, TCP_ShutDown, LONG, s, d0, LONG, how, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_Socket(domain, type, protocol) \
|
||||
LP3(0x1e, LONG, TCP_Socket, LONG, domain, d0, LONG, type, d1, LONG, protocol, d2, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_SocketBaseTagList(taglist) \
|
||||
LP1(0x126, LONG, TCP_SocketBaseTagList, struct TagItem *, taglist, a0, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#ifndef NO_INLINE_STDARG
|
||||
#define TCP_SocketBaseTags(tags...) \
|
||||
({ULONG _tags[] = { tags }; TCP_SocketBaseTagList((struct TagItem *)_tags);})
|
||||
#endif
|
||||
|
||||
#define TCP_SyslogA(level, format, ap) \
|
||||
LP3NR(0x102, TCP_SyslogA, ULONG, level, d0, const char *, format, a0, va_list, ap, a1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#define TCP_WaitSelect(nfds, readfds, writefds, execptfds, timeout, maskp) \
|
||||
LP6(0x7e, LONG, TCP_WaitSelect, LONG, nfds, d0, fd_set *, readfds, a0, fd_set *, writefds, a1, fd_set *, execptfds, a2, struct timeval *, timeout, a3, ULONG *, maskp, d1, \
|
||||
, AMITCP_BASE_NAME)
|
||||
|
||||
#endif /* !_INLINE_AMITCP_H */
|
||||
@@ -0,0 +1,523 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Carsten Larsen
|
||||
* Copyright (c) 2001, 02 Motoyuki Kasahara
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This program provides getaddrinfo() and getnameinfo() described in
|
||||
* RFC2133, 2553 and 3493. These functions are mainly used for IPv6
|
||||
* application to resolve hostname or address.
|
||||
*
|
||||
* This program is designed to be working on traditional IPv4 systems
|
||||
* which don't have those functions. Therefore, this implementation
|
||||
* supports IPv4 only.
|
||||
*
|
||||
* This program is useful for application which should support both IPv6
|
||||
* and traditional IPv4 systems. Use genuine getaddrinfo() and getnameinfo()
|
||||
* provided by system if the system supports IPv6. Otherwise, use this
|
||||
* implementation.
|
||||
*
|
||||
* This program also provides freeaddrinfo() and gai_strerror().
|
||||
*
|
||||
* Restriction:
|
||||
* getaddrinfo() and getnameinfo() of this program are NOT thread
|
||||
* safe, unless the cpp macro ENABLE_PTHREAD is defined.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "fping.h"
|
||||
#include "inet_getaddrinfo.h"
|
||||
|
||||
#ifdef ENABLE_PTHREAD
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
#include <libintl.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
#define _(string) gettext(string)
|
||||
#ifdef gettext_noop
|
||||
#define N_(string) gettext_noop(string)
|
||||
#else
|
||||
#define N_(string) (string)
|
||||
#endif
|
||||
#else
|
||||
#define gettext(string) (string)
|
||||
#define _(string) (string)
|
||||
#define N_(string) (string)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Error messages for gai_strerror().
|
||||
*/
|
||||
static char *eai_errlist[] = {
|
||||
N_("Success"),
|
||||
|
||||
/* EAI_ADDRFAMILY */
|
||||
N_("Address family for hostname not supported"),
|
||||
|
||||
/* EAI_AGAIN */
|
||||
N_("Temporary failure in name resolution"),
|
||||
|
||||
/* EAI_BADFLAGS */
|
||||
N_("Invalid value for ai_flags"),
|
||||
|
||||
/* EAI_FAIL */
|
||||
N_("Non-recoverable failure in name resolution"),
|
||||
|
||||
/* EAI_FAMILY */
|
||||
N_("ai_family not supported"),
|
||||
|
||||
/* EAI_MEMORY */
|
||||
N_("Memory allocation failure"),
|
||||
|
||||
/* EAI_NONAME */
|
||||
N_("hostname nor servname provided, or not known"),
|
||||
|
||||
/* EAI_OVERFLOW */
|
||||
N_("An argument buffer overflowed"),
|
||||
|
||||
/* EAI_SERVICE */
|
||||
N_("servname not supported for ai_socktype"),
|
||||
|
||||
/* EAI_SOCKTYPE */
|
||||
N_("ai_socktype not supported"),
|
||||
|
||||
/* EAI_SYSTEM */
|
||||
N_("System error returned in errno")
|
||||
};
|
||||
|
||||
/*
|
||||
* Default hints for getaddrinfo().
|
||||
*/
|
||||
static struct addrinfo default_hints = {
|
||||
0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
/*
|
||||
* Mutex.
|
||||
*/
|
||||
#ifdef ENABLE_PTHREAD
|
||||
static pthread_mutex_t gai_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declaration of static functions.
|
||||
*/
|
||||
#ifdef __STDC__
|
||||
static int is_integer(const char *);
|
||||
static int is_address(const char *);
|
||||
static int itoa_length(int);
|
||||
#else
|
||||
static int is_integer();
|
||||
static int is_address();
|
||||
static int itoa_length();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* gai_strerror().
|
||||
*/
|
||||
const char *
|
||||
gai_strerror(ecode)
|
||||
int ecode;
|
||||
{
|
||||
if (ecode < 0 || ecode > EAI_SYSTEM)
|
||||
return _("Unknown error");
|
||||
|
||||
return gettext(eai_errlist[ecode]);
|
||||
}
|
||||
|
||||
/*
|
||||
* freeaddrinfo().
|
||||
*/
|
||||
void
|
||||
freeaddrinfo(ai)
|
||||
struct addrinfo *ai;
|
||||
{
|
||||
struct addrinfo *next_ai;
|
||||
|
||||
while (ai != NULL) {
|
||||
if (ai->ai_canonname != NULL)
|
||||
free(ai->ai_canonname);
|
||||
if (ai->ai_addr != NULL)
|
||||
free(ai->ai_addr);
|
||||
next_ai = ai->ai_next;
|
||||
free(ai);
|
||||
ai = next_ai;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 1 if the string `s' represents an integer.
|
||||
*/
|
||||
static int
|
||||
is_integer(s)
|
||||
const char *s;
|
||||
{
|
||||
if (*s == '-' || *s == '+')
|
||||
s++;
|
||||
if (*s < '0' || '9' < *s)
|
||||
return 0;
|
||||
|
||||
s++;
|
||||
while ('0' <= *s && *s <= '9')
|
||||
s++;
|
||||
|
||||
return (*s == '\0');
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 1 if the string `s' represents an IPv4 address.
|
||||
* Unlike inet_addr(), it doesn't permit malformed nortation such
|
||||
* as "192.168".
|
||||
*/
|
||||
static int
|
||||
is_address(s)
|
||||
const char *s;
|
||||
{
|
||||
const static char delimiters[] = {'.', '.', '.', '\0'};
|
||||
int i, j;
|
||||
int octet;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (*s == '0' && *(s + 1) != delimiters[i])
|
||||
return 0;
|
||||
for (j = 0, octet = 0; '0' <= *s && *s <= '9' && j < 3; s++, j++)
|
||||
octet = octet * 10 + (*s - '0');
|
||||
if (j == 0 || octet > 255 || *s != delimiters[i])
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calcurate length of the string `s', where `s' is set by
|
||||
* sprintf(s, "%d", n).
|
||||
*/
|
||||
static int
|
||||
itoa_length(n)
|
||||
int n;
|
||||
{
|
||||
int result = 1;
|
||||
|
||||
if (n < 0) {
|
||||
n = -n;
|
||||
result++;
|
||||
}
|
||||
|
||||
while (n >= 10) {
|
||||
result++;
|
||||
n /= 10;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* getaddrinfo().
|
||||
*/
|
||||
int
|
||||
getaddrinfo(nodename, servname, hints, res)
|
||||
const char *nodename;
|
||||
const char *servname;
|
||||
const struct addrinfo *hints;
|
||||
struct addrinfo **res;
|
||||
{
|
||||
struct addrinfo *head_res = NULL;
|
||||
struct addrinfo *tail_res = NULL;
|
||||
struct addrinfo *new_res;
|
||||
struct sockaddr_in *sa_in;
|
||||
struct in_addr **addr_list;
|
||||
struct in_addr *addr_list_buf[2];
|
||||
struct in_addr addr_buf;
|
||||
struct in_addr **ap;
|
||||
struct servent *servent;
|
||||
struct hostent *hostent;
|
||||
const char *canonname = NULL;
|
||||
in_port_t port;
|
||||
int saved_h_errno;
|
||||
int result = 0;
|
||||
|
||||
#ifdef ENABLE_PTHREAD
|
||||
pthread_mutex_lock(&gai_mutex);
|
||||
#endif
|
||||
|
||||
saved_h_errno = h_errno;
|
||||
|
||||
if (nodename == NULL && servname == NULL) {
|
||||
result = EAI_NONAME;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (hints != NULL) {
|
||||
if (hints->ai_family != PF_INET && hints->ai_family != PF_UNSPEC) {
|
||||
result = EAI_FAMILY;
|
||||
goto end;
|
||||
}
|
||||
if (hints->ai_socktype != SOCK_DGRAM
|
||||
&& hints->ai_socktype != SOCK_STREAM
|
||||
&& hints->ai_socktype != 0) {
|
||||
result = EAI_SOCKTYPE;
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
hints = &default_hints;
|
||||
}
|
||||
|
||||
if (servname != NULL) {
|
||||
if (is_integer(servname))
|
||||
port = htons(atoi(servname));
|
||||
else {
|
||||
if (hints->ai_flags & AI_NUMERICSERV) {
|
||||
result = EAI_NONAME;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (hints->ai_socktype == SOCK_DGRAM)
|
||||
servent = getservbyname((char*)servname, (char*)"udp");
|
||||
else if (hints->ai_socktype == SOCK_STREAM)
|
||||
servent = getservbyname((char*)servname, (char*)"tcp");
|
||||
else if (hints->ai_socktype == 0)
|
||||
servent = getservbyname((char*)servname, (char*)"tcp");
|
||||
else {
|
||||
result = EAI_SOCKTYPE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (servent == NULL) {
|
||||
result = EAI_SERVICE;
|
||||
goto end;
|
||||
}
|
||||
port = servent->s_port;
|
||||
}
|
||||
} else {
|
||||
port = htons(0);
|
||||
}
|
||||
|
||||
if (nodename != NULL) {
|
||||
if (is_address(nodename)) {
|
||||
addr_buf.s_addr = inet_addr(nodename);
|
||||
addr_list_buf[0] = &addr_buf;
|
||||
addr_list_buf[1] = NULL;
|
||||
addr_list = addr_list_buf;
|
||||
|
||||
if (hints->ai_flags & AI_CANONNAME
|
||||
&& !(hints->ai_flags & AI_NUMERICHOST)) {
|
||||
hostent = gethostbyaddr((char *)&addr_buf,
|
||||
sizeof(struct in_addr), AF_INET);
|
||||
if (hostent != NULL)
|
||||
canonname = hostent->h_name;
|
||||
else
|
||||
canonname = nodename;
|
||||
}
|
||||
} else {
|
||||
if (hints->ai_flags & AI_NUMERICHOST) {
|
||||
result = EAI_NONAME;
|
||||
goto end;
|
||||
}
|
||||
|
||||
hostent = gethostbyname(nodename);
|
||||
if (hostent == NULL) {
|
||||
switch (h_errno) {
|
||||
case HOST_NOT_FOUND:
|
||||
case NO_DATA:
|
||||
result = EAI_NONAME;
|
||||
goto end;
|
||||
case TRY_AGAIN:
|
||||
result = EAI_AGAIN;
|
||||
goto end;
|
||||
default:
|
||||
result = EAI_FAIL;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
addr_list = (struct in_addr **)hostent->h_addr_list;
|
||||
|
||||
if (hints->ai_flags & AI_CANONNAME)
|
||||
canonname = hostent->h_name;
|
||||
}
|
||||
} else {
|
||||
if (hints->ai_flags & AI_PASSIVE)
|
||||
addr_buf.s_addr = htonl(INADDR_ANY);
|
||||
else
|
||||
addr_buf.s_addr = htonl(0x7F000001);
|
||||
addr_list_buf[0] = &addr_buf;
|
||||
addr_list_buf[1] = NULL;
|
||||
addr_list = addr_list_buf;
|
||||
}
|
||||
|
||||
for (ap = addr_list; *ap != NULL; ap++) {
|
||||
new_res = (struct addrinfo *)malloc(sizeof(struct addrinfo));
|
||||
if (new_res == NULL) {
|
||||
if (head_res != NULL)
|
||||
freeaddrinfo(head_res);
|
||||
result = EAI_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
||||
new_res->ai_family = PF_INET;
|
||||
new_res->ai_socktype = hints->ai_socktype;
|
||||
new_res->ai_protocol = hints->ai_protocol;
|
||||
new_res->ai_addr = NULL;
|
||||
new_res->ai_addrlen = sizeof(struct sockaddr_in);
|
||||
new_res->ai_canonname = NULL;
|
||||
new_res->ai_next = NULL;
|
||||
|
||||
new_res->ai_addr = (struct sockaddr *)
|
||||
malloc(sizeof(struct sockaddr_in));
|
||||
if (new_res->ai_addr == NULL) {
|
||||
free(new_res);
|
||||
if (head_res != NULL)
|
||||
freeaddrinfo(head_res);
|
||||
result = EAI_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
||||
sa_in = (struct sockaddr_in *)new_res->ai_addr;
|
||||
memset(sa_in, 0, sizeof(struct sockaddr_in));
|
||||
sa_in->sin_family = PF_INET;
|
||||
sa_in->sin_port = port;
|
||||
memcpy(&sa_in->sin_addr, *ap, sizeof(struct in_addr));
|
||||
|
||||
if (head_res == NULL)
|
||||
head_res = new_res;
|
||||
else
|
||||
tail_res->ai_next = new_res;
|
||||
tail_res = new_res;
|
||||
}
|
||||
|
||||
if (canonname != NULL && head_res != NULL) {
|
||||
head_res->ai_canonname = (char *)malloc(strlen(canonname) + 1);
|
||||
if (head_res->ai_canonname != NULL)
|
||||
strcpy(head_res->ai_canonname, canonname);
|
||||
}
|
||||
|
||||
*res = head_res;
|
||||
|
||||
end:
|
||||
h_errno = saved_h_errno;
|
||||
#ifdef ENABLE_PTHREAD
|
||||
pthread_mutex_unlock(&gai_mutex);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node, socklen_t nodelen, char *serv, socklen_t servlen, int flags) {
|
||||
|
||||
const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa;
|
||||
struct hostent *hostent;
|
||||
struct servent *servent;
|
||||
char *ntoa_address;
|
||||
int saved_h_errno;
|
||||
int result = 0;
|
||||
|
||||
#ifdef ENABLE_PTHREAD
|
||||
pthread_mutex_lock(&gai_mutex);
|
||||
#endif
|
||||
|
||||
saved_h_errno = h_errno;
|
||||
|
||||
if (sa_in->sin_family != PF_INET) {
|
||||
result = EAI_FAMILY;
|
||||
goto end;
|
||||
} else if (node == NULL && serv == NULL) {
|
||||
result = EAI_NONAME;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (serv != NULL && servlen > 0) {
|
||||
if (flags & NI_NUMERICSERV)
|
||||
servent = NULL;
|
||||
else if (flags & NI_DGRAM)
|
||||
servent = getservbyport(sa_in->sin_port, "udp");
|
||||
else
|
||||
servent = getservbyport(sa_in->sin_port, "tcp");
|
||||
|
||||
if (servent != NULL) {
|
||||
if (servlen <= strlen(servent->s_name)) {
|
||||
result = EAI_OVERFLOW;
|
||||
goto end;
|
||||
}
|
||||
strcpy(serv, servent->s_name);
|
||||
} else {
|
||||
if (servlen <= itoa_length(ntohs(sa_in->sin_port))) {
|
||||
result = EAI_OVERFLOW;
|
||||
goto end;
|
||||
}
|
||||
sprintf(serv, "%d", ntohs(sa_in->sin_port));
|
||||
}
|
||||
}
|
||||
|
||||
if (node != NULL && nodelen > 0) {
|
||||
if (flags & NI_NUMERICHOST)
|
||||
hostent = NULL;
|
||||
else {
|
||||
hostent = gethostbyaddr((char *)&sa_in->sin_addr,
|
||||
sizeof(struct in_addr), AF_INET);
|
||||
}
|
||||
if (hostent != NULL) {
|
||||
if (nodelen <= strlen(hostent->h_name)) {
|
||||
result = EAI_OVERFLOW;
|
||||
goto end;
|
||||
}
|
||||
strcpy(node, hostent->h_name);
|
||||
} else {
|
||||
if (flags & NI_NAMEREQD) {
|
||||
result = EAI_NONAME;
|
||||
goto end;
|
||||
}
|
||||
ntoa_address = inet_ntoa(sa_in->sin_addr);
|
||||
if (nodelen <= strlen(ntoa_address)) {
|
||||
result = EAI_OVERFLOW;
|
||||
goto end;
|
||||
}
|
||||
strcpy(node, ntoa_address);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
h_errno = saved_h_errno;
|
||||
#ifdef ENABLE_PTHREAD
|
||||
pthread_mutex_unlock(&gai_mutex);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Carsten Larsen
|
||||
* Copyright (c) 2001, 02 Motoyuki Kasahara
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef INET_GETADDRINFO_H
|
||||
#define INET_GETADDRINFO_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netdb.h>
|
||||
|
||||
/********************************************************************/
|
||||
/*
|
||||
* Undefine all the macros.
|
||||
* <netdb.h> might defines some of them.
|
||||
*/
|
||||
#ifdef EAI_ADDRFAMILY
|
||||
#undef EAI_ADDRFAMILY
|
||||
#endif
|
||||
#ifdef EAI_AGAIN
|
||||
#undef EAI_AGAIN
|
||||
#endif
|
||||
#ifdef EAI_BADFLAGS
|
||||
#undef EAI_BADFLAGS
|
||||
#endif
|
||||
#ifdef EAI_FAIL
|
||||
#undef EAI_FAIL
|
||||
#endif
|
||||
#ifdef EAI_FAMILY
|
||||
#undef EAI_FAMILY
|
||||
#endif
|
||||
#ifdef EAI_MEMORY
|
||||
#undef EAI_MEMORY
|
||||
#endif
|
||||
#ifdef EAI_NONAME
|
||||
#undef EAI_NONAME
|
||||
#endif
|
||||
#ifdef EAI_OVERFLOW
|
||||
#undef EAI_OVERFLOW
|
||||
#endif
|
||||
#ifdef EAI_SERVICE
|
||||
#undef EAI_SERVICE
|
||||
#endif
|
||||
#ifdef EAI_SOCKTYPE
|
||||
#undef EAI_SOCKTYPE
|
||||
#endif
|
||||
#ifdef EAI_SYSTEM
|
||||
#undef EAI_SYSTEM
|
||||
#endif
|
||||
|
||||
#ifdef AI_PASSIVE
|
||||
#undef AI_PASSIVE
|
||||
#endif
|
||||
#ifdef AI_CANONNAME
|
||||
#undef AI_CANONNAME
|
||||
#endif
|
||||
#ifdef AI_NUMERICHOST
|
||||
#undef AI_NUMERICHOST
|
||||
#endif
|
||||
#ifdef AI_NUMERICSERV
|
||||
#undef AI_NUMERICSERV
|
||||
#endif
|
||||
#ifdef AI_V4MAPPED
|
||||
#undef AI_V4MAPPED
|
||||
#endif
|
||||
#ifdef AI_ALL
|
||||
#undef AI_ALL
|
||||
#endif
|
||||
#ifdef AI_ADDRCONFIG
|
||||
#undef AI_ADDRCONFIG
|
||||
#endif
|
||||
#ifdef AI_DEFAULT
|
||||
#undef AI_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifdef NI_NOFQDN
|
||||
#undef NI_NOFQDN
|
||||
#endif
|
||||
#ifdef NI_NUMERICHOST
|
||||
#undef NI_NUMERICHOST
|
||||
#endif
|
||||
#ifdef NI_NAMEREQD
|
||||
#undef NI_NAMEREQD
|
||||
#endif
|
||||
#ifdef NI_NUMERICSERV
|
||||
#undef NI_NUMERICSERV
|
||||
#endif
|
||||
#ifdef NI_NUMERICSCOPE
|
||||
#undef NI_NUMERICSCOPE
|
||||
#endif
|
||||
|
||||
#ifdef NI_DGRAM
|
||||
#undef NI_DGRAM
|
||||
#endif
|
||||
#ifdef NI_MAXHOST
|
||||
#undef NI_MAXHOST
|
||||
#endif
|
||||
#ifdef NI_MAXSERV
|
||||
#undef NI_MAXSERV
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Fake struct and function names.
|
||||
* <netdb.h> might declares all or some of them.
|
||||
*/
|
||||
/*
|
||||
#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO)
|
||||
#define addrinfo my_addrinfo
|
||||
#define gai_strerror my_gai_strerror
|
||||
#define freeaddrinfo my_freeaddrinfo
|
||||
#define getaddrinfo my_getaddrinfo
|
||||
#define getnameinfo my_getnameinfo
|
||||
#endif
|
||||
*/
|
||||
|
||||
/********************************************************************/
|
||||
/*
|
||||
* Error codes.
|
||||
*/
|
||||
#define EAI_ADDRFAMILY 1
|
||||
#define EAI_AGAIN 2
|
||||
#define EAI_BADFLAGS 3
|
||||
#define EAI_FAIL 4
|
||||
#define EAI_FAMILY 5
|
||||
#define EAI_MEMORY 6
|
||||
#define EAI_NONAME 7
|
||||
#define EAI_OVERFLOW 8
|
||||
#define EAI_SERVICE 9
|
||||
#define EAI_SOCKTYPE 10
|
||||
#define EAI_SYSTEM 11
|
||||
|
||||
/*
|
||||
* Flags for getaddrinfo().
|
||||
*/
|
||||
#define AI_ADDRCONFIG 0x0001
|
||||
#define AI_ALL 0x0002
|
||||
#define AI_CANONNAME 0x0004
|
||||
#define AI_NUMERICHOST 0x0008
|
||||
#define AI_NUMERICSERV 0x0010
|
||||
#define AI_PASSIVE 0x0020
|
||||
#define AI_V4MAPPED 0x0040
|
||||
#define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
|
||||
|
||||
/*
|
||||
* Flags for getnameinfo().
|
||||
*/
|
||||
#define NI_DGRAM 0x0001
|
||||
#define NI_NAMEREQD 0x0002
|
||||
#define NI_NOFQDN 0x0004
|
||||
#define NI_NUMERICHOST 0x0008
|
||||
#define NI_NUMERICSCOPE 0x0010
|
||||
#define NI_NUMERICSERV 0x0020
|
||||
|
||||
/*
|
||||
* Maximum length of FQDN and servie name for getnameinfo().
|
||||
*/
|
||||
#define NI_MAXHOST 1025
|
||||
#define NI_MAXSERV 32
|
||||
|
||||
/*
|
||||
* Address families and Protocol families.
|
||||
*/
|
||||
#ifndef AF_UNSPEC
|
||||
#define AF_UNSPEC AF_INET
|
||||
#endif
|
||||
#ifndef PF_UNSPEC
|
||||
#define PF_UNSPEC PF_INET
|
||||
#endif
|
||||
|
||||
typedef u_int16_t in_port_t;
|
||||
typedef unsigned int sa_family_t;
|
||||
|
||||
const char* gai_strerror(int);
|
||||
void freeaddrinfo(struct addrinfo *);
|
||||
int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
|
||||
int getnameinfo(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int);
|
||||
|
||||
#endif
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 1999 - 2001 Kungliga Tekniska Högskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Heimdal: inet_ntop.c 21005 2007-06-08 01:54:35Z lha $
|
||||
* $NetBSD: inet_ntop.c,v 1.2 2008/03/22 08:37:21 mlelstv Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifndef INET_ADDRSTRLEN
|
||||
# define INET_ADDRSTRLEN 16
|
||||
#endif
|
||||
|
||||
static const char *
|
||||
inet_ntop_v4 (const void *src, char *dst, size_t size)
|
||||
{
|
||||
const char digits[] = "0123456789";
|
||||
int i;
|
||||
struct in_addr *addr = (struct in_addr *)src;
|
||||
u_long a = ntohl(addr->s_addr);
|
||||
const char *orig_dst = dst;
|
||||
|
||||
if (size < INET_ADDRSTRLEN) {
|
||||
errno = ENOSPC;
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < 4; ++i) {
|
||||
int n = (a >> (24 - i * 8)) & 0xFF;
|
||||
int non_zerop = 0;
|
||||
|
||||
if (non_zerop || n / 100 > 0) {
|
||||
*dst++ = digits[n / 100];
|
||||
n %= 100;
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || n / 10 > 0) {
|
||||
*dst++ = digits[n / 10];
|
||||
n %= 10;
|
||||
non_zerop = 1;
|
||||
}
|
||||
*dst++ = digits[n];
|
||||
if (i != 3)
|
||||
*dst++ = '.';
|
||||
}
|
||||
*dst++ = '\0';
|
||||
return orig_dst;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
static const char *
|
||||
inet_ntop_v6 (const void *src, char *dst, size_t size)
|
||||
{
|
||||
const char xdigits[] = "0123456789abcdef";
|
||||
int i;
|
||||
const struct in6_addr *addr = (struct in6_addr *)src;
|
||||
const u_char *ptr = addr->s6_addr;
|
||||
const char *orig_dst = dst;
|
||||
|
||||
if (size < INET6_ADDRSTRLEN) {
|
||||
errno = ENOSPC;
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < 8; ++i) {
|
||||
int non_zerop = 0;
|
||||
|
||||
if (non_zerop || (ptr[0] >> 4)) {
|
||||
*dst++ = xdigits[ptr[0] >> 4];
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || (ptr[0] & 0x0F)) {
|
||||
*dst++ = xdigits[ptr[0] & 0x0F];
|
||||
non_zerop = 1;
|
||||
}
|
||||
if (non_zerop || (ptr[1] >> 4)) {
|
||||
*dst++ = xdigits[ptr[1] >> 4];
|
||||
non_zerop = 1;
|
||||
}
|
||||
*dst++ = xdigits[ptr[1] & 0x0F];
|
||||
if (i != 7)
|
||||
*dst++ = ':';
|
||||
ptr += 2;
|
||||
}
|
||||
*dst++ = '\0';
|
||||
return orig_dst;
|
||||
}
|
||||
#endif /* HAVE_IPV6 */
|
||||
|
||||
const char *
|
||||
inet_ntop(int af, const void *src, char *dst, size_t size)
|
||||
{
|
||||
switch (af) {
|
||||
case AF_INET :
|
||||
return inet_ntop_v4 (src, dst, size);
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6 :
|
||||
return inet_ntop_v6 (src, dst, size);
|
||||
#endif
|
||||
default :
|
||||
errno = EAFNOSUPPORT;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
+303
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1996,1999 by Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
*
|
||||
* $NetBSD: inet_pton.c,v 1.9 2007/07/23 11:45:52 lukem Exp $
|
||||
* from NetBSD: inet_pton.c,v 1.3 2006/09/26 05:59:18 lukem Exp
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifndef uint32_t
|
||||
# define uint32_t u_int32_t
|
||||
#endif
|
||||
|
||||
#if !defined(NS_INADDRSZ)
|
||||
# define NS_INADDRSZ 4
|
||||
#endif
|
||||
#if !defined(NS_IN6ADDRSZ)
|
||||
# define NS_IN6ADDRSZ 16
|
||||
#endif
|
||||
#if !defined(NS_INT16SZ)
|
||||
# define NS_INT16SZ 2
|
||||
#endif
|
||||
|
||||
/*
|
||||
* WARNING: Don't even consider trying to compile this on a system where
|
||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||
*/
|
||||
|
||||
static int inet_pton4(const char *src, unsigned char *dst, int pton);
|
||||
#ifdef INET6
|
||||
static int inet_pton6(const char *src, unsigned char *dst);
|
||||
#endif /* INET6 */
|
||||
|
||||
/* int
|
||||
* inet_pton(af, src, dst)
|
||||
* convert from presentation format (which usually means ASCII printable)
|
||||
* to network format (which is usually some kind of binary format).
|
||||
* return:
|
||||
* 1 if the address was valid for the specified address family
|
||||
* 0 if the address wasn't valid (`dst' is untouched in this case)
|
||||
* -1 if some other error occurred (`dst' is untouched in this case, too)
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
int
|
||||
inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
return (inet_pton4(src, dst, 1));
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
return (inet_pton6(src, dst));
|
||||
#endif /* INET6 */
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return (-1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/* int
|
||||
* inet_pton4(src, dst, pton)
|
||||
* when last arg is 0: inet_aton(). with hexadecimal, octal and shorthand.
|
||||
* when last arg is 1: inet_pton(). decimal dotted-quad only.
|
||||
* return:
|
||||
* 1 if `src' is a valid input, else 0.
|
||||
* notice:
|
||||
* does not touch `dst' unless it's returning 1.
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static int
|
||||
inet_pton4(const char *src, unsigned char *dst, int pton)
|
||||
{
|
||||
uint32_t val;
|
||||
unsigned int digit, base;
|
||||
int n;
|
||||
unsigned char c;
|
||||
unsigned int parts[4];
|
||||
register unsigned int *pp = parts;
|
||||
|
||||
c = *src;
|
||||
for (;;) {
|
||||
/*
|
||||
* Collect number up to ``.''.
|
||||
* Values are specified as for C:
|
||||
* 0x=hex, 0=octal, isdigit=decimal.
|
||||
*/
|
||||
if (!isdigit(c))
|
||||
return (0);
|
||||
val = 0;
|
||||
base = 10;
|
||||
if (c == '0') {
|
||||
c = *++src;
|
||||
if (c == 'x' || c == 'X')
|
||||
base = 16, c = *++src;
|
||||
else if (isdigit(c) && c != '9')
|
||||
base = 8;
|
||||
}
|
||||
/* inet_pton() takes decimal only */
|
||||
if (pton && base != 10)
|
||||
return (0);
|
||||
for (;;) {
|
||||
if (isdigit(c)) {
|
||||
digit = c - '0';
|
||||
if (digit >= base)
|
||||
break;
|
||||
val = (val * base) + digit;
|
||||
c = *++src;
|
||||
} else if (base == 16 && isxdigit(c)) {
|
||||
digit = c + 10 - (islower(c) ? 'a' : 'A');
|
||||
if (digit >= 16)
|
||||
break;
|
||||
val = (val << 4) | digit;
|
||||
c = *++src;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (c == '.') {
|
||||
/*
|
||||
* Internet format:
|
||||
* a.b.c.d
|
||||
* a.b.c (with c treated as 16 bits)
|
||||
* a.b (with b treated as 24 bits)
|
||||
* a (with a treated as 32 bits)
|
||||
*/
|
||||
if (pp >= parts + 3)
|
||||
return (0);
|
||||
*pp++ = val;
|
||||
c = *++src;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check for trailing characters.
|
||||
*/
|
||||
if (c != '\0' && !isspace(c))
|
||||
return (0);
|
||||
/*
|
||||
* Concoct the address according to
|
||||
* the number of parts specified.
|
||||
*/
|
||||
n = pp - parts + 1;
|
||||
/* inet_pton() takes dotted-quad only. it does not take shorthand. */
|
||||
if (pton && n != 4)
|
||||
return (0);
|
||||
switch (n) {
|
||||
|
||||
case 0:
|
||||
return (0); /* initial nondigit */
|
||||
|
||||
case 1: /* a -- 32 bits */
|
||||
break;
|
||||
|
||||
case 2: /* a.b -- 8.24 bits */
|
||||
if (parts[0] > 0xff || val > 0xffffff)
|
||||
return (0);
|
||||
val |= parts[0] << 24;
|
||||
break;
|
||||
|
||||
case 3: /* a.b.c -- 8.8.16 bits */
|
||||
if ((parts[0] | parts[1]) > 0xff || val > 0xffff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16);
|
||||
break;
|
||||
|
||||
case 4: /* a.b.c.d -- 8.8.8.8 bits */
|
||||
if ((parts[0] | parts[1] | parts[2] | val) > 0xff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||
break;
|
||||
}
|
||||
if (dst) {
|
||||
val = htonl(val);
|
||||
memcpy(dst, &val, NS_INADDRSZ);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef INET6
|
||||
/* int
|
||||
* inet_pton6(src, dst)
|
||||
* convert presentation level address to network order binary form.
|
||||
* return:
|
||||
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
|
||||
* notice:
|
||||
* (1) does not touch `dst' unless it's returning 1.
|
||||
* (2) :: in a full address is silently ignored.
|
||||
* credit:
|
||||
* inspired by Mark Andrews.
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static int
|
||||
inet_pton6(const char *src, unsigned char *dst)
|
||||
{
|
||||
static const char xdigits_l[] = "0123456789abcdef",
|
||||
xdigits_u[] = "0123456789ABCDEF";
|
||||
unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||
const char *xdigits, *curtok;
|
||||
int ch, saw_xdigit;
|
||||
unsigned int val;
|
||||
|
||||
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
|
||||
endp = tp + NS_IN6ADDRSZ;
|
||||
colonp = NULL;
|
||||
/* Leading :: requires some special handling. */
|
||||
if (*src == ':')
|
||||
if (*++src != ':')
|
||||
return (0);
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
while ((ch = *src++) != '\0') {
|
||||
const char *pch;
|
||||
|
||||
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
||||
pch = strchr((xdigits = xdigits_u), ch);
|
||||
if (pch != NULL) {
|
||||
val <<= 4;
|
||||
val |= (pch - xdigits);
|
||||
if (val > 0xffff)
|
||||
return (0);
|
||||
saw_xdigit = 1;
|
||||
continue;
|
||||
}
|
||||
if (ch == ':') {
|
||||
curtok = src;
|
||||
if (!saw_xdigit) {
|
||||
if (colonp)
|
||||
return (0);
|
||||
colonp = tp;
|
||||
continue;
|
||||
} else if (*src == '\0')
|
||||
return (0);
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
||||
inet_pton4(curtok, tp, 1) > 0) {
|
||||
tp += NS_INADDRSZ;
|
||||
saw_xdigit = 0;
|
||||
break; /* '\0' was seen by inet_pton4(). */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
if (saw_xdigit) {
|
||||
if (tp + NS_INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
}
|
||||
if (colonp != NULL) {
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
const int n = tp - colonp;
|
||||
int i;
|
||||
|
||||
if (tp == endp)
|
||||
return (0);
|
||||
for (i = 1; i <= n; i++) {
|
||||
endp[- i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
if (tp != endp)
|
||||
return (0);
|
||||
memcpy(dst, tmp, NS_IN6ADDRSZ);
|
||||
return (1);
|
||||
}
|
||||
#endif /* INET6 */
|
||||
+10
-13
@@ -1,20 +1,20 @@
|
||||
|
||||
/*
|
||||
* Interval is the minimum amount of time between sending a ping packet to
|
||||
/*
|
||||
* Interval is the minimum amount of time between sending a ping packet to
|
||||
* any host.
|
||||
*
|
||||
* Perhost_interval is the minimum amount of time between sending a ping
|
||||
*
|
||||
* Perhost_interval is the minimum amount of time between sending a ping
|
||||
* packet to a particular responding host (when count is > 1)
|
||||
*
|
||||
*
|
||||
* Timeout is the initial amount of time between sending a ping packet to
|
||||
* a particular non-responding host.
|
||||
*
|
||||
*
|
||||
* Retry is the number of ping packets to send to a non-responding host
|
||||
* before giving up (in is-it-alive mode).
|
||||
*
|
||||
*
|
||||
* Backoff factor is how much longer to wait on successive retries.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* constants */
|
||||
@@ -32,7 +32,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DEFAULT_RETRY
|
||||
#ifndef DEFAULT_RETRY
|
||||
#define DEFAULT_RETRY 3 /* number of times to retry a host */
|
||||
#endif
|
||||
|
||||
@@ -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 */
|
||||
|
||||
+6
-8
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
@@ -22,8 +22,8 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
#include "seqmap.h"
|
||||
#include "options.h"
|
||||
#include "limits.h"
|
||||
#include <limits.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -53,15 +53,13 @@
|
||||
|
||||
static SEQMAP_VALUE *seqmap_map = NULL;
|
||||
static unsigned int seqmap_next_id = 0;
|
||||
static SEQMAP_VALUE *seqmap_free_list;
|
||||
//static SEQMAP_VALUE *seqmap_free_list;
|
||||
|
||||
#define SEQMAP_TIMEOUT_IN_S 10
|
||||
#define SEQMAP_UNASSIGNED_HOST_NR UINT_MAX
|
||||
|
||||
void seqmap_init()
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
seqmap_map = calloc(SEQMAP_MAXSEQ, sizeof(SEQMAP_VALUE));
|
||||
if(seqmap_map == NULL) {
|
||||
perror("malloc error (can't allocate seqmap_map)");
|
||||
@@ -83,7 +81,7 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct ti
|
||||
next_value = &seqmap_map[seqmap_next_id];
|
||||
if(next_value->ping_ts.tv_sec != 0 && (now->tv_sec - next_value->ping_ts.tv_sec) < SEQMAP_TIMEOUT_IN_S) {
|
||||
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%d, host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
|
||||
SEQMAP_TIMEOUT_IN_S, host_nr, ping_count, seqmap_next_id);
|
||||
SEQMAP_TIMEOUT_IN_S, host_nr, ping_count, seqmap_next_id);
|
||||
exit(4);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
@@ -22,8 +22,8 @@
|
||||
* 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
|
||||
* 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
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
@@ -22,8 +22,8 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -45,7 +45,7 @@ int open_ping_socket_ipv4()
|
||||
int s;
|
||||
|
||||
/* confirm that ICMP is available on this machine */
|
||||
if( ( proto = getprotobyname( "icmp" ) ) == NULL )
|
||||
if( ( proto = getprotobyname( "icmp" ) ) == NULL )
|
||||
crash_and_burn( "icmp: unknown protocol" );
|
||||
|
||||
/* create raw socket for ICMP calls (ping) */
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* fping: fast-ping, file-ping, favorite-ping, funky-ping
|
||||
*
|
||||
* Ping a list of target hosts in a round robin fashion.
|
||||
@@ -22,8 +22,8 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -48,7 +48,7 @@ int open_ping_socket_ipv6()
|
||||
int s;
|
||||
|
||||
/* confirm that ICMP is available on this machine */
|
||||
if( ( proto = getprotobyname( "ipv6-icmp" ) ) == NULL )
|
||||
if( ( proto = getprotobyname( "ipv6-icmp" ) ) == NULL )
|
||||
crash_and_burn( "icmp: unknown protocol" );
|
||||
|
||||
/* create raw socket for ICMP calls (ping) */
|
||||
|
||||
Reference in New Issue
Block a user