Codebase list fping / 0c7ca3f
New upstream version 3.16 Axel Beckert 7 years ago
24 changed file(s) with 2251 addition(s) and 2384 deletion(s). Raw diff Collapse all Expand all
0 Unreleased
1 * INCOMPATIBILITY WARNING:
2 fping and fping6 are now unified into one binary. This means that for
3 example doing 'fping www.google.com' is going to ping the IPv6 IP of
4 www.google.com on IPv6-enabled hosts. If you need exact compatibility with
5 old versions, you can:
6 - compile fping with --disable-ipv6 (or use a wrapper, and call 'fping -4')
7 - compile fping with --enable-ipv6 and rename it to fping6 (same as 'fping -6')
8
9 * (feature) Unified 'fping' and 'fping6' into one binary
10 * (feature) New option '-4' to force IPv4
11 * (feature) New option '-6' to force IPv6
0 2017-02-09 David Schweikert <david@schweikert.ch>
1 * Version 3.16
122 * (feature) Support kernel-timestamping of received packets (#46)
133 * (feature) Simplify restrictions: only -i >= 1 and -p >= 10 are enforced now
14 * (feature) --enable-ipv6 is now default (you can use --disable-ipv6 to disable IPv6 support)
154 * (bugfix) Fix option -m to return all IPs of a hostname
165 * (bugfix) Fix option -H (ttl) for IPv6
176 * (bugfix) Fix option -M (don't fragment) for IPv6
8080 subdir = .
8181 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
8282 $(top_srcdir)/configure $(am__configure_deps) \
83 $(srcdir)/config.h.in COPYING ChangeLog INSTALL README TODO \
84 compile config.guess config.sub depcomp install-sh missing
83 $(srcdir)/config.h.in COPYING ChangeLog INSTALL README compile \
84 config.guess config.sub install-sh missing
8585 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
8686 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
8787 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+0
-5
TODO less more
0 - implement -4
1 - implement -6
2 - test -4
3 - test -6
4 - fix -m
102102 # configured tree to be moved without reconfiguration.
103103
104104 AC_DEFUN([AM_AUX_DIR_EXPAND],
105 [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
106 # Expand $ac_aux_dir to an absolute path.
107 am_aux_dir=`cd "$ac_aux_dir" && pwd`
105 [dnl Rely on autoconf to set up CDPATH properly.
106 AC_PREREQ([2.50])dnl
107 # expand $ac_aux_dir to an absolute path
108 am_aux_dir=`cd $ac_aux_dir && pwd`
108109 ])
109110
110111 # AM_CONDITIONAL -*- Autoconf -*-
571572 END
572573 AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
573574 fi
574 fi
575 ])
575 fi])
576576
577577 dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not
578578 dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
00 #! /bin/sh
11 # Attempt to guess a canonical system name.
2 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 # 2011, 2012 Free Software Foundation, Inc.
5
6 timestamp='2012-02-10'
2 # Copyright 1992-2013 Free Software Foundation, Inc.
3
4 timestamp='2013-11-29'
75
86 # This file is free software; you can redistribute it and/or modify it
97 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
8 # the Free Software Foundation; either version 3 of the License, or
119 # (at your option) any later version.
1210 #
1311 # This program is distributed in the hope that it will be useful, but
2119 # As a special exception to the GNU General Public License, if you
2220 # distribute this file as part of a program that contains a
2321 # configuration script generated by Autoconf, you may include it under
24 # the same distribution terms that you use for the rest of that program.
25
26
27 # Originally written by Per Bothner. Please send patches (context
28 # diff format) to <config-patches@gnu.org> and include a ChangeLog
29 # entry.
22 # the same distribution terms that you use for the rest of that
23 # program. This Exception is an additional permission under section 7
24 # of the GNU General Public License, version 3 ("GPLv3").
3025 #
31 # This script attempts to guess a canonical system name similar to
32 # config.sub. If it succeeds, it prints the system name on stdout, and
33 # exits with 0. Otherwise, it exits with 1.
26 # Originally written by Per Bothner.
3427 #
3528 # You can get the latest version of this script from:
3629 # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
30 #
31 # Please send patches with a ChangeLog entry to config-patches@gnu.org.
32
3733
3834 me=`echo "$0" | sed -e 's,.*/,,'`
3935
5349 GNU config.guess ($timestamp)
5450
5551 Originally written by Per Bothner.
56 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
57 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
58 Free Software Foundation, Inc.
52 Copyright 1992-2013 Free Software Foundation, Inc.
5953
6054 This is free software; see the source for copying conditions. There is NO
6155 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
136130 UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
137131 UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
138132 UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
133
134 case "${UNAME_SYSTEM}" in
135 Linux|GNU|GNU/*)
136 # If the system lacks a compiler, then just pick glibc.
137 # We could probably try harder.
138 LIBC=gnu
139
140 eval $set_cc_for_build
141 cat <<-EOF > $dummy.c
142 #include <features.h>
143 #if defined(__UCLIBC__)
144 LIBC=uclibc
145 #elif defined(__dietlibc__)
146 LIBC=dietlibc
147 #else
148 LIBC=gnu
149 #endif
150 EOF
151 eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
152 ;;
153 esac
139154
140155 # Note: order is significant - the case branches are not exclusive.
141156
198213 # contains redundant information, the shorter form:
199214 # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
200215 echo "${machine}-${os}${release}"
216 exit ;;
217 *:Bitrig:*:*)
218 UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
219 echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
201220 exit ;;
202221 *:OpenBSD:*:*)
203222 UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
301320 arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
302321 echo arm-acorn-riscix${UNAME_RELEASE}
303322 exit ;;
304 arm:riscos:*:*|arm:RISCOS:*:*)
323 arm*:riscos:*:*|arm*:RISCOS:*:*)
305324 echo arm-unknown-riscos
306325 exit ;;
307326 SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
800819 i*:CYGWIN*:*)
801820 echo ${UNAME_MACHINE}-pc-cygwin
802821 exit ;;
822 *:MINGW64*:*)
823 echo ${UNAME_MACHINE}-pc-mingw64
824 exit ;;
803825 *:MINGW*:*)
804826 echo ${UNAME_MACHINE}-pc-mingw32
805827 exit ;;
851873 exit ;;
852874 *:GNU:*:*)
853875 # the GNU system
854 echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
876 echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
855877 exit ;;
856878 *:GNU/*:*:*)
857879 # other systems with GNU libc and userland
858 echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
880 echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
859881 exit ;;
860882 i*86:Minix:*:*)
861883 echo ${UNAME_MACHINE}-pc-minix
862884 exit ;;
863885 aarch64:Linux:*:*)
864 echo ${UNAME_MACHINE}-unknown-linux-gnu
886 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
865887 exit ;;
866888 aarch64_be:Linux:*:*)
867889 UNAME_MACHINE=aarch64_be
868 echo ${UNAME_MACHINE}-unknown-linux-gnu
890 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
869891 exit ;;
870892 alpha:Linux:*:*)
871893 case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
878900 EV68*) UNAME_MACHINE=alphaev68 ;;
879901 esac
880902 objdump --private-headers /bin/sh | grep -q ld.so.1
881 if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
882 echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
903 if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
904 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
905 exit ;;
906 arc:Linux:*:* | arceb:Linux:*:*)
907 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
883908 exit ;;
884909 arm*:Linux:*:*)
885910 eval $set_cc_for_build
886911 if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
887912 | grep -q __ARM_EABI__
888913 then
889 echo ${UNAME_MACHINE}-unknown-linux-gnu
914 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
890915 else
891916 if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
892917 | grep -q __ARM_PCS_VFP
893918 then
894 echo ${UNAME_MACHINE}-unknown-linux-gnueabi
919 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
895920 else
896 echo ${UNAME_MACHINE}-unknown-linux-gnueabihf
921 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
897922 fi
898923 fi
899924 exit ;;
900925 avr32*:Linux:*:*)
901 echo ${UNAME_MACHINE}-unknown-linux-gnu
926 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
902927 exit ;;
903928 cris:Linux:*:*)
904 echo ${UNAME_MACHINE}-axis-linux-gnu
929 echo ${UNAME_MACHINE}-axis-linux-${LIBC}
905930 exit ;;
906931 crisv32:Linux:*:*)
907 echo ${UNAME_MACHINE}-axis-linux-gnu
932 echo ${UNAME_MACHINE}-axis-linux-${LIBC}
908933 exit ;;
909934 frv:Linux:*:*)
910 echo ${UNAME_MACHINE}-unknown-linux-gnu
935 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
911936 exit ;;
912937 hexagon:Linux:*:*)
913 echo ${UNAME_MACHINE}-unknown-linux-gnu
938 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
914939 exit ;;
915940 i*86:Linux:*:*)
916 LIBC=gnu
917 eval $set_cc_for_build
918 sed 's/^ //' << EOF >$dummy.c
919 #ifdef __dietlibc__
920 LIBC=dietlibc
921 #endif
922 EOF
923 eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
924 echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
941 echo ${UNAME_MACHINE}-pc-linux-${LIBC}
925942 exit ;;
926943 ia64:Linux:*:*)
927 echo ${UNAME_MACHINE}-unknown-linux-gnu
944 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
928945 exit ;;
929946 m32r*:Linux:*:*)
930 echo ${UNAME_MACHINE}-unknown-linux-gnu
947 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
931948 exit ;;
932949 m68*:Linux:*:*)
933 echo ${UNAME_MACHINE}-unknown-linux-gnu
950 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
934951 exit ;;
935952 mips:Linux:*:* | mips64:Linux:*:*)
936953 eval $set_cc_for_build
949966 #endif
950967 EOF
951968 eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
952 test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
969 test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
953970 ;;
971 or1k:Linux:*:*)
972 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
973 exit ;;
954974 or32:Linux:*:*)
955 echo ${UNAME_MACHINE}-unknown-linux-gnu
975 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
956976 exit ;;
957977 padre:Linux:*:*)
958 echo sparc-unknown-linux-gnu
978 echo sparc-unknown-linux-${LIBC}
959979 exit ;;
960980 parisc64:Linux:*:* | hppa64:Linux:*:*)
961 echo hppa64-unknown-linux-gnu
981 echo hppa64-unknown-linux-${LIBC}
962982 exit ;;
963983 parisc:Linux:*:* | hppa:Linux:*:*)
964984 # Look for CPU level
965985 case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
966 PA7*) echo hppa1.1-unknown-linux-gnu ;;
967 PA8*) echo hppa2.0-unknown-linux-gnu ;;
968 *) echo hppa-unknown-linux-gnu ;;
986 PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
987 PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
988 *) echo hppa-unknown-linux-${LIBC} ;;
969989 esac
970990 exit ;;
971991 ppc64:Linux:*:*)
972 echo powerpc64-unknown-linux-gnu
992 echo powerpc64-unknown-linux-${LIBC}
973993 exit ;;
974994 ppc:Linux:*:*)
975 echo powerpc-unknown-linux-gnu
995 echo powerpc-unknown-linux-${LIBC}
996 exit ;;
997 ppc64le:Linux:*:*)
998 echo powerpc64le-unknown-linux-${LIBC}
999 exit ;;
1000 ppcle:Linux:*:*)
1001 echo powerpcle-unknown-linux-${LIBC}
9761002 exit ;;
9771003 s390:Linux:*:* | s390x:Linux:*:*)
978 echo ${UNAME_MACHINE}-ibm-linux
1004 echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
9791005 exit ;;
9801006 sh64*:Linux:*:*)
981 echo ${UNAME_MACHINE}-unknown-linux-gnu
1007 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
9821008 exit ;;
9831009 sh*:Linux:*:*)
984 echo ${UNAME_MACHINE}-unknown-linux-gnu
1010 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
9851011 exit ;;
9861012 sparc:Linux:*:* | sparc64:Linux:*:*)
987 echo ${UNAME_MACHINE}-unknown-linux-gnu
1013 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
9881014 exit ;;
9891015 tile*:Linux:*:*)
990 echo ${UNAME_MACHINE}-unknown-linux-gnu
1016 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
9911017 exit ;;
9921018 vax:Linux:*:*)
993 echo ${UNAME_MACHINE}-dec-linux-gnu
1019 echo ${UNAME_MACHINE}-dec-linux-${LIBC}
9941020 exit ;;
9951021 x86_64:Linux:*:*)
996 echo ${UNAME_MACHINE}-unknown-linux-gnu
1022 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
9971023 exit ;;
9981024 xtensa*:Linux:*:*)
999 echo ${UNAME_MACHINE}-unknown-linux-gnu
1025 echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
10001026 exit ;;
10011027 i*86:DYNIX/ptx:4*:*)
10021028 # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
12001226 BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
12011227 echo i586-pc-haiku
12021228 exit ;;
1229 x86_64:Haiku:*:*)
1230 echo x86_64-unknown-haiku
1231 exit ;;
12031232 SX-4:SUPER-UX:*:*)
12041233 echo sx4-nec-superux${UNAME_RELEASE}
12051234 exit ;;
12261255 exit ;;
12271256 *:Darwin:*:*)
12281257 UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
1229 case $UNAME_PROCESSOR in
1230 i386)
1231 eval $set_cc_for_build
1232 if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
1233 if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
1234 (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
1235 grep IS_64BIT_ARCH >/dev/null
1236 then
1237 UNAME_PROCESSOR="x86_64"
1238 fi
1239 fi ;;
1240 unknown) UNAME_PROCESSOR=powerpc ;;
1241 esac
1258 eval $set_cc_for_build
1259 if test "$UNAME_PROCESSOR" = unknown ; then
1260 UNAME_PROCESSOR=powerpc
1261 fi
1262 if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then
1263 if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
1264 if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
1265 (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
1266 grep IS_64BIT_ARCH >/dev/null
1267 then
1268 case $UNAME_PROCESSOR in
1269 i386) UNAME_PROCESSOR=x86_64 ;;
1270 powerpc) UNAME_PROCESSOR=powerpc64 ;;
1271 esac
1272 fi
1273 fi
1274 elif test "$UNAME_PROCESSOR" = i386 ; then
1275 # Avoid executing cc on OS X 10.9, as it ships with a stub
1276 # that puts up a graphical alert prompting to install
1277 # developer tools. Any system running Mac OS X 10.7 or
1278 # later (Darwin 11 and later) is required to have a 64-bit
1279 # processor. This is not true of the ARM version of Darwin
1280 # that Apple uses in portable devices.
1281 UNAME_PROCESSOR=x86_64
1282 fi
12421283 echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
12431284 exit ;;
12441285 *:procnto*:*:* | *:QNX:[0123456789]*:*)
12551296 NEO-?:NONSTOP_KERNEL:*:*)
12561297 echo neo-tandem-nsk${UNAME_RELEASE}
12571298 exit ;;
1258 NSE-?:NONSTOP_KERNEL:*:*)
1299 NSE-*:NONSTOP_KERNEL:*:*)
12591300 echo nse-tandem-nsk${UNAME_RELEASE}
12601301 exit ;;
12611302 NSR-?:NONSTOP_KERNEL:*:*)
13281369 echo ${UNAME_MACHINE}-unknown-esx
13291370 exit ;;
13301371 esac
1331
1332 #echo '(No uname command or uname output not recognized.)' 1>&2
1333 #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
13341372
13351373 eval $set_cc_for_build
13361374 cat >$dummy.c <<EOF
00 #! /bin/sh
11 # Configuration validation subroutine script.
2 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 # 2011, 2012 Free Software Foundation, Inc.
5
6 timestamp='2012-04-18'
7
8 # This file is (in principle) common to ALL GNU software.
9 # The presence of a machine in this file suggests that SOME GNU software
10 # can handle that machine. It does not imply ALL GNU software can.
11 #
12 # This file is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
2 # Copyright 1992-2013 Free Software Foundation, Inc.
3
4 timestamp='2013-10-01'
5
6 # This file is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
159 # (at your option) any later version.
1610 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
2115 #
2216 # You should have received a copy of the GNU General Public License
2317 # along with this program; if not, see <http://www.gnu.org/licenses/>.
2519 # As a special exception to the GNU General Public License, if you
2620 # distribute this file as part of a program that contains a
2721 # configuration script generated by Autoconf, you may include it under
28 # the same distribution terms that you use for the rest of that program.
29
30
31 # Please send patches to <config-patches@gnu.org>. Submit a context
32 # diff and a properly formatted GNU ChangeLog entry.
22 # the same distribution terms that you use for the rest of that
23 # program. This Exception is an additional permission under section 7
24 # of the GNU General Public License, version 3 ("GPLv3").
25
26
27 # Please send patches with a ChangeLog entry to config-patches@gnu.org.
3328 #
3429 # Configuration subroutine to validate and canonicalize a configuration type.
3530 # Supply the specified configuration type as an argument.
7267 version="\
7368 GNU config.sub ($timestamp)
7469
75 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
76 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
77 Free Software Foundation, Inc.
70 Copyright 1992-2013 Free Software Foundation, Inc.
7871
7972 This is free software; see the source for copying conditions. There is NO
8073 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
122115 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
123116 case $maybe_os in
124117 nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
125 linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
118 linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
126119 knetbsd*-gnu* | netbsd*-gnu* | \
127120 kopensolaris*-gnu* | \
128121 storm-chaos* | os2-emx* | rtmk-nova*)
155148 -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
156149 -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
157150 -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
158 -apple | -axis | -knuth | -cray | -microblaze)
151 -apple | -axis | -knuth | -cray | -microblaze*)
159152 os=
160153 basic_machine=$1
161154 ;;
258251 | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
259252 | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
260253 | am33_2.0 \
261 | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
262 | be32 | be64 \
254 | arc | arceb \
255 | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
256 | avr | avr32 \
257 | be32 | be64 \
263258 | bfin \
264 | c4x | clipper \
259 | c4x | c8051 | clipper \
265260 | d10v | d30v | dlx | dsp16xx \
266261 | epiphany \
267262 | fido | fr30 | frv \
269264 | hexagon \
270265 | i370 | i860 | i960 | ia64 \
271266 | ip2k | iq2000 \
267 | k1om \
272268 | le32 | le64 \
273269 | lm32 \
274270 | m32c | m32r | m32rle | m68000 | m68k | m88k \
275 | maxq | mb | microblaze | mcore | mep | metag \
271 | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
276272 | mips | mipsbe | mipseb | mipsel | mipsle \
277273 | mips16 \
278274 | mips64 | mips64el \
290286 | mipsisa64r2 | mipsisa64r2el \
291287 | mipsisa64sb1 | mipsisa64sb1el \
292288 | mipsisa64sr71k | mipsisa64sr71kel \
289 | mipsr5900 | mipsr5900el \
293290 | mipstx39 | mipstx39el \
294291 | mn10200 | mn10300 \
295292 | moxie \
296293 | mt \
297294 | msp430 \
298295 | nds32 | nds32le | nds32be \
299 | nios | nios2 \
296 | nios | nios2 | nios2eb | nios2el \
300297 | ns16k | ns32k \
301298 | open8 \
302 | or32 \
299 | or1k | or32 \
303300 | pdp10 | pdp11 | pj | pjl \
304301 | powerpc | powerpc64 | powerpc64le | powerpcle \
305302 | pyramid \
327324 c6x)
328325 basic_machine=tic6x-unknown
329326 ;;
330 m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip)
327 m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
331328 basic_machine=$basic_machine-unknown
332329 os=-none
333330 ;;
369366 | aarch64-* | aarch64_be-* \
370367 | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
371368 | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
372 | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
369 | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
373370 | arm-* | armbe-* | armle-* | armeb-* | armv*-* \
374371 | avr-* | avr32-* \
375372 | be32-* | be64-* \
376373 | bfin-* | bs2000-* \
377374 | c[123]* | c30-* | [cjt]90-* | c4x-* \
378 | clipper-* | craynv-* | cydra-* \
375 | c8051-* | clipper-* | craynv-* | cydra-* \
379376 | d10v-* | d30v-* | dlx-* \
380377 | elxsi-* \
381378 | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
384381 | hexagon-* \
385382 | i*86-* | i860-* | i960-* | ia64-* \
386383 | ip2k-* | iq2000-* \
384 | k1om-* \
387385 | le32-* | le64-* \
388386 | lm32-* \
389387 | m32c-* | m32r-* | m32rle-* \
390388 | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
391 | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
389 | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
390 | microblaze-* | microblazeel-* \
392391 | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
393392 | mips16-* \
394393 | mips64-* | mips64el-* \
406405 | mipsisa64r2-* | mipsisa64r2el-* \
407406 | mipsisa64sb1-* | mipsisa64sb1el-* \
408407 | mipsisa64sr71k-* | mipsisa64sr71kel-* \
408 | mipsr5900-* | mipsr5900el-* \
409409 | mipstx39-* | mipstx39el-* \
410410 | mmix-* \
411411 | mt-* \
412412 | msp430-* \
413413 | nds32-* | nds32le-* | nds32be-* \
414 | nios-* | nios2-* \
414 | nios-* | nios2-* | nios2eb-* | nios2el-* \
415415 | none-* | np1-* | ns16k-* | ns32k-* \
416416 | open8-* \
417417 | orion-* \
787787 basic_machine=ns32k-utek
788788 os=-sysv
789789 ;;
790 microblaze)
790 microblaze*)
791791 basic_machine=microblaze-xilinx
792792 ;;
793 mingw64)
794 basic_machine=x86_64-pc
795 os=-mingw64
796 ;;
793797 mingw32)
794 basic_machine=i386-pc
798 basic_machine=i686-pc
795799 os=-mingw32
796800 ;;
797801 mingw32ce)
827831 basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
828832 ;;
829833 msys)
830 basic_machine=i386-pc
834 basic_machine=i686-pc
831835 os=-msys
832836 ;;
833837 mvs)
10181022 basic_machine=i586-unknown
10191023 os=-pw32
10201024 ;;
1021 rdos)
1025 rdos | rdos64)
1026 basic_machine=x86_64-pc
1027 os=-rdos
1028 ;;
1029 rdos32)
10221030 basic_machine=i386-pc
10231031 os=-rdos
10241032 ;;
13451353 -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
13461354 | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
13471355 | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
1348 | -sym* | -kopensolaris* \
1356 | -sym* | -kopensolaris* | -plan9* \
13491357 | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
13501358 | -aos* | -aros* \
13511359 | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
13521360 | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
13531361 | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
1354 | -openbsd* | -solidbsd* \
1362 | -bitrig* | -openbsd* | -solidbsd* \
13551363 | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
13561364 | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
13571365 | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
13581366 | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
13591367 | -chorusos* | -chorusrdb* | -cegcc* \
13601368 | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
1361 | -mingw32* | -linux-gnu* | -linux-android* \
1362 | -linux-newlib* | -linux-uclibc* \
1369 | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
1370 | -linux-newlib* | -linux-musl* | -linux-uclibc* \
13631371 | -uxpv* | -beos* | -mpeix* | -udk* \
13641372 | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
13651373 | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
14911499 -aros*)
14921500 os=-aros
14931501 ;;
1494 -kaos*)
1495 os=-kaos
1496 ;;
14971502 -zvmoe)
14981503 os=-zvmoe
14991504 ;;
15421547 c4x-* | tic4x-*)
15431548 os=-coff
15441549 ;;
1550 c8051-*)
1551 os=-elf
1552 ;;
15451553 hexagon-*)
15461554 os=-elf
15471555 ;;
15831591 os=-elf
15841592 ;;
15851593 mips*-*)
1594 os=-elf
1595 ;;
1596 or1k-*)
15861597 os=-elf
15871598 ;;
15881599 or32-*)
00 #! /bin/sh
11 # Guess values for system-dependent variables and create Makefiles.
2 # Generated by GNU Autoconf 2.69 for fping 3.16-rc2.
2 # Generated by GNU Autoconf 2.69 for fping 3.16.
33 #
44 #
55 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
576576 # Identity of this package.
577577 PACKAGE_NAME='fping'
578578 PACKAGE_TARNAME='fping'
579 PACKAGE_VERSION='3.16-rc2'
580 PACKAGE_STRING='fping 3.16-rc2'
579 PACKAGE_VERSION='3.16'
580 PACKAGE_STRING='fping 3.16'
581581 PACKAGE_BUGREPORT=''
582582 PACKAGE_URL=''
583583
685685 CC
686686 IPV6_FALSE
687687 IPV6_TRUE
688 IPV4_FALSE
689 IPV4_TRUE
688690 target_alias
689691 host_alias
690692 build_alias
12821284 # Omit some internal or obsolete options to make the list less imposing.
12831285 # This message is too long to be a string in the A/UX 3.1 sh.
12841286 cat <<_ACEOF
1285 \`configure' configures fping 3.16-rc2 to adapt to many kinds of systems.
1287 \`configure' configures fping 3.16 to adapt to many kinds of systems.
12861288
12871289 Usage: $0 [OPTION]... [VAR=VALUE]...
12881290
13531355
13541356 if test -n "$ac_init_help"; then
13551357 case $ac_init_help in
1356 short | recursive ) echo "Configuration of fping 3.16-rc2:";;
1358 short | recursive ) echo "Configuration of fping 3.16:";;
13571359 esac
13581360 cat <<\_ACEOF
13591361
13611363 --disable-option-checking ignore unrecognized --enable/--with options
13621364 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
13631365 --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
1364 --enable-ipv4 (ignored for compatibility with previous versions)
1365 --enable-ipv6 Build IPv6 capable fping6
1366 --enable-ipv4 Build IPv4 capable fping
1367 --enable-ipv6 Build IPv6 capable fping6
13661368 --disable-timestamp Disable kernel-based packet timestaping
13671369 (SO_TIMESTAMP)
13681370 --enable-dependency-tracking
14511453 test -n "$ac_init_help" && exit $ac_status
14521454 if $ac_init_version; then
14531455 cat <<\_ACEOF
1454 fping configure 3.16-rc2
1456 fping configure 3.16
14551457 generated by GNU Autoconf 2.69
14561458
14571459 Copyright (C) 2012 Free Software Foundation, Inc.
18621864 This file contains any messages produced by compilers while
18631865 running configure, to aid debugging if configure makes a mistake.
18641866
1865 It was created by fping $as_me 3.16-rc2, which was
1867 It was created by fping $as_me 3.16, which was
18661868 generated by GNU Autoconf 2.69. Invocation command line was
18671869
18681870 $ $0 $@
22132215
22142216 # Check whether --enable-ipv4 was given.
22152217 if test "${enable_ipv4+set}" = set; then :
2216 enableval=$enable_ipv4;
2218 enableval=$enable_ipv4; case "${enableval}" in
2219 yes) ipv4=true ;;
2220 no) ipv4=false ;;
2221 *) as_fn_error $? "bad value ${enableval} for --enable-ipv4" "$LINENO" 5 ;;
2222 esac
2223 else
2224 ipv4=true
2225 fi
2226
2227 if test x$ipv4 = xtrue; then
2228 IPV4_TRUE=
2229 IPV4_FALSE='#'
2230 else
2231 IPV4_TRUE='#'
2232 IPV4_FALSE=
22172233 fi
22182234
22192235
22252241 *) as_fn_error $? "bad value ${enableval} for --enable-ipv6" "$LINENO" 5 ;;
22262242 esac
22272243 else
2228 ipv6=true
2229 fi
2230
2231 if test x$ipv6 = xtrue; then
2244 ipv6=false
2245 fi
2246
2247 if test x$ipv6 = xtrue; then
22322248 IPV6_TRUE=
22332249 IPV6_FALSE='#'
22342250 else
22362252 IPV6_FALSE=
22372253 fi
22382254
2255
2256 if test x$ipv4 = xfalse && test x$ipv6 = xfalse; then
2257 as_fn_error $? "You must enable at least one of IPv4 and IPv6." "$LINENO" 5
2258 fi
22392259
22402260 # Check whether --enable-timestamp was given.
22412261 if test "${enable_timestamp+set}" = set; then :
22422262 enableval=$enable_timestamp;
22432263 fi
22442264
2245 ac_aux_dir=
2246 for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
2247 if test -f "$ac_dir/install-sh"; then
2248 ac_aux_dir=$ac_dir
2249 ac_install_sh="$ac_aux_dir/install-sh -c"
2250 break
2251 elif test -f "$ac_dir/install.sh"; then
2252 ac_aux_dir=$ac_dir
2253 ac_install_sh="$ac_aux_dir/install.sh -c"
2254 break
2255 elif test -f "$ac_dir/shtool"; then
2256 ac_aux_dir=$ac_dir
2257 ac_install_sh="$ac_aux_dir/shtool install -c"
2258 break
2259 fi
2260 done
2261 if test -z "$ac_aux_dir"; then
2262 as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
2263 fi
2264
2265 # These three variables are undocumented and unsupported,
2266 # and are intended to be withdrawn in a future Autoconf release.
2267 # They can cause serious problems if a builder's source tree is in a directory
2268 # whose full name contains unusual characters.
2269 ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var.
2270 ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var.
2271 ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var.
2272
2273
2274 # Expand $ac_aux_dir to an absolute path.
2275 am_aux_dir=`cd "$ac_aux_dir" && pwd`
2265 # expand $ac_aux_dir to an absolute path
2266 am_aux_dir=`cd $ac_aux_dir && pwd`
22762267
22772268 ac_ext=c
22782269 ac_cpp='$CPP $CPPFLAGS'
31433134 as_fn_error $? "--enable-timestamp not supported on this platform" "$LINENO" 5
31443135
31453136 fi
3137
3138 ac_aux_dir=
3139 for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
3140 if test -f "$ac_dir/install-sh"; then
3141 ac_aux_dir=$ac_dir
3142 ac_install_sh="$ac_aux_dir/install-sh -c"
3143 break
3144 elif test -f "$ac_dir/install.sh"; then
3145 ac_aux_dir=$ac_dir
3146 ac_install_sh="$ac_aux_dir/install.sh -c"
3147 break
3148 elif test -f "$ac_dir/shtool"; then
3149 ac_aux_dir=$ac_dir
3150 ac_install_sh="$ac_aux_dir/shtool install -c"
3151 break
3152 fi
3153 done
3154 if test -z "$ac_aux_dir"; then
3155 as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
3156 fi
3157
3158 # These three variables are undocumented and unsupported,
3159 # and are intended to be withdrawn in a future Autoconf release.
3160 # They can cause serious problems if a builder's source tree is in a directory
3161 # whose full name contains unusual characters.
3162 ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var.
3163 ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var.
3164 ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var.
3165
31463166
31473167 # Make sure we can run config.sub.
31483168 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
38003820
38013821 # Define the identity of the package.
38023822 PACKAGE='fping'
3803 VERSION='3.16-rc2'
3823 VERSION='3.16'
38043824
38053825
38063826 cat >>confdefs.h <<_ACEOF
40214041 fi
40224042 fi
40234043
4024
40254044 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
40264045 $as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
40274046 # Check whether --enable-maintainer-mode was given.
52835302 LTLIBOBJS=$ac_ltlibobjs
52845303
52855304
5305 if test -z "${IPV4_TRUE}" && test -z "${IPV4_FALSE}"; then
5306 as_fn_error $? "conditional \"IPV4\" was never defined.
5307 Usually this means the macro was only invoked conditionally." "$LINENO" 5
5308 fi
52865309 if test -z "${IPV6_TRUE}" && test -z "${IPV6_FALSE}"; then
52875310 as_fn_error $? "conditional \"IPV6\" was never defined.
52885311 Usually this means the macro was only invoked conditionally." "$LINENO" 5
57125735 # report actual input values of CONFIG_FILES etc. instead of their
57135736 # values after options handling.
57145737 ac_log="
5715 This file was extended by fping $as_me 3.16-rc2, which was
5738 This file was extended by fping $as_me 3.16, which was
57165739 generated by GNU Autoconf 2.69. Invocation command line was
57175740
57185741 CONFIG_FILES = $CONFIG_FILES
57785801 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
57795802 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
57805803 ac_cs_version="\\
5781 fping config.status 3.16-rc2
5804 fping config.status 3.16
57825805 configured by $0, generated by GNU Autoconf 2.69,
57835806 with options \\"\$ac_cs_config\\"
57845807
22 dnl Minimum Autoconf version required.
33 AC_PREREQ(2.59)
44
5 AC_INIT([fping],[3.16-rc2])
5 AC_INIT([fping],[3.16])
66
77 dnl make ipv4 and ipv6 options
88 AC_ARG_ENABLE([ipv4],
9 AS_HELP_STRING([--enable-ipv4], [(ignored for compatibility with previous versions)]))
9 [ --enable-ipv4 Build IPv4 capable fping],
10 [case "${enableval}" in
11 yes) ipv4=true ;;
12 no) ipv4=false ;;
13 *) AC_MSG_ERROR([bad value ${enableval} for --enable-ipv4]) ;;
14 esac],[ipv4=true])
15 AM_CONDITIONAL([IPV4], [test x$ipv4 = xtrue])
1016
1117 AC_ARG_ENABLE([ipv6],
12 AS_HELP_STRING([--enable-ipv6], [Build IPv6 capable fping6]),
18 [ --enable-ipv6 Build IPv6 capable fping6],
1319 [case "${enableval}" in
1420 yes) ipv6=true ;;
1521 no) ipv6=false ;;
1622 *) AC_MSG_ERROR([bad value ${enableval} for --enable-ipv6]) ;;
17 esac],[ipv6=true])
18 AM_CONDITIONAL([IPV6], [test x$ipv6 = xtrue])
23 esac],[ipv6=false])
24 AM_CONDITIONAL([IPV6], [test x$ipv6 = xtrue])
25
26 if test x$ipv4 = xfalse && test x$ipv6 = xfalse; then
27 AC_MSG_ERROR([You must enable at least one of IPv4 and IPv6.])
28 fi
1929
2030 AC_ARG_ENABLE([timestamp],
2131 AS_HELP_STRING([--disable-timestamp], [Disable kernel-based packet timestaping (SO_TIMESTAMP)]))
+271
-188
depcomp less more
00 #! /bin/sh
11 # depcomp - compile a program generating dependencies as side-effects
22
3 scriptversion=2012-03-27.16; # UTC
4
5 # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010,
6 # 2011, 2012 Free Software Foundation, Inc.
3 scriptversion=2013-05-30.07; # UTC
4
5 # Copyright (C) 1999-2013 Free Software Foundation, Inc.
76
87 # This program is free software; you can redistribute it and/or modify
98 # it under the terms of the GNU General Public License as published by
2726
2827 case $1 in
2928 '')
30 echo "$0: No command. Try '$0 --help' for more information." 1>&2
31 exit 1;
32 ;;
29 echo "$0: No command. Try '$0 --help' for more information." 1>&2
30 exit 1;
31 ;;
3332 -h | --h*)
3433 cat <<\EOF
3534 Usage: depcomp [--help] [--version] PROGRAM [ARGS]
5655 ;;
5756 esac
5857
58 # Get the directory component of the given path, and save it in the
59 # global variables '$dir'. Note that this directory component will
60 # be either empty or ending with a '/' character. This is deliberate.
61 set_dir_from ()
62 {
63 case $1 in
64 */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
65 *) dir=;;
66 esac
67 }
68
69 # Get the suffix-stripped basename of the given path, and save it the
70 # global variable '$base'.
71 set_base_from ()
72 {
73 base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
74 }
75
76 # If no dependency file was actually created by the compiler invocation,
77 # we still have to create a dummy depfile, to avoid errors with the
78 # Makefile "include basename.Plo" scheme.
79 make_dummy_depfile ()
80 {
81 echo "#dummy" > "$depfile"
82 }
83
84 # Factor out some common post-processing of the generated depfile.
85 # Requires the auxiliary global variable '$tmpdepfile' to be set.
86 aix_post_process_depfile ()
87 {
88 # If the compiler actually managed to produce a dependency file,
89 # post-process it.
90 if test -f "$tmpdepfile"; then
91 # Each line is of the form 'foo.o: dependency.h'.
92 # Do two passes, one to just change these to
93 # $object: dependency.h
94 # and one to simply output
95 # dependency.h:
96 # which is needed to avoid the deleted-header problem.
97 { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
98 sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
99 } > "$depfile"
100 rm -f "$tmpdepfile"
101 else
102 make_dummy_depfile
103 fi
104 }
105
59106 # A tabulation character.
60107 tab=' '
61108 # A newline character.
62109 nl='
63110 '
111 # Character ranges might be problematic outside the C locale.
112 # These definitions help.
113 upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
114 lower=abcdefghijklmnopqrstuvwxyz
115 digits=0123456789
116 alpha=${upper}${lower}
64117
65118 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
66119 echo "depcomp: Variables source, object and depmode must be set" 1>&2
73126 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
74127
75128 rm -f "$tmpdepfile"
129
130 # Avoid interferences from the environment.
131 gccflag= dashmflag=
76132
77133 # Some modes work just like other modes, but use different flags. We
78134 # parameterize here, but still list the modes in the big case below,
85141 fi
86142
87143 if test "$depmode" = dashXmstdout; then
88 # This is just like dashmstdout with a different argument.
89 dashmflag=-xM
90 depmode=dashmstdout
144 # This is just like dashmstdout with a different argument.
145 dashmflag=-xM
146 depmode=dashmstdout
91147 fi
92148
93149 cygpath_u="cygpath -u -f -"
94150 if test "$depmode" = msvcmsys; then
95 # This is just like msvisualcpp but w/o cygpath translation.
96 # Just convert the backslash-escaped backslashes to single forward
97 # slashes to satisfy depend.m4
98 cygpath_u='sed s,\\\\,/,g'
99 depmode=msvisualcpp
151 # This is just like msvisualcpp but w/o cygpath translation.
152 # Just convert the backslash-escaped backslashes to single forward
153 # slashes to satisfy depend.m4
154 cygpath_u='sed s,\\\\,/,g'
155 depmode=msvisualcpp
100156 fi
101157
102158 if test "$depmode" = msvc7msys; then
103 # This is just like msvc7 but w/o cygpath translation.
104 # Just convert the backslash-escaped backslashes to single forward
105 # slashes to satisfy depend.m4
106 cygpath_u='sed s,\\\\,/,g'
107 depmode=msvc7
159 # This is just like msvc7 but w/o cygpath translation.
160 # Just convert the backslash-escaped backslashes to single forward
161 # slashes to satisfy depend.m4
162 cygpath_u='sed s,\\\\,/,g'
163 depmode=msvc7
108164 fi
109165
110166 if test "$depmode" = xlc; then
111 # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations.
112 gccflag=-qmakedep=gcc,-MF
113 depmode=gcc
167 # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
168 gccflag=-qmakedep=gcc,-MF
169 depmode=gcc
114170 fi
115171
116172 case "$depmode" in
133189 done
134190 "$@"
135191 stat=$?
136 if test $stat -eq 0; then :
137 else
192 if test $stat -ne 0; then
138193 rm -f "$tmpdepfile"
139194 exit $stat
140195 fi
142197 ;;
143198
144199 gcc)
200 ## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
201 ## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
202 ## (see the conditional assignment to $gccflag above).
145203 ## There are various ways to get dependency output from gcc. Here's
146204 ## why we pick this rather obscure method:
147205 ## - Don't want to use -MD because we'd like the dependencies to end
148206 ## up in a subdir. Having to rename by hand is ugly.
149207 ## (We might end up doing this anyway to support other compilers.)
150208 ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
151 ## -MM, not -M (despite what the docs say).
209 ## -MM, not -M (despite what the docs say). Also, it might not be
210 ## supported by the other compilers which use the 'gcc' depmode.
152211 ## - Using -M directly means running the compiler twice (even worse
153212 ## than renaming).
154213 if test -z "$gccflag"; then
156215 fi
157216 "$@" -Wp,"$gccflag$tmpdepfile"
158217 stat=$?
159 if test $stat -eq 0; then :
160 else
218 if test $stat -ne 0; then
161219 rm -f "$tmpdepfile"
162220 exit $stat
163221 fi
164222 rm -f "$depfile"
165223 echo "$object : \\" > "$depfile"
166 alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
167 ## The second -e expression handles DOS-style file names with drive letters.
224 # The second -e expression handles DOS-style file names with drive
225 # letters.
168226 sed -e 's/^[^:]*: / /' \
169227 -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
170228 ## This next piece of magic avoids the "deleted header file" problem.
173231 ## typically no way to rebuild the header). We avoid this by adding
174232 ## dummy dependencies for each header file. Too bad gcc doesn't do
175233 ## this for us directly.
176 tr ' ' "$nl" < "$tmpdepfile" |
177234 ## Some versions of gcc put a space before the ':'. On the theory
178235 ## that the space means something, we add a space to the output as
179236 ## well. hp depmode also adds that space, but also prefixes the VPATH
180237 ## to the object. Take care to not repeat it in the output.
181238 ## Some versions of the HPUX 10.20 sed can't process this invocation
182239 ## correctly. Breaking it into two sed invocations is a workaround.
183 sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
184 | sed -e 's/$/ :/' >> "$depfile"
240 tr ' ' "$nl" < "$tmpdepfile" \
241 | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
242 | sed -e 's/$/ :/' >> "$depfile"
185243 rm -f "$tmpdepfile"
186244 ;;
187245
199257 "$@" -MDupdate "$tmpdepfile"
200258 fi
201259 stat=$?
202 if test $stat -eq 0; then :
203 else
260 if test $stat -ne 0; then
204261 rm -f "$tmpdepfile"
205262 exit $stat
206263 fi
208265
209266 if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
210267 echo "$object : \\" > "$depfile"
211
212268 # Clip off the initial element (the dependent). Don't try to be
213269 # clever and replace this with sed code, as IRIX sed won't handle
214270 # lines with more than a fixed number of characters (4096 in
216272 # the IRIX cc adds comments like '#:fec' to the end of the
217273 # dependency line.
218274 tr ' ' "$nl" < "$tmpdepfile" \
219 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
220 tr "$nl" ' ' >> "$depfile"
275 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
276 | tr "$nl" ' ' >> "$depfile"
221277 echo >> "$depfile"
222
223278 # The second pass generates a dummy entry for each header file.
224279 tr ' ' "$nl" < "$tmpdepfile" \
225 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
226 >> "$depfile"
280 | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
281 >> "$depfile"
227282 else
228 # The sourcefile does not contain any dependencies, so just
229 # store a dummy comment line, to avoid errors with the Makefile
230 # "include basename.Plo" scheme.
231 echo "#dummy" > "$depfile"
283 make_dummy_depfile
232284 fi
233285 rm -f "$tmpdepfile"
234286 ;;
246298 # current directory. Also, the AIX compiler puts '$object:' at the
247299 # start of each line; $object doesn't have directory information.
248300 # Version 6 uses the directory in both cases.
249 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
250 test "x$dir" = "x$object" && dir=
251 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
301 set_dir_from "$object"
302 set_base_from "$object"
252303 if test "$libtool" = yes; then
253304 tmpdepfile1=$dir$base.u
254305 tmpdepfile2=$base.u
261312 "$@" -M
262313 fi
263314 stat=$?
264
265 if test $stat -eq 0; then :
266 else
315 if test $stat -ne 0; then
267316 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
268317 exit $stat
269318 fi
272321 do
273322 test -f "$tmpdepfile" && break
274323 done
275 if test -f "$tmpdepfile"; then
276 # Each line is of the form 'foo.o: dependent.h'.
277 # Do two passes, one to just change these to
278 # '$object: dependent.h' and one to simply 'dependent.h:'.
279 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
280 sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
281 else
282 # The sourcefile does not contain any dependencies, so just
283 # store a dummy comment line, to avoid errors with the Makefile
284 # "include basename.Plo" scheme.
285 echo "#dummy" > "$depfile"
286 fi
324 aix_post_process_depfile
325 ;;
326
327 tcc)
328 # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
329 # FIXME: That version still under development at the moment of writing.
330 # Make that this statement remains true also for stable, released
331 # versions.
332 # It will wrap lines (doesn't matter whether long or short) with a
333 # trailing '\', as in:
334 #
335 # foo.o : \
336 # foo.c \
337 # foo.h \
338 #
339 # It will put a trailing '\' even on the last line, and will use leading
340 # spaces rather than leading tabs (at least since its commit 0394caf7
341 # "Emit spaces for -MD").
342 "$@" -MD -MF "$tmpdepfile"
343 stat=$?
344 if test $stat -ne 0; then
345 rm -f "$tmpdepfile"
346 exit $stat
347 fi
348 rm -f "$depfile"
349 # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
350 # We have to change lines of the first kind to '$object: \'.
351 sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
352 # And for each line of the second kind, we have to emit a 'dep.h:'
353 # dummy dependency, to avoid the deleted-header problem.
354 sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
287355 rm -f "$tmpdepfile"
288356 ;;
289357
290 icc)
291 # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'.
292 # However on
293 # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c
294 # ICC 7.0 will fill foo.d with something like
295 # foo.o: sub/foo.c
296 # foo.o: sub/foo.h
297 # which is wrong. We want
298 # sub/foo.o: sub/foo.c
299 # sub/foo.o: sub/foo.h
300 # sub/foo.c:
301 # sub/foo.h:
302 # ICC 7.1 will output
358 ## The order of this option in the case statement is important, since the
359 ## shell code in configure will try each of these formats in the order
360 ## listed in this file. A plain '-MD' option would be understood by many
361 ## compilers, so we must ensure this comes after the gcc and icc options.
362 pgcc)
363 # Portland's C compiler understands '-MD'.
364 # Will always output deps to 'file.d' where file is the root name of the
365 # source file under compilation, even if file resides in a subdirectory.
366 # The object file name does not affect the name of the '.d' file.
367 # pgcc 10.2 will output
303368 # foo.o: sub/foo.c sub/foo.h
304 # and will wrap long lines using '\':
369 # and will wrap long lines using '\' :
305370 # foo.o: sub/foo.c ... \
306371 # sub/foo.h ... \
307372 # ...
308 # tcc 0.9.26 (FIXME still under development at the moment of writing)
309 # will emit a similar output, but also prepend the continuation lines
310 # with horizontal tabulation characters.
311 "$@" -MD -MF "$tmpdepfile"
312 stat=$?
313 if test $stat -eq 0; then :
314 else
373 set_dir_from "$object"
374 # Use the source, not the object, to determine the base name, since
375 # that's sadly what pgcc will do too.
376 set_base_from "$source"
377 tmpdepfile=$base.d
378
379 # For projects that build the same source file twice into different object
380 # files, the pgcc approach of using the *source* file root name can cause
381 # problems in parallel builds. Use a locking strategy to avoid stomping on
382 # the same $tmpdepfile.
383 lockdir=$base.d-lock
384 trap "
385 echo '$0: caught signal, cleaning up...' >&2
386 rmdir '$lockdir'
387 exit 1
388 " 1 2 13 15
389 numtries=100
390 i=$numtries
391 while test $i -gt 0; do
392 # mkdir is a portable test-and-set.
393 if mkdir "$lockdir" 2>/dev/null; then
394 # This process acquired the lock.
395 "$@" -MD
396 stat=$?
397 # Release the lock.
398 rmdir "$lockdir"
399 break
400 else
401 # If the lock is being held by a different process, wait
402 # until the winning process is done or we timeout.
403 while test -d "$lockdir" && test $i -gt 0; do
404 sleep 1
405 i=`expr $i - 1`
406 done
407 fi
408 i=`expr $i - 1`
409 done
410 trap - 1 2 13 15
411 if test $i -le 0; then
412 echo "$0: failed to acquire lock after $numtries attempts" >&2
413 echo "$0: check lockdir '$lockdir'" >&2
414 exit 1
415 fi
416
417 if test $stat -ne 0; then
315418 rm -f "$tmpdepfile"
316419 exit $stat
317420 fi
318421 rm -f "$depfile"
319 # Each line is of the form 'foo.o: dependent.h',
320 # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'.
422 # Each line is of the form `foo.o: dependent.h',
423 # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
321424 # Do two passes, one to just change these to
322 # '$object: dependent.h' and one to simply 'dependent.h:'.
323 sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \
324 < "$tmpdepfile" > "$depfile"
325 sed '
326 s/[ '"$tab"'][ '"$tab"']*/ /g
327 s/^ *//
328 s/ *\\*$//
329 s/^[^:]*: *//
330 /^$/d
331 /:$/d
332 s/$/ :/
333 ' < "$tmpdepfile" >> "$depfile"
425 # `$object: dependent.h' and one to simply `dependent.h:'.
426 sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
427 # Some versions of the HPUX 10.20 sed can't process this invocation
428 # correctly. Breaking it into two sed invocations is a workaround.
429 sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
430 | sed -e 's/$/ :/' >> "$depfile"
334431 rm -f "$tmpdepfile"
335432 ;;
336433
341438 # 'foo.d', which lands next to the object file, wherever that
342439 # happens to be.
343440 # Much of this is similar to the tru64 case; see comments there.
344 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
345 test "x$dir" = "x$object" && dir=
346 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
441 set_dir_from "$object"
442 set_base_from "$object"
347443 if test "$libtool" = yes; then
348444 tmpdepfile1=$dir$base.d
349445 tmpdepfile2=$dir.libs/$base.d
354450 "$@" +Maked
355451 fi
356452 stat=$?
357 if test $stat -eq 0; then :
358 else
453 if test $stat -ne 0; then
359454 rm -f "$tmpdepfile1" "$tmpdepfile2"
360455 exit $stat
361456 fi
365460 test -f "$tmpdepfile" && break
366461 done
367462 if test -f "$tmpdepfile"; then
368 sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
463 sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
369464 # Add 'dependent.h:' lines.
370465 sed -ne '2,${
371 s/^ *//
372 s/ \\*$//
373 s/$/:/
374 p
375 }' "$tmpdepfile" >> "$depfile"
466 s/^ *//
467 s/ \\*$//
468 s/$/:/
469 p
470 }' "$tmpdepfile" >> "$depfile"
376471 else
377 echo "#dummy" > "$depfile"
472 make_dummy_depfile
378473 fi
379474 rm -f "$tmpdepfile" "$tmpdepfile2"
380475 ;;
381476
382477 tru64)
383 # The Tru64 compiler uses -MD to generate dependencies as a side
384 # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
385 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
386 # dependencies in 'foo.d' instead, so we check for that too.
387 # Subdirectories are respected.
388 dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
389 test "x$dir" = "x$object" && dir=
390 base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
391
392 if test "$libtool" = yes; then
393 # With Tru64 cc, shared objects can also be used to make a
394 # static library. This mechanism is used in libtool 1.4 series to
395 # handle both shared and static libraries in a single compilation.
396 # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
397 #
398 # With libtool 1.5 this exception was removed, and libtool now
399 # generates 2 separate objects for the 2 libraries. These two
400 # compilations output dependencies in $dir.libs/$base.o.d and
401 # in $dir$base.o.d. We have to check for both files, because
402 # one of the two compilations can be disabled. We should prefer
403 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
404 # automatically cleaned when .libs/ is deleted, while ignoring
405 # the former would cause a distcleancheck panic.
406 tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
407 tmpdepfile2=$dir$base.o.d # libtool 1.5
408 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
409 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
410 "$@" -Wc,-MD
411 else
412 tmpdepfile1=$dir$base.o.d
413 tmpdepfile2=$dir$base.d
414 tmpdepfile3=$dir$base.d
415 tmpdepfile4=$dir$base.d
416 "$@" -MD
417 fi
418
419 stat=$?
420 if test $stat -eq 0; then :
421 else
422 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
423 exit $stat
424 fi
425
426 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
427 do
428 test -f "$tmpdepfile" && break
429 done
430 if test -f "$tmpdepfile"; then
431 sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
432 sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
433 else
434 echo "#dummy" > "$depfile"
435 fi
436 rm -f "$tmpdepfile"
437 ;;
478 # The Tru64 compiler uses -MD to generate dependencies as a side
479 # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
480 # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
481 # dependencies in 'foo.d' instead, so we check for that too.
482 # Subdirectories are respected.
483 set_dir_from "$object"
484 set_base_from "$object"
485
486 if test "$libtool" = yes; then
487 # Libtool generates 2 separate objects for the 2 libraries. These
488 # two compilations output dependencies in $dir.libs/$base.o.d and
489 # in $dir$base.o.d. We have to check for both files, because
490 # one of the two compilations can be disabled. We should prefer
491 # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
492 # automatically cleaned when .libs/ is deleted, while ignoring
493 # the former would cause a distcleancheck panic.
494 tmpdepfile1=$dir$base.o.d # libtool 1.5
495 tmpdepfile2=$dir.libs/$base.o.d # Likewise.
496 tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
497 "$@" -Wc,-MD
498 else
499 tmpdepfile1=$dir$base.d
500 tmpdepfile2=$dir$base.d
501 tmpdepfile3=$dir$base.d
502 "$@" -MD
503 fi
504
505 stat=$?
506 if test $stat -ne 0; then
507 rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
508 exit $stat
509 fi
510
511 for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
512 do
513 test -f "$tmpdepfile" && break
514 done
515 # Same post-processing that is required for AIX mode.
516 aix_post_process_depfile
517 ;;
438518
439519 msvc7)
440520 if test "$libtool" = yes; then
445525 "$@" $showIncludes > "$tmpdepfile"
446526 stat=$?
447527 grep -v '^Note: including file: ' "$tmpdepfile"
448 if test "$stat" = 0; then :
449 else
528 if test $stat -ne 0; then
450529 rm -f "$tmpdepfile"
451530 exit $stat
452531 fi
472551 G
473552 p
474553 }' >> "$depfile"
554 echo >> "$depfile" # make sure the fragment doesn't end with a backslash
475555 rm -f "$tmpdepfile"
476556 ;;
477557
523603 # in the target name. This is to cope with DOS-style filenames:
524604 # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
525605 "$@" $dashmflag |
526 sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile"
606 sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
527607 rm -f "$depfile"
528608 cat < "$tmpdepfile" > "$depfile"
529 tr ' ' "$nl" < "$tmpdepfile" | \
530 ## Some versions of the HPUX 10.20 sed can't process this invocation
531 ## correctly. Breaking it into two sed invocations is a workaround.
532 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
609 # Some versions of the HPUX 10.20 sed can't process this sed invocation
610 # correctly. Breaking it into two sed invocations is a workaround.
611 tr ' ' "$nl" < "$tmpdepfile" \
612 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
613 | sed -e 's/$/ :/' >> "$depfile"
533614 rm -f "$tmpdepfile"
534615 ;;
535616
582663 # makedepend may prepend the VPATH from the source file name to the object.
583664 # No need to regex-escape $object, excess matching of '.' is harmless.
584665 sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
585 sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \
586 ## Some versions of the HPUX 10.20 sed can't process this invocation
587 ## correctly. Breaking it into two sed invocations is a workaround.
588 sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
666 # Some versions of the HPUX 10.20 sed can't process the last invocation
667 # correctly. Breaking it into two sed invocations is a workaround.
668 sed '1,2d' "$tmpdepfile" \
669 | tr ' ' "$nl" \
670 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
671 | sed -e 's/$/ :/' >> "$depfile"
589672 rm -f "$tmpdepfile" "$tmpdepfile".bak
590673 ;;
591674
621704 esac
622705 done
623706
624 "$@" -E |
625 sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
626 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
627 sed '$ s: \\$::' > "$tmpdepfile"
707 "$@" -E \
708 | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
709 -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
710 | sed '$ s: \\$::' > "$tmpdepfile"
628711 rm -f "$depfile"
629712 echo "$object : \\" > "$depfile"
630713 cat < "$tmpdepfile" >> "$depfile"
656739 shift
657740 ;;
658741 "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
659 set fnord "$@"
660 shift
661 shift
662 ;;
742 set fnord "$@"
743 shift
744 shift
745 ;;
663746 *)
664 set fnord "$@" "$arg"
665 shift
666 shift
667 ;;
747 set fnord "$@" "$arg"
748 shift
749 shift
750 ;;
668751 esac
669752 done
670753 "$@" -E 2>/dev/null |
00 man_MANS =
11
2 if IPV4
23 man_MANS += fping.8
4 endif
35
46 if IPV6
57 man_MANS += fping6.8
7777 build_triplet = @build@
7878 host_triplet = @host@
7979 target_triplet = @target@
80 @IPV6_TRUE@am__append_1 = fping6.8
80 @IPV4_TRUE@am__append_1 = fping.8
81 @IPV6_TRUE@am__append_2 = fping6.8
8182 subdir = doc
8283 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
8384 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
240241 top_build_prefix = @top_build_prefix@
241242 top_builddir = @top_builddir@
242243 top_srcdir = @top_srcdir@
243 man_MANS = fping.8 $(am__append_1)
244 man_MANS = $(am__append_1) $(am__append_2)
244245 EXTRA_DIST = fping.8 fping6.8 fping.pod README.1992
245246 all: all-am
246247
0 .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
0 .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
11 .\"
22 .\" Standard preamble:
33 .\" ========================================================================
132132 .\" ========================================================================
133133 .\"
134134 .IX Title "FPING 8"
135 .TH FPING 8 "2017-01-31" "fping" ""
135 .TH FPING 8 "2017-02-09" "fping" ""
136136 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
137137 .\" way too many mistakes in technical documents.
138138 .if n .ad l
162162 addresses instead of IPv4.
163163 .SH "OPTIONS"
164164 .IX Header "OPTIONS"
165 .IP "\fB\-4\fR" 5
166 .IX Item "-4"
167 Restrict name resolution and IPs to IPv4 addresses.
168 .IP "\fB\-6\fR" 5
169 .IX Item "-6"
170 Restrict name resolution and IPs to IPv6 addresses. If the program name is
171 \&'fping6' (via a sym-link, for example), then '\-6' is implicitly added.
172165 .IP "\fB\-a\fR" 5
173166 .IX Item "-a"
174167 Show systems that are alive.
2828
2929 =over 5
3030
31 =item B<-4>
32
33 Restrict name resolution and IPs to IPv4 addresses.
34
35 =item B<-6>
36
37 Restrict name resolution and IPs to IPv6 addresses. If the program name is
38 'fping6' (via a sym-link, for example), then '-6' is implicitly added.
39
4031 =item B<-a>
4132
4233 Show systems that are alive.
0 .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28)
0 .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
11 .\"
22 .\" Standard preamble:
33 .\" ========================================================================
132132 .\" ========================================================================
133133 .\"
134134 .IX Title "fping6 8"
135 .TH fping6 8 "2017-01-31" "fping" ""
135 .TH fping6 8 "2017-02-09" "fping" ""
136136 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
137137 .\" way too many mistakes in technical documents.
138138 .if n .ad l
162162 addresses instead of IPv4.
163163 .SH "OPTIONS"
164164 .IX Header "OPTIONS"
165 .IP "\fB\-4\fR" 5
166 .IX Item "-4"
167 Restrict name resolution and IPs to IPv4 addresses.
168 .IP "\fB\-6\fR" 5
169 .IX Item "-6"
170 Restrict name resolution and IPs to IPv6 addresses. If the program name is
171 \&'fping6' (via a sym-link, for example), then '\-6' is implicitly added.
172165 .IP "\fB\-a\fR" 5
173166 .IX Item "-a"
174167 Show systems that are alive.
00 #!/bin/sh
11 # install - install a program, script, or datafile
22
3 scriptversion=2011-01-19.21; # UTC
3 scriptversion=2011-11-20.07; # UTC
44
55 # This originates from X11R5 (mit/util/scripts/install.sh), which was
66 # later released in X11R6 (xc/config/util/install.sh) with the
3434 # FSF changes to this file are in the public domain.
3535 #
3636 # Calling this script install-sh is preferred over install.sh, to prevent
37 # `make' implicit rules from creating a file called install from it
37 # 'make' implicit rules from creating a file called install from it
3838 # when there is no Makefile.
3939 #
4040 # This script is compatible with the BSD install script, but was written
155155 -s) stripcmd=$stripprog;;
156156
157157 -t) dst_arg=$2
158 # Protect names problematic for `test' and other utilities.
158 # Protect names problematic for 'test' and other utilities.
159159 case $dst_arg in
160160 -* | [=\(\)!]) dst_arg=./$dst_arg;;
161161 esac
189189 fi
190190 shift # arg
191191 dst_arg=$arg
192 # Protect names problematic for `test' and other utilities.
192 # Protect names problematic for 'test' and other utilities.
193193 case $dst_arg in
194194 -* | [=\(\)!]) dst_arg=./$dst_arg;;
195195 esac
201201 echo "$0: no input file specified." >&2
202202 exit 1
203203 fi
204 # It's OK to call `install-sh -d' without argument.
204 # It's OK to call 'install-sh -d' without argument.
205205 # This can happen when creating conditional directories.
206206 exit 0
207207 fi
239239
240240 for src
241241 do
242 # Protect names problematic for `test' and other utilities.
242 # Protect names problematic for 'test' and other utilities.
243243 case $src in
244244 -* | [=\(\)!]) src=./$src;;
245245 esac
353353 if test -z "$dir_arg" || {
354354 # Check for POSIX incompatibilities with -m.
355355 # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
356 # other-writeable bit of parent directory when it shouldn't.
356 # other-writable bit of parent directory when it shouldn't.
357357 # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
358358 ls_ld_tmpdir=`ls -ld "$tmpdir"`
359359 case $ls_ld_tmpdir in
+155
-271
missing less more
00 #! /bin/sh
1 # Common stub for a few missing GNU programs while installing.
2
3 scriptversion=2012-01-06.13; # UTC
4
5 # Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
6 # 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
7 # Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
1 # Common wrapper for a few potentially missing GNU programs.
2
3 scriptversion=2013-10-28.13; # UTC
4
5 # Copyright (C) 1996-2013 Free Software Foundation, Inc.
6 # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
87
98 # This program is free software; you can redistribute it and/or modify
109 # it under the terms of the GNU General Public License as published by
2524 # the same distribution terms that you use for the rest of that program.
2625
2726 if test $# -eq 0; then
28 echo 1>&2 "Try \`$0 --help' for more information"
27 echo 1>&2 "Try '$0 --help' for more information"
2928 exit 1
3029 fi
3130
32 run=:
33 sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
34 sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
35
36 # In the cases where this matters, `missing' is being run in the
37 # srcdir already.
38 if test -f configure.ac; then
39 configure_ac=configure.ac
40 else
41 configure_ac=configure.in
42 fi
43
44 msg="missing on your system"
45
4631 case $1 in
47 --run)
48 # Try to run requested program, and just exit if it succeeds.
49 run=
50 shift
51 "$@" && exit 0
52 # Exit code 63 means version mismatch. This often happens
53 # when the user try to use an ancient version of a tool on
54 # a file that requires a minimum version. In this case we
55 # we should proceed has if the program had been absent, or
56 # if --run hadn't been passed.
57 if test $? = 63; then
58 run=:
59 msg="probably too old"
60 fi
61 ;;
32
33 --is-lightweight)
34 # Used by our autoconf macros to check whether the available missing
35 # script is modern enough.
36 exit 0
37 ;;
38
39 --run)
40 # Back-compat with the calling convention used by older automake.
41 shift
42 ;;
6243
6344 -h|--h|--he|--hel|--help)
6445 echo "\
6546 $0 [OPTION]... PROGRAM [ARGUMENT]...
6647
67 Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
68 error status if there is no known handling for PROGRAM.
48 Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
49 to PROGRAM being missing or too old.
6950
7051 Options:
7152 -h, --help display this help and exit
7253 -v, --version output version information and exit
73 --run try to run the given command, and emulate it if it fails
7454
7555 Supported PROGRAM values:
76 aclocal touch file \`aclocal.m4'
77 autoconf touch file \`configure'
78 autoheader touch file \`config.h.in'
79 autom4te touch the output file, or create a stub one
80 automake touch all \`Makefile.in' files
81 bison create \`y.tab.[ch]', if possible, from existing .[ch]
82 flex create \`lex.yy.c', if possible, from existing .c
83 help2man touch the output file
84 lex create \`lex.yy.c', if possible, from existing .c
85 makeinfo touch the output file
86 yacc create \`y.tab.[ch]', if possible, from existing .[ch]
87
88 Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
89 \`g' are ignored when checking the name.
56 aclocal autoconf autoheader autom4te automake makeinfo
57 bison yacc flex lex help2man
58
59 Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
60 'g' are ignored when checking the name.
9061
9162 Send bug reports to <bug-automake@gnu.org>."
9263 exit $?
9869 ;;
9970
10071 -*)
101 echo 1>&2 "$0: Unknown \`$1' option"
102 echo 1>&2 "Try \`$0 --help' for more information"
72 echo 1>&2 "$0: unknown '$1' option"
73 echo 1>&2 "Try '$0 --help' for more information"
10374 exit 1
10475 ;;
10576
10677 esac
10778
108 # normalize program name to check for.
109 program=`echo "$1" | sed '
110 s/^gnu-//; t
111 s/^gnu//; t
112 s/^g//; t'`
113
114 # Now exit if we have it, but it failed. Also exit now if we
115 # don't have it and --version was passed (most likely to detect
116 # the program). This is about non-GNU programs, so use $1 not
117 # $program.
118 case $1 in
119 lex*|yacc*)
120 # Not GNU programs, they don't have --version.
121 ;;
122
123 *)
124 if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
125 # We have it, but it failed.
126 exit 1
127 elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
128 # Could not run --version or --help. This is probably someone
129 # running `$TOOL --version' or `$TOOL --help' to check whether
130 # $TOOL exists and not knowing $TOOL uses missing.
131 exit 1
132 fi
133 ;;
134 esac
135
136 # If it does not exist, or fails to run (possibly an outdated version),
137 # try to emulate it.
138 case $program in
139 aclocal*)
140 echo 1>&2 "\
141 WARNING: \`$1' is $msg. You should only need it if
142 you modified \`acinclude.m4' or \`${configure_ac}'. You might want
143 to install the \`Automake' and \`Perl' packages. Grab them from
144 any GNU archive site."
145 touch aclocal.m4
146 ;;
147
148 autoconf*)
149 echo 1>&2 "\
150 WARNING: \`$1' is $msg. You should only need it if
151 you modified \`${configure_ac}'. You might want to install the
152 \`Autoconf' and \`GNU m4' packages. Grab them from any GNU
153 archive site."
154 touch configure
155 ;;
156
157 autoheader*)
158 echo 1>&2 "\
159 WARNING: \`$1' is $msg. You should only need it if
160 you modified \`acconfig.h' or \`${configure_ac}'. You might want
161 to install the \`Autoconf' and \`GNU m4' packages. Grab them
162 from any GNU archive site."
163 files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
164 test -z "$files" && files="config.h"
165 touch_files=
166 for f in $files; do
167 case $f in
168 *:*) touch_files="$touch_files "`echo "$f" |
169 sed -e 's/^[^:]*://' -e 's/:.*//'`;;
170 *) touch_files="$touch_files $f.in";;
171 esac
172 done
173 touch $touch_files
174 ;;
175
176 automake*)
177 echo 1>&2 "\
178 WARNING: \`$1' is $msg. You should only need it if
179 you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
180 You might want to install the \`Automake' and \`Perl' packages.
181 Grab them from any GNU archive site."
182 find . -type f -name Makefile.am -print |
183 sed 's/\.am$/.in/' |
184 while read f; do touch "$f"; done
185 ;;
186
187 autom4te*)
188 echo 1>&2 "\
189 WARNING: \`$1' is needed, but is $msg.
190 You might have modified some files without having the
191 proper tools for further handling them.
192 You can get \`$1' as part of \`Autoconf' from any GNU
193 archive site."
194
195 file=`echo "$*" | sed -n "$sed_output"`
196 test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
197 if test -f "$file"; then
198 touch $file
199 else
200 test -z "$file" || exec >$file
201 echo "#! /bin/sh"
202 echo "# Created by GNU Automake missing as a replacement of"
203 echo "# $ $@"
204 echo "exit 0"
205 chmod +x $file
206 exit 1
207 fi
208 ;;
209
210 bison*|yacc*)
211 echo 1>&2 "\
212 WARNING: \`$1' $msg. You should only need it if
213 you modified a \`.y' file. You may need the \`Bison' package
214 in order for those modifications to take effect. You can get
215 \`Bison' from any GNU archive site."
216 rm -f y.tab.c y.tab.h
217 if test $# -ne 1; then
218 eval LASTARG=\${$#}
219 case $LASTARG in
220 *.y)
221 SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
222 if test -f "$SRCFILE"; then
223 cp "$SRCFILE" y.tab.c
224 fi
225 SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
226 if test -f "$SRCFILE"; then
227 cp "$SRCFILE" y.tab.h
228 fi
229 ;;
230 esac
231 fi
232 if test ! -f y.tab.h; then
233 echo >y.tab.h
234 fi
235 if test ! -f y.tab.c; then
236 echo 'main() { return 0; }' >y.tab.c
237 fi
238 ;;
239
240 lex*|flex*)
241 echo 1>&2 "\
242 WARNING: \`$1' is $msg. You should only need it if
243 you modified a \`.l' file. You may need the \`Flex' package
244 in order for those modifications to take effect. You can get
245 \`Flex' from any GNU archive site."
246 rm -f lex.yy.c
247 if test $# -ne 1; then
248 eval LASTARG=\${$#}
249 case $LASTARG in
250 *.l)
251 SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
252 if test -f "$SRCFILE"; then
253 cp "$SRCFILE" lex.yy.c
254 fi
255 ;;
256 esac
257 fi
258 if test ! -f lex.yy.c; then
259 echo 'main() { return 0; }' >lex.yy.c
260 fi
261 ;;
262
263 help2man*)
264 echo 1>&2 "\
265 WARNING: \`$1' is $msg. You should only need it if
266 you modified a dependency of a manual page. You may need the
267 \`Help2man' package in order for those modifications to take
268 effect. You can get \`Help2man' from any GNU archive site."
269
270 file=`echo "$*" | sed -n "$sed_output"`
271 test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
272 if test -f "$file"; then
273 touch $file
274 else
275 test -z "$file" || exec >$file
276 echo ".ab help2man is required to generate this page"
277 exit $?
278 fi
279 ;;
280
281 makeinfo*)
282 echo 1>&2 "\
283 WARNING: \`$1' is $msg. You should only need it if
284 you modified a \`.texi' or \`.texinfo' file, or any other file
285 indirectly affecting the aspect of the manual. The spurious
286 call might also be the consequence of using a buggy \`make' (AIX,
287 DU, IRIX). You might want to install the \`Texinfo' package or
288 the \`GNU make' package. Grab either from any GNU archive site."
289 # The file to touch is that specified with -o ...
290 file=`echo "$*" | sed -n "$sed_output"`
291 test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
292 if test -z "$file"; then
293 # ... or it is the one specified with @setfilename ...
294 infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
295 file=`sed -n '
296 /^@setfilename/{
297 s/.* \([^ ]*\) *$/\1/
298 p
299 q
300 }' $infile`
301 # ... or it is derived from the source name (dir/f.texi becomes f.info)
302 test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
303 fi
304 # If the file does not exist, the user really needs makeinfo;
305 # let's fail without touching anything.
306 test -f $file || exit 1
307 touch $file
308 ;;
309
310 *)
311 echo 1>&2 "\
312 WARNING: \`$1' is needed, and is $msg.
313 You might have modified some files without having the
314 proper tools for further handling them. Check the \`README' file,
315 it often tells you about the needed prerequisites for installing
316 this package. You may also peek at any GNU archive site, in case
317 some other package would contain this missing \`$1' program."
318 exit 1
319 ;;
320 esac
321
322 exit 0
79 # Run the given program, remember its exit status.
80 "$@"; st=$?
81
82 # If it succeeded, we are done.
83 test $st -eq 0 && exit 0
84
85 # Also exit now if we it failed (or wasn't found), and '--version' was
86 # passed; such an option is passed most likely to detect whether the
87 # program is present and works.
88 case $2 in --version|--help) exit $st;; esac
89
90 # Exit code 63 means version mismatch. This often happens when the user
91 # tries to use an ancient version of a tool on a file that requires a
92 # minimum version.
93 if test $st -eq 63; then
94 msg="probably too old"
95 elif test $st -eq 127; then
96 # Program was missing.
97 msg="missing on your system"
98 else
99 # Program was found and executed, but failed. Give up.
100 exit $st
101 fi
102
103 perl_URL=http://www.perl.org/
104 flex_URL=http://flex.sourceforge.net/
105 gnu_software_URL=http://www.gnu.org/software
106
107 program_details ()
108 {
109 case $1 in
110 aclocal|automake)
111 echo "The '$1' program is part of the GNU Automake package:"
112 echo "<$gnu_software_URL/automake>"
113 echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
114 echo "<$gnu_software_URL/autoconf>"
115 echo "<$gnu_software_URL/m4/>"
116 echo "<$perl_URL>"
117 ;;
118 autoconf|autom4te|autoheader)
119 echo "The '$1' program is part of the GNU Autoconf package:"
120 echo "<$gnu_software_URL/autoconf/>"
121 echo "It also requires GNU m4 and Perl in order to run:"
122 echo "<$gnu_software_URL/m4/>"
123 echo "<$perl_URL>"
124 ;;
125 esac
126 }
127
128 give_advice ()
129 {
130 # Normalize program name to check for.
131 normalized_program=`echo "$1" | sed '
132 s/^gnu-//; t
133 s/^gnu//; t
134 s/^g//; t'`
135
136 printf '%s\n' "'$1' is $msg."
137
138 configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
139 case $normalized_program in
140 autoconf*)
141 echo "You should only need it if you modified 'configure.ac',"
142 echo "or m4 files included by it."
143 program_details 'autoconf'
144 ;;
145 autoheader*)
146 echo "You should only need it if you modified 'acconfig.h' or"
147 echo "$configure_deps."
148 program_details 'autoheader'
149 ;;
150 automake*)
151 echo "You should only need it if you modified 'Makefile.am' or"
152 echo "$configure_deps."
153 program_details 'automake'
154 ;;
155 aclocal*)
156 echo "You should only need it if you modified 'acinclude.m4' or"
157 echo "$configure_deps."
158 program_details 'aclocal'
159 ;;
160 autom4te*)
161 echo "You might have modified some maintainer files that require"
162 echo "the 'autom4te' program to be rebuilt."
163 program_details 'autom4te'
164 ;;
165 bison*|yacc*)
166 echo "You should only need it if you modified a '.y' file."
167 echo "You may want to install the GNU Bison package:"
168 echo "<$gnu_software_URL/bison/>"
169 ;;
170 lex*|flex*)
171 echo "You should only need it if you modified a '.l' file."
172 echo "You may want to install the Fast Lexical Analyzer package:"
173 echo "<$flex_URL>"
174 ;;
175 help2man*)
176 echo "You should only need it if you modified a dependency" \
177 "of a man page."
178 echo "You may want to install the GNU Help2man package:"
179 echo "<$gnu_software_URL/help2man/>"
180 ;;
181 makeinfo*)
182 echo "You should only need it if you modified a '.texi' file, or"
183 echo "any other file indirectly affecting the aspect of the manual."
184 echo "You might want to install the Texinfo package:"
185 echo "<$gnu_software_URL/texinfo/>"
186 echo "The spurious makeinfo call might also be the consequence of"
187 echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
188 echo "want to install GNU make:"
189 echo "<$gnu_software_URL/make/>"
190 ;;
191 *)
192 echo "You might have modified some files without having the proper"
193 echo "tools for further handling them. Check the 'README' file, it"
194 echo "often tells you about the needed prerequisites for installing"
195 echo "this package. You may also peek at any GNU archive site, in"
196 echo "case some other package contains this missing '$1' program."
197 ;;
198 esac
199 }
200
201 give_advice "$1" | sed -e '1s/^/WARNING: /' \
202 -e '2,$s/^/ /' >&2
203
204 # Propagate the correct exit status (expected to be 127 for a program
205 # not found, 63 for a program that failed due to version mismatch).
206 exit $st
323207
324208 # Local variables:
325209 # eval: (add-hook 'write-file-hooks 'time-stamp)
00 AM_CFLAGS = -Wall -Wextra -Wno-sign-compare
11
2 sbin_PROGRAMS = fping
2 prog =
33
4 fping_SOURCES = fping.c seqmap.c socket4.c fping.h options.h seqmap.h
4 if IPV4
5 prog += fping
6 endif
7 if IPV6
8 prog += fping6
9 endif
10
11 sbin_PROGRAMS = ${prog}
12
13 fping_SOURCES = fping.c seqmap.c socket.c socket4.c fping.h options.h seqmap.h
514 fping_DEPENDENCIES = ../config.h
6
7 if IPV6
8 fping_SOURCES += socket6.c
9 fping_CFLAGS = $(AM_CFLAGS) -DIPV6
10 install-exec-hook:
11 ln -s fping$(EXEEXT) $(DESTDIR)$(sbindir)/fping6
12 endif
15 fping6_SOURCES = fping.c seqmap.c socket.c socket6.c fping.h options.h seqmap.h
16 fping6_DEPENDENCIES = ../config.h
17 fping6_CFLAGS = $(AM_CFLAGS) -DIPV6
7878 build_triplet = @build@
7979 host_triplet = @host@
8080 target_triplet = @target@
81 sbin_PROGRAMS = fping$(EXEEXT)
82 @IPV6_TRUE@am__append_1 = socket6.c
81 @IPV4_TRUE@am__append_1 = fping
82 @IPV6_TRUE@am__append_2 = fping6
83 sbin_PROGRAMS = $(am__EXEEXT_3)
8384 subdir = src
8485 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
8586 $(top_srcdir)/depcomp
9192 CONFIG_HEADER = $(top_builddir)/config.h
9293 CONFIG_CLEAN_FILES =
9394 CONFIG_CLEAN_VPATH_FILES =
95 @IPV4_TRUE@am__EXEEXT_1 = fping$(EXEEXT)
96 @IPV6_TRUE@am__EXEEXT_2 = fping6$(EXEEXT)
97 am__EXEEXT_3 = $(am__EXEEXT_1) $(am__EXEEXT_2)
9498 am__installdirs = "$(DESTDIR)$(sbindir)"
9599 PROGRAMS = $(sbin_PROGRAMS)
96 am__fping_SOURCES_DIST = fping.c seqmap.c socket4.c fping.h options.h \
97 seqmap.h socket6.c
98 @IPV6_TRUE@am__objects_1 = fping-socket6.$(OBJEXT)
99 am_fping_OBJECTS = fping-fping.$(OBJEXT) fping-seqmap.$(OBJEXT) \
100 fping-socket4.$(OBJEXT) $(am__objects_1)
100 am_fping_OBJECTS = fping.$(OBJEXT) seqmap.$(OBJEXT) socket.$(OBJEXT) \
101 socket4.$(OBJEXT)
101102 fping_OBJECTS = $(am_fping_OBJECTS)
102103 fping_LDADD = $(LDADD)
103 fping_LINK = $(CCLD) $(fping_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
104 am_fping6_OBJECTS = fping6-fping.$(OBJEXT) fping6-seqmap.$(OBJEXT) \
105 fping6-socket.$(OBJEXT) fping6-socket6.$(OBJEXT)
106 fping6_OBJECTS = $(am_fping6_OBJECTS)
107 fping6_LDADD = $(LDADD)
108 fping6_LINK = $(CCLD) $(fping6_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
104109 $(LDFLAGS) -o $@
105110 AM_V_P = $(am__v_P_@AM_V@)
106111 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
134139 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
135140 am__v_CCLD_0 = @echo " CCLD " $@;
136141 am__v_CCLD_1 =
137 SOURCES = $(fping_SOURCES)
138 DIST_SOURCES = $(am__fping_SOURCES_DIST)
142 SOURCES = $(fping_SOURCES) $(fping6_SOURCES)
143 DIST_SOURCES = $(fping_SOURCES) $(fping6_SOURCES)
139144 am__can_run_installinfo = \
140145 case $$AM_UPDATE_INFO_DIR in \
141146 n|no|NO) false;; \
262267 top_builddir = @top_builddir@
263268 top_srcdir = @top_srcdir@
264269 AM_CFLAGS = -Wall -Wextra -Wno-sign-compare
265 fping_SOURCES = fping.c seqmap.c socket4.c fping.h options.h seqmap.h \
266 $(am__append_1)
270 prog = $(am__append_1) $(am__append_2)
271 fping_SOURCES = fping.c seqmap.c socket.c socket4.c fping.h options.h seqmap.h
267272 fping_DEPENDENCIES = ../config.h
268 @IPV6_TRUE@fping_CFLAGS = $(AM_CFLAGS) -DIPV6
273 fping6_SOURCES = fping.c seqmap.c socket.c socket6.c fping.h options.h seqmap.h
274 fping6_DEPENDENCIES = ../config.h
275 fping6_CFLAGS = $(AM_CFLAGS) -DIPV6
269276 all: all-am
270277
271278 .SUFFIXES:
345352
346353 fping$(EXEEXT): $(fping_OBJECTS) $(fping_DEPENDENCIES) $(EXTRA_fping_DEPENDENCIES)
347354 @rm -f fping$(EXEEXT)
348 $(AM_V_CCLD)$(fping_LINK) $(fping_OBJECTS) $(fping_LDADD) $(LIBS)
355 $(AM_V_CCLD)$(LINK) $(fping_OBJECTS) $(fping_LDADD) $(LIBS)
356
357 fping6$(EXEEXT): $(fping6_OBJECTS) $(fping6_DEPENDENCIES) $(EXTRA_fping6_DEPENDENCIES)
358 @rm -f fping6$(EXEEXT)
359 $(AM_V_CCLD)$(fping6_LINK) $(fping6_OBJECTS) $(fping6_LDADD) $(LIBS)
349360
350361 mostlyclean-compile:
351362 -rm -f *.$(OBJEXT)
353364 distclean-compile:
354365 -rm -f *.tab.c
355366
356 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping-fping.Po@am__quote@
357 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping-seqmap.Po@am__quote@
358 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping-socket4.Po@am__quote@
359 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping-socket6.Po@am__quote@
367 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping.Po@am__quote@
368 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping6-fping.Po@am__quote@
369 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping6-seqmap.Po@am__quote@
370 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping6-socket.Po@am__quote@
371 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fping6-socket6.Po@am__quote@
372 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/seqmap.Po@am__quote@
373 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socket.Po@am__quote@
374 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socket4.Po@am__quote@
360375
361376 .c.o:
362377 @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
372387 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
373388 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
374389
375 fping-fping.o: fping.c
376 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-fping.o -MD -MP -MF $(DEPDIR)/fping-fping.Tpo -c -o fping-fping.o `test -f 'fping.c' || echo '$(srcdir)/'`fping.c
377 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-fping.Tpo $(DEPDIR)/fping-fping.Po
378 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fping.c' object='fping-fping.o' libtool=no @AMDEPBACKSLASH@
379 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
380 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-fping.o `test -f 'fping.c' || echo '$(srcdir)/'`fping.c
381
382 fping-fping.obj: fping.c
383 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-fping.obj -MD -MP -MF $(DEPDIR)/fping-fping.Tpo -c -o fping-fping.obj `if test -f 'fping.c'; then $(CYGPATH_W) 'fping.c'; else $(CYGPATH_W) '$(srcdir)/fping.c'; fi`
384 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-fping.Tpo $(DEPDIR)/fping-fping.Po
385 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fping.c' object='fping-fping.obj' libtool=no @AMDEPBACKSLASH@
386 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
387 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-fping.obj `if test -f 'fping.c'; then $(CYGPATH_W) 'fping.c'; else $(CYGPATH_W) '$(srcdir)/fping.c'; fi`
388
389 fping-seqmap.o: seqmap.c
390 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-seqmap.o -MD -MP -MF $(DEPDIR)/fping-seqmap.Tpo -c -o fping-seqmap.o `test -f 'seqmap.c' || echo '$(srcdir)/'`seqmap.c
391 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-seqmap.Tpo $(DEPDIR)/fping-seqmap.Po
392 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='seqmap.c' object='fping-seqmap.o' libtool=no @AMDEPBACKSLASH@
393 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
394 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-seqmap.o `test -f 'seqmap.c' || echo '$(srcdir)/'`seqmap.c
395
396 fping-seqmap.obj: seqmap.c
397 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-seqmap.obj -MD -MP -MF $(DEPDIR)/fping-seqmap.Tpo -c -o fping-seqmap.obj `if test -f 'seqmap.c'; then $(CYGPATH_W) 'seqmap.c'; else $(CYGPATH_W) '$(srcdir)/seqmap.c'; fi`
398 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-seqmap.Tpo $(DEPDIR)/fping-seqmap.Po
399 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='seqmap.c' object='fping-seqmap.obj' libtool=no @AMDEPBACKSLASH@
400 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
401 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-seqmap.obj `if test -f 'seqmap.c'; then $(CYGPATH_W) 'seqmap.c'; else $(CYGPATH_W) '$(srcdir)/seqmap.c'; fi`
402
403 fping-socket4.o: socket4.c
404 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-socket4.o -MD -MP -MF $(DEPDIR)/fping-socket4.Tpo -c -o fping-socket4.o `test -f 'socket4.c' || echo '$(srcdir)/'`socket4.c
405 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-socket4.Tpo $(DEPDIR)/fping-socket4.Po
406 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket4.c' object='fping-socket4.o' libtool=no @AMDEPBACKSLASH@
407 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
408 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-socket4.o `test -f 'socket4.c' || echo '$(srcdir)/'`socket4.c
409
410 fping-socket4.obj: socket4.c
411 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-socket4.obj -MD -MP -MF $(DEPDIR)/fping-socket4.Tpo -c -o fping-socket4.obj `if test -f 'socket4.c'; then $(CYGPATH_W) 'socket4.c'; else $(CYGPATH_W) '$(srcdir)/socket4.c'; fi`
412 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-socket4.Tpo $(DEPDIR)/fping-socket4.Po
413 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket4.c' object='fping-socket4.obj' libtool=no @AMDEPBACKSLASH@
414 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
415 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-socket4.obj `if test -f 'socket4.c'; then $(CYGPATH_W) 'socket4.c'; else $(CYGPATH_W) '$(srcdir)/socket4.c'; fi`
416
417 fping-socket6.o: socket6.c
418 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-socket6.o -MD -MP -MF $(DEPDIR)/fping-socket6.Tpo -c -o fping-socket6.o `test -f 'socket6.c' || echo '$(srcdir)/'`socket6.c
419 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-socket6.Tpo $(DEPDIR)/fping-socket6.Po
420 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket6.c' object='fping-socket6.o' libtool=no @AMDEPBACKSLASH@
421 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
422 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-socket6.o `test -f 'socket6.c' || echo '$(srcdir)/'`socket6.c
423
424 fping-socket6.obj: socket6.c
425 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -MT fping-socket6.obj -MD -MP -MF $(DEPDIR)/fping-socket6.Tpo -c -o fping-socket6.obj `if test -f 'socket6.c'; then $(CYGPATH_W) 'socket6.c'; else $(CYGPATH_W) '$(srcdir)/socket6.c'; fi`
426 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping-socket6.Tpo $(DEPDIR)/fping-socket6.Po
427 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket6.c' object='fping-socket6.obj' libtool=no @AMDEPBACKSLASH@
428 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
429 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping_CFLAGS) $(CFLAGS) -c -o fping-socket6.obj `if test -f 'socket6.c'; then $(CYGPATH_W) 'socket6.c'; else $(CYGPATH_W) '$(srcdir)/socket6.c'; fi`
390 fping6-fping.o: fping.c
391 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-fping.o -MD -MP -MF $(DEPDIR)/fping6-fping.Tpo -c -o fping6-fping.o `test -f 'fping.c' || echo '$(srcdir)/'`fping.c
392 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-fping.Tpo $(DEPDIR)/fping6-fping.Po
393 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fping.c' object='fping6-fping.o' libtool=no @AMDEPBACKSLASH@
394 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
395 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-fping.o `test -f 'fping.c' || echo '$(srcdir)/'`fping.c
396
397 fping6-fping.obj: fping.c
398 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-fping.obj -MD -MP -MF $(DEPDIR)/fping6-fping.Tpo -c -o fping6-fping.obj `if test -f 'fping.c'; then $(CYGPATH_W) 'fping.c'; else $(CYGPATH_W) '$(srcdir)/fping.c'; fi`
399 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-fping.Tpo $(DEPDIR)/fping6-fping.Po
400 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fping.c' object='fping6-fping.obj' libtool=no @AMDEPBACKSLASH@
401 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
402 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-fping.obj `if test -f 'fping.c'; then $(CYGPATH_W) 'fping.c'; else $(CYGPATH_W) '$(srcdir)/fping.c'; fi`
403
404 fping6-seqmap.o: seqmap.c
405 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-seqmap.o -MD -MP -MF $(DEPDIR)/fping6-seqmap.Tpo -c -o fping6-seqmap.o `test -f 'seqmap.c' || echo '$(srcdir)/'`seqmap.c
406 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-seqmap.Tpo $(DEPDIR)/fping6-seqmap.Po
407 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='seqmap.c' object='fping6-seqmap.o' libtool=no @AMDEPBACKSLASH@
408 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
409 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-seqmap.o `test -f 'seqmap.c' || echo '$(srcdir)/'`seqmap.c
410
411 fping6-seqmap.obj: seqmap.c
412 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-seqmap.obj -MD -MP -MF $(DEPDIR)/fping6-seqmap.Tpo -c -o fping6-seqmap.obj `if test -f 'seqmap.c'; then $(CYGPATH_W) 'seqmap.c'; else $(CYGPATH_W) '$(srcdir)/seqmap.c'; fi`
413 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-seqmap.Tpo $(DEPDIR)/fping6-seqmap.Po
414 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='seqmap.c' object='fping6-seqmap.obj' libtool=no @AMDEPBACKSLASH@
415 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
416 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-seqmap.obj `if test -f 'seqmap.c'; then $(CYGPATH_W) 'seqmap.c'; else $(CYGPATH_W) '$(srcdir)/seqmap.c'; fi`
417
418 fping6-socket.o: socket.c
419 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-socket.o -MD -MP -MF $(DEPDIR)/fping6-socket.Tpo -c -o fping6-socket.o `test -f 'socket.c' || echo '$(srcdir)/'`socket.c
420 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-socket.Tpo $(DEPDIR)/fping6-socket.Po
421 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket.c' object='fping6-socket.o' libtool=no @AMDEPBACKSLASH@
422 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
423 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-socket.o `test -f 'socket.c' || echo '$(srcdir)/'`socket.c
424
425 fping6-socket.obj: socket.c
426 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-socket.obj -MD -MP -MF $(DEPDIR)/fping6-socket.Tpo -c -o fping6-socket.obj `if test -f 'socket.c'; then $(CYGPATH_W) 'socket.c'; else $(CYGPATH_W) '$(srcdir)/socket.c'; fi`
427 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-socket.Tpo $(DEPDIR)/fping6-socket.Po
428 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket.c' object='fping6-socket.obj' libtool=no @AMDEPBACKSLASH@
429 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
430 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-socket.obj `if test -f 'socket.c'; then $(CYGPATH_W) 'socket.c'; else $(CYGPATH_W) '$(srcdir)/socket.c'; fi`
431
432 fping6-socket6.o: socket6.c
433 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-socket6.o -MD -MP -MF $(DEPDIR)/fping6-socket6.Tpo -c -o fping6-socket6.o `test -f 'socket6.c' || echo '$(srcdir)/'`socket6.c
434 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-socket6.Tpo $(DEPDIR)/fping6-socket6.Po
435 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket6.c' object='fping6-socket6.o' libtool=no @AMDEPBACKSLASH@
436 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
437 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-socket6.o `test -f 'socket6.c' || echo '$(srcdir)/'`socket6.c
438
439 fping6-socket6.obj: socket6.c
440 @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -MT fping6-socket6.obj -MD -MP -MF $(DEPDIR)/fping6-socket6.Tpo -c -o fping6-socket6.obj `if test -f 'socket6.c'; then $(CYGPATH_W) 'socket6.c'; else $(CYGPATH_W) '$(srcdir)/socket6.c'; fi`
441 @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/fping6-socket6.Tpo $(DEPDIR)/fping6-socket6.Po
442 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='socket6.c' object='fping6-socket6.obj' libtool=no @AMDEPBACKSLASH@
443 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
444 @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(fping6_CFLAGS) $(CFLAGS) -c -o fping6-socket6.obj `if test -f 'socket6.c'; then $(CYGPATH_W) 'socket6.c'; else $(CYGPATH_W) '$(srcdir)/socket6.c'; fi`
430445
431446 ID: $(am__tagged_files)
432447 $(am__define_uniq_tagged_files); mkid -fID $$unique
547562 maintainer-clean-generic:
548563 @echo "This command is intended for maintainers to use"
549564 @echo "it deletes files that may require special tools to rebuild."
550 @IPV6_FALSE@install-exec-hook:
551565 clean: clean-am
552566
553567 clean-am: clean-generic clean-sbinPROGRAMS mostlyclean-am
577591 install-dvi-am:
578592
579593 install-exec-am: install-sbinPROGRAMS
580 @$(NORMAL_INSTALL)
581 $(MAKE) $(AM_MAKEFLAGS) install-exec-hook
594
582595 install-html: install-html-am
583596
584597 install-html-am:
618631
619632 uninstall-am: uninstall-sbinPROGRAMS
620633
621 .MAKE: install-am install-exec-am install-strip
634 .MAKE: install-am install-strip
622635
623636 .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
624637 clean-sbinPROGRAMS cscopelist-am ctags ctags-am distclean \
625638 distclean-compile distclean-generic distclean-tags distdir dvi \
626639 dvi-am html html-am info info-am install install-am \
627640 install-data install-data-am install-dvi install-dvi-am \
628 install-exec install-exec-am install-exec-hook install-html \
629 install-html-am install-info install-info-am install-man \
630 install-pdf install-pdf-am install-ps install-ps-am \
631 install-sbinPROGRAMS install-strip installcheck \
632 installcheck-am installdirs maintainer-clean \
633 maintainer-clean-generic mostlyclean mostlyclean-compile \
634 mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \
635 uninstall-am uninstall-sbinPROGRAMS
636
637 @IPV6_TRUE@install-exec-hook:
638 @IPV6_TRUE@ ln -s fping$(EXEEXT) $(DESTDIR)$(sbindir)/fping6
641 install-exec install-exec-am install-html install-html-am \
642 install-info install-info-am install-man install-pdf \
643 install-pdf-am install-ps install-ps-am install-sbinPROGRAMS \
644 install-strip installcheck installcheck-am installdirs \
645 maintainer-clean maintainer-clean-generic mostlyclean \
646 mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
647 tags tags-am uninstall uninstall-am uninstall-sbinPROGRAMS
648
639649
640650 # Tell versions [3.59,3.63) of GNU make to not export all variables.
641651 # Otherwise a system limit (for SysV at least) may be exceeded.
+1227
-1469
src/fping.c less more
3030 */
3131
3232 #ifdef __cplusplus
33 extern "C"
34 {
33 extern "C" {
3534 #endif /* __cplusplus */
3635
3736 #include "fping.h"
3938
4039 /*** autoconf includes ***/
4140
42
43 #include <stdio.h>
4441 #include <errno.h>
45 #include <time.h>
4642 #include <signal.h>
4743 #include <stdarg.h>
44 #include <stdio.h>
45 #include <time.h>
4846
4947 #include "config.h"
5048 #include "seqmap.h"
5755 #include <stdlib.h>
5856 #endif /* HAVE_STDLIB_H */
5957
58 #include <stddef.h>
6059 #include <string.h>
61 #include <stddef.h>
62
60
61 #include <sys/socket.h>
62 #include <sys/time.h>
6363 #include <sys/types.h>
64 #include <sys/time.h>
65 #include <sys/socket.h>
6664
6765 #if HAVE_SYS_FILE_H
6866 #include <sys/file.h>
7775 #include <netinet/ip_icmp.h>
7876
7977 #include <arpa/inet.h>
78 #include <ctype.h>
8079 #include <netdb.h>
81 #include <ctype.h>
82
80
81 /* RS6000 hasn't getopt.h */
82 #ifdef HAVE_GETOPT_H
8383 #include <getopt.h>
84
84 #endif /* HAVE_GETOPT_H */
85
86 /* RS6000 has sys/select.h */
87 #ifdef HAVE_SYS_SELECT_H
8588 #include <sys/select.h>
89 #endif /* HAVE_SYS_SELECT_H */
8690
8791 /*** externals ***/
8892
89 extern char *optarg;
90 extern int optind,opterr;
93 extern char* optarg;
94 extern int optind, opterr;
9195 #ifndef h_errno
9296 extern int h_errno;
9397 #endif
98102
99103 /*** Constants ***/
100104
101 #define EMAIL "david@schweikert.ch"
105 #define EMAIL "david@schweikert.ch"
102106
103107 /*** Ping packet defines ***/
104108
105 #define MAX_IP_PACKET 65536 /* (theoretical) max IP packet size */
106 #define SIZE_IP_HDR 40
107 #define SIZE_ICMP_HDR 8 /* from ip_icmp.h */
108 #define MAX_PING_DATA ( MAX_IP_PACKET - SIZE_IP_HDR - SIZE_ICMP_HDR )
109
110 #define MAX_GENERATE 100000 /* maximum number of hosts that -g can generate */
109 #define MAX_IP_PACKET 65536 /* (theoretical) max IP packet size */
110 #define SIZE_IP_HDR 40
111 #ifndef IPV6
112 #define SIZE_ICMP_HDR ICMP_MINLEN /* from ip_icmp.h */
113 #else
114 #define SIZE_ICMP_HDR sizeof(FPING_ICMPHDR)
115 #endif
116 #define MAX_PING_DATA (MAX_IP_PACKET - SIZE_IP_HDR - SIZE_ICMP_HDR)
117
118 #define MAX_GENERATE 100000 /* maximum number of hosts that -g can generate */
111119
112120 /* sized so as to be like traditional ping */
113 #define DEFAULT_PING_DATA_SIZE 56
121 #define DEFAULT_PING_DATA_SIZE 56
114122
115123 /* maxima and minima */
116 #define MIN_INTERVAL 1 /* in millisec */
117 #define MIN_PERHOST_INTERVAL 10 /* in millisec */
124 #define MIN_INTERVAL 1 /* in millisec */
125 #define MIN_PERHOST_INTERVAL 10 /* in millisec */
118126
119127 /* response time array flags */
120 #define RESP_WAITING -1
121 #define RESP_UNUSED -2
122 #define RESP_ERROR -3
128 #define RESP_WAITING -1
129 #define RESP_UNUSED -2
130 #define RESP_ERROR -3
123131
124132 /* debugging flags */
125 #if defined( DEBUG ) || defined( _DEBUG )
126 #define DBG_TRACE 1
127 #define DBG_SENT_TIMES 2
128 #define DBG_RANDOM_LOSE_FEW 4
129 #define DBG_RANDOM_LOSE_MANY 8
130 #define DBG_PRINT_PER_SYSTEM 16
131 #define DBG_REPORT_ALL_RTTS 32
133 #if defined(DEBUG) || defined(_DEBUG)
134 #define DBG_TRACE 1
135 #define DBG_SENT_TIMES 2
136 #define DBG_RANDOM_LOSE_FEW 4
137 #define DBG_RANDOM_LOSE_MANY 8
138 #define DBG_PRINT_PER_SYSTEM 16
139 #define DBG_REPORT_ALL_RTTS 32
132140 #endif /* DEBUG || _DEBUG */
133141
134142 /* Long names for ICMP packet types */
135143 #define ICMP_TYPE_STR_MAX 18
136 char *icmp_type_str[19] =
137 {
138 "ICMP Echo Reply", /* 0 */
144 char* icmp_type_str[19] = {
145 "ICMP Echo Reply", /* 0 */
139146 "",
140147 "",
141 "ICMP Unreachable", /* 3 */
142 "ICMP Source Quench", /* 4 */
143 "ICMP Redirect", /* 5 */
148 "ICMP Unreachable", /* 3 */
149 "ICMP Source Quench", /* 4 */
150 "ICMP Redirect", /* 5 */
144151 "",
145152 "",
146 "ICMP Echo", /* 8 */
153 "ICMP Echo", /* 8 */
147154 "",
148155 "",
149 "ICMP Time Exceeded", /* 11 */
150 "ICMP Parameter Problem", /* 12 */
151 "ICMP Timestamp Request", /* 13 */
152 "ICMP Timestamp Reply", /* 14 */
156 "ICMP Time Exceeded", /* 11 */
157 "ICMP Parameter Problem", /* 12 */
158 "ICMP Timestamp Request", /* 13 */
159 "ICMP Timestamp Reply", /* 14 */
153160 "ICMP Information Request", /* 15 */
154 "ICMP Information Reply", /* 16 */
155 "ICMP Mask Request", /* 17 */
156 "ICMP Mask Reply" /* 18 */
161 "ICMP Information Reply", /* 16 */
162 "ICMP Mask Request", /* 17 */
163 "ICMP Mask Reply" /* 18 */
157164 };
158165
159 char *icmp_unreach_str[16] =
160 {
161 "ICMP Network Unreachable", /* 0 */
162 "ICMP Host Unreachable", /* 1 */
163 "ICMP Protocol Unreachable", /* 2 */
164 "ICMP Port Unreachable", /* 3 */
165 "ICMP Unreachable (Fragmentation Needed)", /* 4 */
166 "ICMP Unreachable (Source Route Failed)", /* 5 */
167 "ICMP Unreachable (Destination Network Unknown)", /* 6 */
168 "ICMP Unreachable (Destination Host Unknown)", /* 7 */
169 "ICMP Unreachable (Source Host Isolated)", /* 8 */
170 "ICMP Unreachable (Communication with Network Prohibited)", /* 9 */
171 "ICMP Unreachable (Communication with Host Prohibited)", /* 10 */
172 "ICMP Unreachable (Network Unreachable For Type Of Service)", /* 11 */
173 "ICMP Unreachable (Host Unreachable For Type Of Service)", /* 12 */
166 char* icmp_unreach_str[16] = {
167 "ICMP Network Unreachable", /* 0 */
168 "ICMP Host Unreachable", /* 1 */
169 "ICMP Protocol Unreachable", /* 2 */
170 "ICMP Port Unreachable", /* 3 */
171 "ICMP Unreachable (Fragmentation Needed)", /* 4 */
172 "ICMP Unreachable (Source Route Failed)", /* 5 */
173 "ICMP Unreachable (Destination Network Unknown)", /* 6 */
174 "ICMP Unreachable (Destination Host Unknown)", /* 7 */
175 "ICMP Unreachable (Source Host Isolated)", /* 8 */
176 "ICMP Unreachable (Communication with Network Prohibited)", /* 9 */
177 "ICMP Unreachable (Communication with Host Prohibited)", /* 10 */
178 "ICMP Unreachable (Network Unreachable For Type Of Service)", /* 11 */
179 "ICMP Unreachable (Host Unreachable For Type Of Service)", /* 12 */
174180 "ICMP Unreachable (Communication Administratively Prohibited)", /* 13 */
175 "ICMP Unreachable (Host Precedence Violation)", /* 14 */
176 "ICMP Unreachable (Precedence cutoff in effect)" /* 15 */
181 "ICMP Unreachable (Host Precedence Violation)", /* 14 */
182 "ICMP Unreachable (Precedence cutoff in effect)" /* 15 */
177183 };
178184
179 #define ICMP_UNREACH_MAXTYPE 15
185 #define ICMP_UNREACH_MAXTYPE 15
180186
181187 /* entry used to keep track of each host we are pinging */
182188
183 #define EV_TYPE_PING 1
184 #define EV_TYPE_TIMEOUT 2
185
186 typedef struct host_entry
187 {
188 /* Each host can have an event attached: either the next time that a ping needs
189 #define EV_TYPE_PING 1
190 #define EV_TYPE_TIMEOUT 2
191
192 typedef struct host_entry {
193 /* Each host can have an event attached: either the next time that a ping needs
189194 * to be sent, or the timeout, if the last ping was sent */
190 struct host_entry *ev_prev; /* double linked list for the event-queue */
191 struct host_entry *ev_next; /* double linked list for the event-queue */
192 struct timeval ev_time; /* time, after which this event should happen */
193 int ev_type; /* event type */
194
195 int i; /* index into array */
196 char *name; /* name as given by user */
197 char *host; /* text description of host */
198 char *pad; /* pad to align print names */
199 struct sockaddr_storage saddr; /* internet address */
200 socklen_t saddr_len;
201 int timeout; /* time to wait for response */
202 unsigned char running; /* unset when through sending */
203 unsigned char waiting; /* waiting for response */
204 struct timeval last_send_time; /* time of last packet sent */
205 int num_sent; /* number of ping packets sent */
206 int num_recv; /* number of pings received (duplicates ignored) */
207 int num_recv_total; /* number of pings received, including duplicates */
208 int max_reply; /* longest response time */
209 int min_reply; /* shortest response time */
210 int total_time; /* sum of response times */
211 /* _i -> splits (reset on every report interval) */
212 int num_sent_i; /* number of ping packets sent */
213 int num_recv_i; /* number of pings received */
214 int max_reply_i; /* longest response time */
215 int min_reply_i; /* shortest response time */
216 int total_time_i; /* sum of response times */
217 int discard_next_recv_i;/* don't count next received reply for split reporting */
218 int *resp_times; /* individual response times */
219 #if defined( DEBUG ) || defined( _DEBUG )
220 int *sent_times; /* per-sent-ping timestamp */
195 struct host_entry* ev_prev; /* double linked list for the event-queue */
196 struct host_entry* ev_next; /* double linked list for the event-queue */
197 struct timeval ev_time; /* time, after which this event should happen */
198 int ev_type; /* event type */
199
200 int i; /* index into array */
201 char* name; /* name as given by user */
202 char* host; /* text description of host */
203 char* pad; /* pad to align print names */
204 struct sockaddr_storage saddr; /* internet address */
205 socklen_t saddr_len;
206 int timeout; /* time to wait for response */
207 unsigned char running; /* unset when through sending */
208 unsigned char waiting; /* waiting for response */
209 struct timeval last_send_time; /* time of last packet sent */
210 int num_sent; /* number of ping packets sent */
211 int num_recv; /* number of pings received (duplicates ignored) */
212 int num_recv_total; /* number of pings received, including duplicates */
213 int max_reply; /* longest response time */
214 int min_reply; /* shortest response time */
215 int total_time; /* sum of response times */
216 /* _i -> splits (reset on every report interval) */
217 int num_sent_i; /* number of ping packets sent */
218 int num_recv_i; /* number of pings received */
219 int max_reply_i; /* longest response time */
220 int min_reply_i; /* shortest response time */
221 int total_time_i; /* sum of response times */
222 int discard_next_recv_i; /* don't count next received reply for split reporting */
223 int* resp_times; /* individual response times */
224 #if defined(DEBUG) || defined(_DEBUG)
225 int* sent_times; /* per-sent-ping timestamp */
221226 #endif /* DEBUG || _DEBUG */
222227 } HOST_ENTRY;
223228
224229 /*** globals ***/
225230
226 HOST_ENTRY **table = NULL; /* array of pointers to items in the list */
231 HOST_ENTRY** table = NULL; /* array of pointers to items in the list */
227232
228233 /* event queue (ev): This, together with the ev_next / ev_prev elements are used
229234 * to track the next event happening for each host. This can be either a new ping
230235 * that needs to be sent or a timeout */
231 HOST_ENTRY *ev_first;
232 HOST_ENTRY *ev_last;
233
234 char *prog;
235 int ident; /* our pid */
236 int socket4 = 0;
237 #ifndef IPV6
238 int hints_ai_family = AF_INET;
239 #else
240 int socket6 = 0;
241 int hints_ai_family = AF_UNSPEC;
242 #endif
243
236 HOST_ENTRY* ev_first;
237 HOST_ENTRY* ev_last;
238
239 char* prog;
240 int ident; /* our pid */
241 int s; /* socket */
244242 unsigned int debugging = 0;
245243
246244 /* times get *100 because all times are calculated in 10 usec units, not ms */
254252 unsigned int trials;
255253 unsigned int report_interval = 0;
256254 unsigned int ttl = 0;
257 int src_addr_set = 0;
255 int src_addr_present = 0;
256 #ifndef IPV6
258257 struct in_addr src_addr;
259 #ifdef IPV6
260 int src_addr6_set = 0;
261 struct in6_addr src_addr6;
258 #else
259 struct in6_addr src_addr;
262260 #endif
263261
264262 /* global stats */
267265 int total_replies = 0;
268266 double sum_replies = 0;
269267 int max_hostname_len = 0;
270 int num_jobs = 0; /* number of hosts still to do */
271 int num_hosts; /* total number of hosts */
272 int num_alive = 0, /* total number alive */
273 num_unreachable = 0, /* total number unreachable */
274 num_noaddress = 0; /* total number of addresses not found */
275 int num_timeout = 0, /* number of times select timed out */
276 num_pingsent = 0, /* total pings sent */
277 num_pingreceived = 0, /* total pings received */
278 num_othericmprcvd = 0; /* total non-echo-reply ICMP received */
279
280 struct timeval current_time; /* current time (pseudo) */
268 int num_jobs = 0; /* number of hosts still to do */
269 int num_hosts; /* total number of hosts */
270 int num_alive = 0, /* total number alive */
271 num_unreachable = 0, /* total number unreachable */
272 num_noaddress = 0; /* total number of addresses not found */
273 int num_timeout = 0, /* number of times select timed out */
274 num_pingsent = 0, /* total pings sent */
275 num_pingreceived = 0, /* total pings received */
276 num_othericmprcvd = 0; /* total non-echo-reply ICMP received */
277
278 struct timeval current_time; /* current time (pseudo) */
281279 struct timeval start_time;
282280 struct timeval end_time;
283 struct timeval last_send_time; /* time last ping was sent */
284 struct timeval next_report_time; /* time next -Q report is expected */
281 struct timeval last_send_time; /* time last ping was sent */
282 struct timeval next_report_time; /* time next -Q report is expected */
285283 struct timezone tz;
286284
287285 /* switches */
288 int generate_flag = 0; /* flag for IP list generation */
286 int generate_flag = 0; /* flag for IP list generation */
289287 int verbose_flag, quiet_flag, stats_flag, unreachable_flag, alive_flag;
290288 int elapsed_flag, version_flag, count_flag, loop_flag, netdata_flag;
291289 int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag;
293291 int outage_flag = 0;
294292 int timestamp_flag = 0;
295293 int random_data_flag = 0;
296 #if defined( DEBUG ) || defined( _DEBUG )
294 #if defined(DEBUG) || defined(_DEBUG)
297295 int randomly_lose_flag, sent_times_flag, trace_flag, print_per_system_flag;
298296 int lose_factor;
299297 #endif /* DEBUG || _DEBUG */
300298
301 char *filename = NULL; /* file containing hosts to ping */
299 char* filename = NULL; /* file containing hosts to ping */
302300
303301 /*** forward declarations ***/
304302
305 void add_name( char *name );
306 void add_addr( char *name, char *host, struct sockaddr *ipaddr, socklen_t ipaddr_len);
307 char *na_cat( char *name, struct in_addr ipaddr );
308 void crash_and_burn( char *message );
309 void errno_crash_and_burn( char *message );
310 char *get_host_by_address( struct in_addr in );
311 void remove_job( HOST_ENTRY *h );
312 int send_ping( HOST_ENTRY *h );
313 long timeval_diff( struct timeval *a, struct timeval *b );
314 void timeval_add(struct timeval *a, long t_10u);
315 void usage( int );
316 int wait_for_reply( long );
317 void print_per_system_stats( void );
318 void print_per_system_splits( void );
319 void print_netdata( void );
320 void print_global_stats( void );
303 void add_name(char* name);
304 void add_addr(char* name, char* host, struct sockaddr* ipaddr, socklen_t ipaddr_len);
305 char* na_cat(char* name, struct in_addr ipaddr);
306 void crash_and_burn(char* message);
307 void errno_crash_and_burn(char* message);
308 char* get_host_by_address(struct in_addr in);
309 int recvfrom_wto(int s, char* buf, int len, struct sockaddr* saddr, socklen_t* saddr_len, long timo);
310 void remove_job(HOST_ENTRY* h);
311 int send_ping(int s, HOST_ENTRY* h);
312 long timeval_diff(struct timeval* a, struct timeval* b);
313 void timeval_add(struct timeval* a, long t_10u);
314 void usage(int);
315 int wait_for_reply(long);
316 void print_per_system_stats(void);
317 void print_per_system_splits(void);
318 void print_netdata(void);
319 void print_global_stats(void);
321320 void main_loop();
322321 void finish();
323 char *sprint_tm( int t );
324 void ev_enqueue(HOST_ENTRY *h);
325 HOST_ENTRY *ev_dequeue();
326 void ev_remove(HOST_ENTRY *h);
327 void add_cidr(char *);
328 void add_range(char *, char *);
329 void print_warning(char *fmt, ...);
330 int addr_cmp(struct sockaddr *a, struct sockaddr *b);
322 int handle_random_icmp(FPING_ICMPHDR* p, struct sockaddr* addr, socklen_t addr_len);
323 char* sprint_tm(int t);
324 void ev_enqueue(HOST_ENTRY* h);
325 HOST_ENTRY* ev_dequeue();
326 void ev_remove(HOST_ENTRY* h);
327 void add_cidr(char*);
328 void add_range(char*, char*);
329 void print_warning(char* fmt, ...);
330 int addr_cmp(struct sockaddr* a, struct sockaddr* b);
331331
332332 /*** function definitions ***/
333333
345345
346346 ************************************************************/
347347
348 int main( int argc, char **argv )
348 int main(int argc, char** argv)
349349 {
350350 int c, i, n;
351 char *buf;
351 char* buf;
352352 uid_t uid;
353353 int tos = 0;
354 HOST_ENTRY *cursor;
354 HOST_ENTRY* cursor;
355355
356356 prog = argv[0];
357357
358 socket4 = open_ping_socket_ipv4(ping_data_size);
359 #ifdef IPV6
360 socket6 = open_ping_socket_ipv6(ping_data_size);
361 #endif
362
363 if((uid = getuid())) {
358 s = open_ping_socket(ping_data_size);
359
360 if ((uid = getuid())) {
364361 /* drop privileges */
365 if(setuid( getuid() ) == -1)
362 if (setuid(getuid()) == -1)
366363 perror("cannot setuid");
367364 }
368365
373370
374371 /* get command line options */
375372
376 while( ( c = getopt( argc, argv, "46ADMNRadeghlmnoqsuvzB:C:H:I:O:Q:S:T:b:c:f:i:p:r:t:" ) ) != EOF )
377 {
378 switch( c )
373 while ((c = getopt(argc, argv, "ADMNRadeghlmnoqsuvzB:C:H:I:O:Q:S:T:b:c:f:i:p:r:t:")) != EOF) {
374 switch (c) {
375 case 'M':
376 #ifdef IP_MTU_DISCOVER
379377 {
380 case '4':
381 if(hints_ai_family != AF_UNSPEC) {
382 fprintf(stderr, "%s: can't specify both -4 and -6\n", prog);
383 exit(1);
384 }
385 hints_ai_family = AF_INET;
386 break;
387 case '6':
388 #ifdef IPV6
389 if(hints_ai_family != AF_UNSPEC) {
390 fprintf(stderr, "%s: can't specify both -4 and -6\n", prog);
391 exit(1);
392 }
393 hints_ai_family = AF_INET6;
378 int val = IP_PMTUDISC_DO;
379 #ifndef IPV6
380 if (setsockopt(s, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val))) {
394381 #else
395 fprintf(stderr, "%s: IPv6 not supported by this binary\n", prog);
382 if (setsockopt(s, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &val, sizeof(val))) {
383 #endif
384 perror("setsockopt IP_MTU_DISCOVER");
385 }
386 }
387 #else
388 fprintf(stderr, "-M option not supported on this platform\n");
396389 exit(1);
397390 #endif
398 break;
399 case 'M':
400 #ifdef IP_MTU_DISCOVER
401 if(socket4) {
402 int val = IP_PMTUDISC_DO;
403 if (setsockopt(socket4, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val))) {
404 perror("setsockopt IP_MTU_DISCOVER");
405 }
406 }
407 #ifdef IPV6
408 if(socket6) {
409 int val = IPV6_PMTUDISC_DO;
410 if (setsockopt(socket6, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &val, sizeof(val))) {
411 perror("setsockopt IPV6_MTU_DISCOVER");
412 }
413 }
414 #endif
415 #else
416 fprintf(stderr, "%s, -M option not supported on this platform\n", prog);
417 exit(1);
418 #endif
419 break;
391 break;
420392
421393 case 't':
422 if( !( timeout = ( unsigned int )atoi( optarg ) * 100 ) )
394 if (!(timeout = (unsigned int)atoi(optarg) * 100))
423395 usage(1);
424396
425397 break;
426398
427399 case 'r':
428 if (!sscanf(optarg,"%u",&retry))
400 if (!sscanf(optarg, "%u", &retry))
429401 usage(1);
430402 break;
431403
432404 case 'i':
433 if (!sscanf(optarg,"%u",&interval))
405 if (!sscanf(optarg, "%u", &interval))
434406 usage(1);
435407 interval *= 100;
436408 break;
437409
438410 case 'p':
439 if( !( perhost_interval = ( unsigned int )atoi( optarg ) * 100 ) )
411 if (!(perhost_interval = (unsigned int)atoi(optarg) * 100))
440412 usage(1);
441413
442414 break;
443415
444416 case 'c':
445 if( !( count = ( unsigned int )atoi( optarg ) ) )
417 if (!(count = (unsigned int)atoi(optarg)))
446418 usage(1);
447419
448420 count_flag = 1;
449421 break;
450422
451423 case 'C':
452 if( !( count = ( unsigned int )atoi( optarg ) ) )
424 if (!(count = (unsigned int)atoi(optarg)))
453425 usage(1);
454426
455427 count_flag = 1;
457429 break;
458430
459431 case 'b':
460 if (!sscanf(optarg,"%u",&ping_data_size))
432 if (!sscanf(optarg, "%u", &ping_data_size))
461433 usage(1);
462434
463435 break;
474446 case 'Q':
475447 verbose_flag = 0;
476448 quiet_flag = 1;
477 if( !( report_interval = ( unsigned int )atoi( optarg ) * 100000 ) )
449 if (!(report_interval = (unsigned int)atoi(optarg) * 100000))
478450 usage(1);
479451
480452 break;
501473 break;
502474
503475 case 'B':
504 if( !( backoff = atof( optarg ) ) )
476 if (!(backoff = atof(optarg)))
505477 usage(1);
506478
507479 break;
532504 break;
533505
534506 case 'H':
535 if( !( ttl = ( u_int )atoi( optarg ) ))
507 if (!(ttl = (u_int)atoi(optarg)))
536508 usage(1);
537509 break;
538510
539 #if defined( DEBUG ) || defined( _DEBUG )
511 #if defined(DEBUG) || defined(_DEBUG)
540512 case 'z':
541 if( ! ( debugging = ( unsigned int )atoi( optarg ) ) )
513 if (!(debugging = (unsigned int)atoi(optarg)))
542514 usage(1);
543515
544516 break;
545517 #endif /* DEBUG || _DEBUG */
546518
547519 case 'v':
548 printf( "%s: Version %s\n", argv[0], VERSION);
549 printf( "%s: comments to %s\n", argv[0], EMAIL );
550 exit( 0 );
520 printf("%s: Version %s\n", argv[0], VERSION);
521 printf("%s: comments to %s\n", argv[0], EMAIL);
522 exit(0);
551523
552524 case 'f':
553525 filename = optarg;
560532 break;
561533
562534 case 'S':
563 if(inet_pton(AF_INET, optarg, &src_addr))
564 {
565 src_addr_set = 1;
566 break;
567 }
568 #ifdef IPV6
569 if(inet_pton(AF_INET6, optarg, &src_addr6))
570 {
571 src_addr6_set = 1;
572 break;
573 }
535 #ifndef IPV6
536 if (!inet_pton(AF_INET, optarg, &src_addr))
537 #else
538 if (!inet_pton(AF_INET6, optarg, &src_addr))
574539 #endif
575 usage(1);
540 usage(1);
541 src_addr_present = 1;
576542 break;
577543
578544 case 'I':
579545 #ifdef SO_BINDTODEVICE
580 if(socket4) {
581 if (setsockopt(socket4, SOL_SOCKET, SO_BINDTODEVICE, optarg, strlen(optarg))) {
582 perror("binding to specific interface (SO_BINTODEVICE)");
583 }
584 }
585 #ifdef IPV6
586 if(socket6) {
587 if (setsockopt(socket6, SOL_SOCKET, SO_BINDTODEVICE, optarg, strlen(optarg))) {
588 perror("binding to specific interface (SO_BINTODEVICE), IPV6");
589 }
590 }
591 #endif
546 if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, optarg, strlen(optarg))) {
547 perror("binding to specific interface (SO_BINTODEVICE)");
548 }
592549 #else
593 printf( "%s: cant bind to a particular net interface since SO_BINDTODEVICE is not supported on your os.\n", argv[0] );
594 exit(3);;
550 printf("%s: cant bind to a particular net interface since SO_BINDTODEVICE is not supported on your os.\n", argv[0]);
551 exit(3);
552 ;
595553 #endif
596554 break;
597555
600558 break;
601559
602560 case 'O':
603 if (sscanf(optarg,"%i",&tos)){
604 if(socket4) {
605 if ( setsockopt(socket4, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) {
606 perror("setting type of service octet IP_TOS");
607 }
561 if (sscanf(optarg, "%i", &tos)) {
562 #ifndef IPV6
563 if (setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) {
564 #else
565 if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos))) {
566 #endif
567 perror("setting type of service octet IP_TOS");
608568 }
609 #ifdef IPV6
610 if(socket6) {
611 if ( setsockopt(socket6, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos))) {
612 perror("setting type of service octet IPV6_TCLASS");
613 }
614 }
615 #endif
616 }
617 else {
569 } else {
618570 usage(1);
619571 }
620572 break;
627579 fprintf(stderr, "see 'fping -h' for usage information\n");
628580 exit(1);
629581 break;
630
631 }/* SWITCH */
632 }/* WHILE */
633
634 /* if we are called 'fping6', assume '-6' */
635 if(strstr(argv[0], "fping6")) {
636 hints_ai_family = AF_INET6;
582 }
637583 }
638584
639585 /* validate various option settings */
640586
641587 if (ttl > 255) {
642 fprintf(stderr, "%s: ttl %u out of range\n", prog, ttl);
588 fprintf(stderr, "ttl %u out of range\n", ttl);
643589 exit(1);
644590 }
645591
646 if( unreachable_flag && alive_flag )
647 {
648 fprintf( stderr, "%s: specify only one of a, u\n", prog);
592 if (unreachable_flag && alive_flag) {
593 fprintf(stderr, "%s: specify only one of a, u\n", argv[0]);
649594 exit(1);
650595
651 }/* IF */
652
653 if( count_flag && loop_flag )
654 {
655 fprintf( stderr, "%s: specify only one of c, l\n", prog);
596 }
597
598 if (count_flag && loop_flag) {
599 fprintf(stderr, "%s: specify only one of c, l\n", argv[0]);
656600 exit(1);
657
658 }/* IF */
659
660 if( ( interval < MIN_INTERVAL * 100 ||
661 perhost_interval < MIN_PERHOST_INTERVAL * 100 )
662 && getuid() )
663 {
664 fprintf( stderr, "%s: these options are too risky for mere mortals.\n", prog );
665 fprintf( stderr, "%s: You need -i >= %u and -p >= %u\n",
666 prog, MIN_INTERVAL, MIN_PERHOST_INTERVAL );
601 }
602
603 if ((interval < MIN_INTERVAL * 100 || perhost_interval < MIN_PERHOST_INTERVAL * 100)
604 && getuid()) {
605 fprintf(stderr, "%s: these options are too risky for mere mortals.\n", prog);
606 fprintf(stderr, "%s: You need -i >= %u and -p >= %u\n",
607 prog, MIN_INTERVAL, MIN_PERHOST_INTERVAL);
667608 exit(1);
668 }/* IF */
669
670 if( ping_data_size > MAX_PING_DATA )
671 {
672 fprintf( stderr, "%s: data size %u not valid, must be lower than %u\n",
673 prog, ping_data_size, (unsigned int) MAX_PING_DATA );
609 }
610
611 if (ping_data_size > MAX_PING_DATA) {
612 fprintf(stderr, "%s: data size %u not valid, must be lower than %u\n",
613 prog, ping_data_size, (unsigned int)MAX_PING_DATA);
674614 exit(1);
675
676 }/* IF */
677
678 if( ( backoff > MAX_BACKOFF_FACTOR ) || ( backoff < MIN_BACKOFF_FACTOR ) )
679 {
680 fprintf( stderr, "%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n",
681 prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR );
615 }
616
617 if ((backoff > MAX_BACKOFF_FACTOR) || (backoff < MIN_BACKOFF_FACTOR)) {
618 fprintf(stderr, "%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n",
619 prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR);
682620 exit(1);
683
684 }/* IF */
685
686 if( alive_flag || unreachable_flag )
621 }
622
623 if (alive_flag || unreachable_flag)
687624 verbose_flag = 0;
688625
689 if( count_flag )
690 {
691 if( verbose_flag )
626 if (count_flag) {
627 if (verbose_flag)
692628 per_recv_flag = 1;
693629
694630 alive_flag = unreachable_flag = verbose_flag = 0;
695
696 }/* IF */
697
698 if( loop_flag )
699 {
700 if( !report_interval )
631 }
632
633 if (loop_flag) {
634 if (!report_interval)
701635 per_recv_flag = 1;
702636
703637 alive_flag = unreachable_flag = verbose_flag = 0;
704
705 }/* IF */
706
707
708 trials = ( count > retry + 1 ) ? count : retry + 1;
709
710 #if defined( DEBUG ) || defined( _DEBUG )
711 if( debugging & DBG_TRACE )
638 }
639
640 trials = (count > retry + 1) ? count : retry + 1;
641
642 #if defined(DEBUG) || defined(_DEBUG)
643 if (debugging & DBG_TRACE)
712644 trace_flag = 1;
713645
714 if( ( debugging & DBG_SENT_TIMES ) && !loop_flag )
646 if ((debugging & DBG_SENT_TIMES) && !loop_flag)
715647 sent_times_flag = 1;
716648
717 if( debugging & DBG_RANDOM_LOSE_FEW )
718 {
649 if (debugging & DBG_RANDOM_LOSE_FEW) {
719650 randomly_lose_flag = 1;
720 lose_factor = 1; /* ie, 1/4 */
721
722 }/* IF */
723
724 if( debugging & DBG_RANDOM_LOSE_MANY )
725 {
651 lose_factor = 1; /* ie, 1/4 */
652 }
653
654 if (debugging & DBG_RANDOM_LOSE_MANY) {
726655 randomly_lose_flag = 1;
727 lose_factor = 5; /* ie, 3/4 */
728
729 }/* IF */
730
731 if( debugging & DBG_PRINT_PER_SYSTEM )
656 lose_factor = 5; /* ie, 3/4 */
657 }
658
659 if (debugging & DBG_PRINT_PER_SYSTEM)
732660 print_per_system_flag = 1;
733661
734 if( ( debugging & DBG_REPORT_ALL_RTTS ) && !loop_flag )
662 if ((debugging & DBG_REPORT_ALL_RTTS) && !loop_flag)
735663 report_all_rtts_flag = 1;
736664
737 if( trace_flag )
738 {
739 fprintf( stderr, "%s:\n count: %u, retry: %u, interval: %u\n",
740 prog, count, retry, interval / 10 );
741 fprintf( stderr, " perhost_interval: %u, timeout: %u\n",
742 perhost_interval / 10, timeout / 10 );
743 fprintf( stderr, " ping_data_size = %u, trials = %u\n",
744 ping_data_size, trials );
745
746 if( verbose_flag ) fprintf( stderr, " verbose_flag set\n" );
747 if( multif_flag ) fprintf( stderr, " multif_flag set\n" );
748 if( name_flag ) fprintf( stderr, " name_flag set\n" );
749 if( addr_flag ) fprintf( stderr, " addr_flag set\n" );
750 if( stats_flag ) fprintf( stderr, " stats_flag set\n" );
751 if( unreachable_flag ) fprintf( stderr, " unreachable_flag set\n" );
752 if( alive_flag ) fprintf( stderr, " alive_flag set\n" );
753 if( elapsed_flag ) fprintf( stderr, " elapsed_flag set\n" );
754 if( version_flag ) fprintf( stderr, " version_flag set\n" );
755 if( count_flag ) fprintf( stderr, " count_flag set\n" );
756 if( loop_flag ) fprintf( stderr, " loop_flag set\n" );
757 if( backoff_flag ) fprintf( stderr, " backoff_flag set\n" );
758 if( per_recv_flag ) fprintf( stderr, " per_recv_flag set\n" );
759 if( report_all_rtts_flag ) fprintf( stderr, " report_all_rtts_flag set\n" );
760 if( randomly_lose_flag ) fprintf( stderr, " randomly_lose_flag set\n" );
761 if( sent_times_flag ) fprintf( stderr, " sent_times_flag set\n" );
762 if( print_per_system_flag ) fprintf( stderr, " print_per_system_flag set\n" );
763 if( outage_flag ) fprintf( stderr, " outage_flag set\n" );
764 if( netdata_flag ) fprintf( stderr, " netdata_flag set\n" );
765
766 }/* IF */
665 if (trace_flag) {
666 fprintf(stderr, "%s:\n count: %u, retry: %u, interval: %u\n",
667 prog, count, retry, interval / 10);
668 fprintf(stderr, " perhost_interval: %u, timeout: %u\n",
669 perhost_interval / 10, timeout / 10);
670 fprintf(stderr, " ping_data_size = %u, trials = %u\n",
671 ping_data_size, trials);
672
673 if (verbose_flag)
674 fprintf(stderr, " verbose_flag set\n");
675 if (multif_flag)
676 fprintf(stderr, " multif_flag set\n");
677 if (name_flag)
678 fprintf(stderr, " name_flag set\n");
679 if (addr_flag)
680 fprintf(stderr, " addr_flag set\n");
681 if (stats_flag)
682 fprintf(stderr, " stats_flag set\n");
683 if (unreachable_flag)
684 fprintf(stderr, " unreachable_flag set\n");
685 if (alive_flag)
686 fprintf(stderr, " alive_flag set\n");
687 if (elapsed_flag)
688 fprintf(stderr, " elapsed_flag set\n");
689 if (version_flag)
690 fprintf(stderr, " version_flag set\n");
691 if (count_flag)
692 fprintf(stderr, " count_flag set\n");
693 if (loop_flag)
694 fprintf(stderr, " loop_flag set\n");
695 if (backoff_flag)
696 fprintf(stderr, " backoff_flag set\n");
697 if (per_recv_flag)
698 fprintf(stderr, " per_recv_flag set\n");
699 if (report_all_rtts_flag)
700 fprintf(stderr, " report_all_rtts_flag set\n");
701 if (randomly_lose_flag)
702 fprintf(stderr, " randomly_lose_flag set\n");
703 if (sent_times_flag)
704 fprintf(stderr, " sent_times_flag set\n");
705 if (print_per_system_flag)
706 fprintf(stderr, " print_per_system_flag set\n");
707 if (outage_flag)
708 fprintf(stderr, " outage_flag set\n");
709 if (netdata_flag)
710 fprintf(stderr, " netdata_flag set\n");
711 }
767712 #endif /* DEBUG || _DEBUG */
768713
769714 /* set the TTL, if the -H option was set (otherwise ttl will be = 0) */
770 if(ttl > 0) {
771 if(socket4) {
772 if (setsockopt(socket4, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) {
773 perror("setting time to live");
774 }
775 }
776 #ifdef IPV6
777 if(socket6) {
778 if (setsockopt(socket6, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl))) {
779 perror("setting time to live");
780 }
781 }
715 if (ttl > 0) {
716 #ifndef IPV6
717 if (setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) {
718 #else
719 if (setsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl))) {
782720 #endif
721 perror("setting time to live");
722 }
783723 }
784724
785725 #if HAVE_SO_TIMESTAMP
786726 {
787727 int opt = 1;
788 if(socket4) {
789 if (setsockopt(socket4, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
790 perror("setting SO_TIMESTAMP option");
791 }
792 }
793 #ifdef IPV6
794 if(socket6) {
795 if (setsockopt(socket6, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
796 perror("setting SO_TIMESTAMP option (IPv6)");
797 }
798 }
799 #endif
728 if (setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
729 perror("setting SO_TIMESTAMP option");
730 }
800731 }
801732 #endif
802733
811742 /* file and generate are mutually exclusive */
812743 /* file and command line are mutually exclusive */
813744 /* generate requires command line parameters beyond the switches */
814 if( ( *argv && filename ) || ( filename && generate_flag ) || ( generate_flag && !*argv ) )
745 if ((*argv && filename) || (filename && generate_flag) || (generate_flag && !*argv))
815746 usage(1);
816747
817748 /* if no conditions are specified, then assume input from stdin */
818 if( !*argv && !filename && !generate_flag )
749 if (!*argv && !filename && !generate_flag)
819750 filename = "-";
820751
821 if( *argv && !generate_flag )
822 {
823 while( *argv )
824 {
825 add_name( *argv );
752 if (*argv && !generate_flag) {
753 while (*argv) {
754 add_name(*argv);
826755 ++argv;
827756
828 }/* WHILE */
829 }/* IF */
830 else if( filename )
831 {
832 FILE *ping_file;
757 }
758 }
759 else if (filename) {
760 FILE* ping_file;
833761 char line[132];
834762 char host[132];
835763
836 if( strcmp( filename, "-" ) == 0 )
837 ping_file = fdopen( 0, "r" );
764 if (strcmp(filename, "-") == 0)
765 ping_file = fdopen(0, "r");
838766 else
839 ping_file = fopen( filename, "r" );
840
841 if( !ping_file )
842 errno_crash_and_burn( "fopen" );
843
844
845 while( fgets( line, sizeof(line), ping_file ) )
846 {
847 if( sscanf( line, "%s", host ) != 1 )
767 ping_file = fopen(filename, "r");
768
769 if (!ping_file)
770 errno_crash_and_burn("fopen");
771
772 while (fgets(line, sizeof(line), ping_file)) {
773 if (sscanf(line, "%s", host) != 1)
848774 continue;
849775
850 if( ( !*host ) || ( host[0] == '#' ) ) /* magic to avoid comments */
776 if ((!*host) || (host[0] == '#')) /* magic to avoid comments */
851777 continue;
852778
853779 add_name(host);
854 }/* WHILE */
855
856 fclose( ping_file );
857 }
858 else if( *argv && generate_flag ) {
859 if(argc == 1) {
780 }
781
782 fclose(ping_file);
783 } else if (*argv && generate_flag) {
784 if (argc == 1) {
860785 /* one target: we expect a cidr range (n.n.n.n/m) */
861786 add_cidr(argv[0]);
862 }
863 else if(argc == 2) {
787 } else if (argc == 2) {
864788 add_range(argv[0], argv[1]);
865 }
866 else {
789 } else {
867790 usage(1);
868791 }
869 }
870 else {
792 } else {
871793 usage(1);
872794 }
873795
874 if(!num_hosts) {
796 if (!num_hosts) {
875797 exit(num_noaddress ? 2 : 1);
876798 }
877799
878 #ifndef IPV6
879 if(src_addr_set) {
880 socket_set_src_addr_ipv4(socket4, &src_addr);
881 }
882 #else
883 if(src_addr6_set) {
884 socket_set_src_addr_ipv6(socket6, &src_addr6);
885 }
886 #endif
800 if (src_addr_present) {
801 socket_set_src_addr(s, src_addr);
802 }
887803
888804 /* allocate array to hold outstanding ping requests */
889805
890 table = ( HOST_ENTRY** )malloc( sizeof( HOST_ENTRY* ) * num_hosts );
891 if( !table )
892 crash_and_burn( "Can't malloc array of hosts" );
806 table = (HOST_ENTRY**)malloc(sizeof(HOST_ENTRY*) * num_hosts);
807 if (!table)
808 crash_and_burn("Can't malloc array of hosts");
893809
894810 cursor = ev_first;
895811
896 for( num_jobs = 0; num_jobs < num_hosts; num_jobs++ )
897 {
812 for (num_jobs = 0; num_jobs < num_hosts; num_jobs++) {
898813 table[num_jobs] = cursor;
899814 cursor->i = num_jobs;
900815
901816 /* as long as we're here, put this in so names print out nicely */
902 if( count_flag || loop_flag )
903 {
904 n = max_hostname_len - strlen( cursor->host );
905 buf = ( char* ) malloc( n + 1 );
906 if( !buf )
907 crash_and_burn( "can't malloc host pad" );
908
909 for ( i = 0; i < n; i++ )
817 if (count_flag || loop_flag) {
818 n = max_hostname_len - strlen(cursor->host);
819 buf = (char*)malloc(n + 1);
820 if (!buf)
821 crash_and_burn("can't malloc host pad");
822
823 for (i = 0; i < n; i++)
910824 buf[i] = ' ';
911825
912826 buf[n] = '\0';
913827 cursor->pad = buf;
914828
915 }/* IF */
916
917 cursor=cursor->ev_next;
918
919 }/* FOR */
920
921 init_ping_buffer_ipv4(ping_data_size);
922 #ifdef IPV6
923 init_ping_buffer_ipv6(ping_data_size);
924 #endif
925
926 signal( SIGINT, finish );
927
928 gettimeofday( &start_time, &tz );
829 }
830
831 cursor = cursor->ev_next;
832 }
833
834 init_ping_buffer(ping_data_size);
835
836 signal(SIGINT, finish);
837
838 gettimeofday(&start_time, &tz);
929839 current_time = start_time;
930840
931 if( report_interval ) {
841 if (report_interval) {
932842 next_report_time = start_time;
933843 timeval_add(&next_report_time, report_interval);
934844 }
935845
936846 last_send_time.tv_sec = current_time.tv_sec - 10000;
937847
938 #if defined( DEBUG ) || defined( _DEBUG )
939 if( randomly_lose_flag )
940 srandom( start_time.tv_usec );
848 #if defined(DEBUG) || defined(_DEBUG)
849 if (randomly_lose_flag)
850 srandom(start_time.tv_usec);
941851 #endif /* DEBUG || _DEBUG */
942852
943853 seqmap_init();
948858 finish();
949859
950860 return 0;
951 } /* main() */
952
953 void add_cidr(char *addr)
954 {
955 char *addr_end;
956 char *mask_str;
861 }
862
863 void add_cidr(char* addr)
864 {
865 char* addr_end;
866 char* mask_str;
957867 unsigned long mask;
958868 unsigned long bitmask;
959869 int ret;
960870 struct addrinfo addr_hints;
961 struct addrinfo *addr_res;
871 struct addrinfo* addr_res;
962872 unsigned long net_addr;
963873 unsigned long net_last;
964874
965875 /* Split address from mask */
966876 addr_end = strchr(addr, '/');
967 if(addr_end == NULL) {
877 if (addr_end == NULL) {
968878 usage(1);
969879 }
970880 *addr_end = '\0';
976886 addr_hints.ai_family = AF_UNSPEC;
977887 addr_hints.ai_flags = AI_NUMERICHOST;
978888 ret = getaddrinfo(addr, NULL, &addr_hints, &addr_res);
979 if(ret) {
980 fprintf(stderr, "%s, can't parse address %s: %s\n", prog, addr, gai_strerror(ret));
889 if (ret) {
890 fprintf(stderr, "Error: can't parse address %s: %s\n", addr, gai_strerror(ret));
981891 exit(1);
982892 }
983 if(addr_res->ai_family != AF_INET) {
984 fprintf(stderr, "%s: -g works only with IPv4 addresses\n", prog);
893 if (addr_res->ai_family != AF_INET) {
894 fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
985895 exit(1);
986896 }
987 net_addr = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
897 net_addr = ntohl(((struct sockaddr_in*)addr_res->ai_addr)->sin_addr.s_addr);
988898
989899 /* check mask */
990 if(mask < 1 || mask > 32) {
991 fprintf(stderr, "%s: netmask must be between 1 and 32 (is: %s)\n", prog, mask_str);
900 if (mask < 1 || mask > 32) {
901 fprintf(stderr, "Error: netmask must be between 1 and 32 (is: %s)\n", mask_str);
992902 exit(1);
993903 }
994904
995905 /* convert mask integer from 1 to 32 to a bitmask */
996 bitmask = ((unsigned long) 0xFFFFFFFF) << (32-mask);
906 bitmask = ((unsigned long)0xFFFFFFFF) << (32 - mask);
997907
998908 /* calculate network range */
999909 net_addr &= bitmask;
1000 net_last = net_addr + ((unsigned long) 0x1 << (32-mask)) - 1;
910 net_last = net_addr + ((unsigned long)0x1 << (32 - mask)) - 1;
1001911
1002912 /* exclude network and broadcast address for regular prefixes */
1003913 if (mask < 31) {
1006916 }
1007917
1008918 /* add all hosts in that network (net_addr and net_last inclusive) */
1009 for(; net_addr <= net_last; net_addr++) {
919 for (; net_addr <= net_last; net_addr++) {
1010920 struct in_addr in_addr_tmp;
1011921 char buffer[20];
1012922 in_addr_tmp.s_addr = htonl(net_addr);
1014924 add_name(buffer);
1015925 }
1016926
1017
1018927 freeaddrinfo(addr_res);
1019928 }
1020929
1021 void add_range(char *start, char *end)
930 void add_range(char* start, char* end)
1022931 {
1023932 struct addrinfo addr_hints;
1024 struct addrinfo *addr_res;
933 struct addrinfo* addr_res;
1025934 unsigned long start_long;
1026935 unsigned long end_long;
1027936 int ret;
1031940 addr_hints.ai_family = AF_UNSPEC;
1032941 addr_hints.ai_flags = AI_NUMERICHOST;
1033942 ret = getaddrinfo(start, NULL, &addr_hints, &addr_res);
1034 if(ret) {
1035 fprintf(stderr, "%s: can't parse address %s: %s\n", prog, start, gai_strerror(ret));
943 if (ret) {
944 fprintf(stderr, "Error: can't parse address %s: %s\n", start, gai_strerror(ret));
1036945 exit(1);
1037946 }
1038 if(addr_res->ai_family != AF_INET) {
947 if (addr_res->ai_family != AF_INET) {
1039948 freeaddrinfo(addr_res);
1040 fprintf(stderr, "%s: -g works only with IPv4 addresses\n", prog);
949 fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
1041950 exit(1);
1042951 }
1043 start_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
952 start_long = ntohl(((struct sockaddr_in*)addr_res->ai_addr)->sin_addr.s_addr);
1044953
1045954 /* parse end address (IPv4 only) */
1046955 memset(&addr_hints, 0, sizeof(struct addrinfo));
1047956 addr_hints.ai_family = AF_UNSPEC;
1048957 addr_hints.ai_flags = AI_NUMERICHOST;
1049958 ret = getaddrinfo(end, NULL, &addr_hints, &addr_res);
1050 if(ret) {
1051 fprintf(stderr, "%s: can't parse address %s: %s\n", prog, end, gai_strerror(ret));
959 if (ret) {
960 fprintf(stderr, "Error: can't parse address %s: %s\n", end, gai_strerror(ret));
1052961 exit(1);
1053962 }
1054 if(addr_res->ai_family != AF_INET) {
963 if (addr_res->ai_family != AF_INET) {
1055964 freeaddrinfo(addr_res);
1056 fprintf(stderr, "%s: -g works only with IPv4 addresses\n", prog);
965 fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
1057966 exit(1);
1058967 }
1059968 end_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
1060969 freeaddrinfo(addr_res);
1061970
1062 if(end_long > start_long + MAX_GENERATE) {
1063 fprintf(stderr, "%s: -g parameter generates too many addresses\n", prog);
1064 exit(1);
971 if (end_long > start_long + MAX_GENERATE) {
972 fprintf(stderr, "%s: -g parameter generates too many addresses\n", prog);
973 exit(1);
1065974 }
1066975
1067976 /* generate */
1068 for(; start_long <= end_long; start_long++) {
977 for (; start_long <= end_long; start_long++) {
1069978 struct in_addr in_addr_tmp;
1070979 char buffer[20];
1071980 in_addr_tmp.s_addr = htonl(start_long);
1074983 }
1075984 }
1076985
1077
1078986 void main_loop()
1079987 {
1080988 long lt;
1081989 long wait_time;
1082990 long wait_time_next_report;
1083 HOST_ENTRY *h;
1084
1085 while(ev_first) {
991 HOST_ENTRY* h;
992
993 while (ev_first) {
1086994 /* Any event that can be processed now ? */
1087 if(ev_first->ev_time.tv_sec < current_time.tv_sec ||
1088 (ev_first->ev_time.tv_sec == current_time.tv_sec &&
1089 ev_first->ev_time.tv_usec < current_time.tv_usec))
1090 {
995 if (ev_first->ev_time.tv_sec < current_time.tv_sec || (ev_first->ev_time.tv_sec == current_time.tv_sec && ev_first->ev_time.tv_usec < current_time.tv_usec)) {
1091996 /* Event type: ping */
1092 if(ev_first->ev_type == EV_TYPE_PING) {
997 if (ev_first->ev_type == EV_TYPE_PING) {
1093998 /* Make sure that we don't ping more than once every "interval" */
1094 lt = timeval_diff( &current_time, &last_send_time );
1095 if(lt < interval) goto wait_for_reply;
999 lt = timeval_diff(&current_time, &last_send_time);
1000 if (lt < interval)
1001 goto wait_for_reply;
10961002
10971003 /* Dequeue the event */
10981004 h = ev_dequeue();
10991005
11001006 /* Send the ping */
1101 send_ping(h);
1007 /*printf("Sending ping after %d ms\n", lt/100); */
1008 send_ping(s, h);
11021009
11031010 /* Check what needs to be done next */
1104 if(!loop_flag && !count_flag) {
1011 if (!loop_flag && !count_flag) {
11051012 /* Normal mode: schedule retry */
1106 if(h->waiting < retry + 1) {
1013 if (h->waiting < retry + 1) {
11071014 h->ev_type = EV_TYPE_PING;
11081015 h->ev_time.tv_sec = last_send_time.tv_sec;
11091016 h->ev_time.tv_usec = last_send_time.tv_usec;
11101017 timeval_add(&h->ev_time, h->timeout);
11111018 ev_enqueue(h);
11121019
1113 if(backoff_flag) {
1020 if (backoff_flag) {
11141021 h->timeout *= backoff;
11151022 }
11161023 }
11241031 }
11251032 }
11261033 /* Loop and count mode: schedule next ping */
1127 else if(loop_flag || (count_flag && h->num_sent < count))
1128 {
1034 else if (loop_flag || (count_flag && h->num_sent < count)) {
11291035 h->ev_type = EV_TYPE_PING;
11301036 h->ev_time.tv_sec = last_send_time.tv_sec;
11311037 h->ev_time.tv_usec = last_send_time.tv_usec;
11331039 ev_enqueue(h);
11341040 }
11351041 /* Count mode: schedule timeout after last ping */
1136 else if(count_flag && h->num_sent >= count) {
1042 else if (count_flag && h->num_sent >= count) {
11371043 h->ev_type = EV_TYPE_TIMEOUT;
11381044 h->ev_time.tv_sec = last_send_time.tv_sec;
11391045 h->ev_time.tv_usec = last_send_time.tv_usec;
11421048 }
11431049 }
11441050 /* Event type: timeout */
1145 else if(ev_first->ev_type == EV_TYPE_TIMEOUT) {
1051 else if (ev_first->ev_type == EV_TYPE_TIMEOUT) {
11461052 num_timeout++;
11471053 remove_job(ev_first);
11481054 }
11511057 wait_for_reply:
11521058
11531059 /* When can we expect the next event? */
1154 if(ev_first) {
1155 if(ev_first->ev_time.tv_sec == 0) {
1060 if (ev_first) {
1061 if (ev_first->ev_time.tv_sec == 0) {
11561062 wait_time = 0;
1157 }
1158 else {
1063 } else {
11591064 wait_time = timeval_diff(&ev_first->ev_time, &current_time);
1160 if(wait_time < 0) wait_time = 0;
1161 }
1162 if(ev_first->ev_type == EV_TYPE_PING) {
1065 if (wait_time < 0)
1066 wait_time = 0;
1067 }
1068 if (ev_first->ev_type == EV_TYPE_PING) {
11631069 /* make sure that we wait enough, so that the inter-ping delay is
11641070 * bigger than 'interval' */
1165 if(wait_time < interval) {
1071 if (wait_time < interval) {
11661072 lt = timeval_diff(&current_time, &last_send_time);
1167 if(lt < interval) {
1168 wait_time = interval-lt;
1169 }
1170 else {
1073 if (lt < interval) {
1074 wait_time = interval - lt;
1075 } else {
11711076 wait_time = 0;
11721077 }
11731078 }
11741079 }
11751080
1176 #if defined( DEBUG ) || defined( _DEBUG )
1177 if( trace_flag ) {
1081 #if defined(DEBUG) || defined(_DEBUG)
1082 if (trace_flag) {
11781083 fprintf(stderr, "next event in %d ms (%s)\n", wait_time / 100, ev_first->host);
11791084 }
11801085 #endif
1181 }
1182 else {
1086 } else {
11831087 wait_time = interval;
11841088 }
11851089
11861090 /* Make sure we don't wait too long, in case a report is expected */
1187 if( report_interval && ( loop_flag || count_flag ) ) {
1188 wait_time_next_report = timeval_diff ( &next_report_time, &current_time );
1189 if(wait_time_next_report < wait_time) {
1190 wait_time = wait_time_next_report;
1191 if(wait_time < 0) { wait_time = 0; }
1192 }
1091 if (report_interval && (loop_flag || count_flag)) {
1092 wait_time_next_report = timeval_diff(&next_report_time, &current_time);
1093 if (wait_time_next_report < wait_time) {
1094 wait_time = wait_time_next_report;
1095 if (wait_time < 0) {
1096 wait_time = 0;
1097 }
1098 }
11931099 }
11941100
11951101 /* Receive replies */
11961102 /* (this is what sleeps during each loop iteration) */
1197 if(wait_for_reply(wait_time)) {
1198 while(wait_for_reply(0)); /* process other replies in the queue */
1199 }
1200
1201 gettimeofday( &current_time, &tz );
1103 if (wait_for_reply(wait_time)) {
1104 while (wait_for_reply(0))
1105 ; /* process other replies in the queue */
1106 }
1107
1108 gettimeofday(&current_time, &tz);
12021109
12031110 /* Print report */
1204 if( report_interval && ( loop_flag || count_flag ) &&
1205 ( timeval_diff ( &current_time, &next_report_time ) >= 0 ) )
1206 {
1207 if(netdata_flag)
1111 if (report_interval && (loop_flag || count_flag) && (timeval_diff(&current_time, &next_report_time) >= 0)) {
1112 if (netdata_flag)
12081113 print_netdata();
12091114 else
12101115 print_per_system_splits();
12111116
1212 while(timeval_diff ( &current_time, &next_report_time ) >= 0 )
1117 while (timeval_diff(&current_time, &next_report_time) >= 0)
12131118 timeval_add(&next_report_time, report_interval);
12141119 }
12151120 }
12321137 void finish()
12331138 {
12341139 int i;
1235 HOST_ENTRY *h;
1236
1237 gettimeofday( &end_time, &tz );
1140 HOST_ENTRY* h;
1141
1142 gettimeofday(&end_time, &tz);
12381143
12391144 /* tot up unreachables */
1240 for( i = 0; i < num_hosts; i++ )
1241 {
1145 for (i = 0; i < num_hosts; i++) {
12421146 h = table[i];
12431147
1244 if( !h->num_recv )
1245 {
1148 if (!h->num_recv) {
12461149 num_unreachable++;
12471150
1248 if( verbose_flag || unreachable_flag )
1249 {
1250 printf( "%s", h->host );
1251
1252 if( verbose_flag )
1253 printf( " is unreachable" );
1254
1255 printf( "\n" );
1256
1257 }/* IF */
1258 }/* IF */
1259 }/* FOR */
1260
1261 if( count_flag || loop_flag )
1151 if (verbose_flag || unreachable_flag) {
1152 printf("%s", h->host);
1153
1154 if (verbose_flag)
1155 printf(" is unreachable");
1156
1157 printf("\n");
1158
1159 }
1160 }
1161 }
1162
1163 if (count_flag || loop_flag)
12621164 print_per_system_stats();
1263 #if defined( DEBUG ) || defined( _DEBUG )
1264 else if( print_per_system_flag )
1165 #if defined(DEBUG) || defined(_DEBUG)
1166 else if (print_per_system_flag)
12651167 print_per_system_stats();
12661168 #endif /* DEBUG || _DEBUG */
12671169
1268 if( stats_flag )
1170 if (stats_flag)
12691171 print_global_stats();
12701172
1271 if( num_noaddress )
1272 exit( 2 );
1273 else if( num_alive != num_hosts )
1274 exit( 1 );
1173 if (num_noaddress)
1174 exit(2);
1175 else if (num_alive != num_hosts)
1176 exit(1);
12751177
12761178 exit(0);
12771179
1278 } /* finish() */
1279
1180 }
12801181
12811182 /************************************************************
12821183
12911192
12921193 ************************************************************/
12931194
1294 void print_per_system_stats( void )
1195 void print_per_system_stats(void)
12951196 {
12961197 int i, j, avg, outage_ms;
1297 HOST_ENTRY *h;
1198 HOST_ENTRY* h;
12981199 int resp;
12991200
1300 fflush( stdout );
1301
1302 if( verbose_flag || per_recv_flag )
1303 fprintf( stderr, "\n" );
1304
1305 for( i = 0; i < num_hosts; i++ )
1306 {
1201 fflush(stdout);
1202
1203 if (verbose_flag || per_recv_flag)
1204 fprintf(stderr, "\n");
1205
1206 for (i = 0; i < num_hosts; i++) {
13071207 h = table[i];
1308 fprintf( stderr, "%s%s :", h->host, h->pad );
1309
1310 if( report_all_rtts_flag ) {
1311 for( j = 0; j < h->num_sent; j++ ) {
1312 if( ( resp = h->resp_times[j] ) >= 0 )
1313 fprintf( stderr, " %d.%02d", resp / 100, resp % 100 );
1208 fprintf(stderr, "%s%s :", h->host, h->pad);
1209
1210 if (report_all_rtts_flag) {
1211 for (j = 0; j < h->num_sent; j++) {
1212 if ((resp = h->resp_times[j]) >= 0)
1213 fprintf(stderr, " %d.%02d", resp / 100, resp % 100);
13141214 else
1315 fprintf( stderr, " -" );
1316 }
1317
1318 fprintf( stderr, "\n" );
1319 }
1320 else {
1321 if( h->num_recv <= h->num_sent )
1322 {
1323 fprintf( stderr, " xmt/rcv/%%loss = %d/%d/%d%%",
1324 h->num_sent, h->num_recv, h->num_sent > 0 ?
1325 ( ( h->num_sent - h->num_recv ) * 100 ) / h->num_sent : 0 );
1215 fprintf(stderr, " -");
1216 }
1217
1218 fprintf(stderr, "\n");
1219 } else {
1220 if (h->num_recv <= h->num_sent) {
1221 fprintf(stderr, " xmt/rcv/%%loss = %d/%d/%d%%",
1222 h->num_sent, h->num_recv, h->num_sent > 0 ? ((h->num_sent - h->num_recv) * 100) / h->num_sent : 0);
13261223
13271224 if (outage_flag) {
13281225 /* Time outage total */
1329 outage_ms = (h->num_sent - h->num_recv) * perhost_interval/100;
1330 fprintf( stderr, ", outage(ms) = %d", outage_ms );
1226 outage_ms = (h->num_sent - h->num_recv) * perhost_interval / 100;
1227 fprintf(stderr, ", outage(ms) = %d", outage_ms);
13311228 }
13321229
1333 }
1334 else {
1335 fprintf( stderr, " xmt/rcv/%%return = %d/%d/%d%%",
1230 } else {
1231 fprintf(stderr, " xmt/rcv/%%return = %d/%d/%d%%",
13361232 h->num_sent, h->num_recv,
1337 ( ( h->num_recv * 100 ) / h->num_sent ) );
1338
1339 }
1340
1341 if( h->num_recv ) {
1233 ((h->num_recv * 100) / h->num_sent));
1234 }
1235
1236 if (h->num_recv) {
13421237 avg = h->total_time / h->num_recv;
1343 fprintf( stderr, ", min/avg/max = %s", sprint_tm( h->min_reply ) );
1344 fprintf( stderr, "/%s", sprint_tm( avg ) );
1345 fprintf( stderr, "/%s", sprint_tm( h->max_reply ) );
1346
1238 fprintf(stderr, ", min/avg/max = %s", sprint_tm(h->min_reply));
1239 fprintf(stderr, "/%s", sprint_tm(avg));
1240 fprintf(stderr, "/%s", sprint_tm(h->max_reply));
13471241 }
13481242
13491243 fprintf(stderr, "\n");
13501244 }
13511245
1352 #if defined( DEBUG ) || defined( _DEBUG )
1353 if( sent_times_flag )
1354 {
1355 for( j = 0; j < h->num_sent; j++ )
1356 {
1357 if( ( resp = h->sent_times[j] ) >= 0 )
1358 fprintf( stderr, " %s", sprint_tm( resp ) );
1246 #if defined(DEBUG) || defined(_DEBUG)
1247 if (sent_times_flag) {
1248 for (j = 0; j < h->num_sent; j++) {
1249 if ((resp = h->sent_times[j]) >= 0)
1250 fprintf(stderr, " %s", sprint_tm(resp));
13591251 else
1360 fprintf( stderr, " -" );
1361
1362 fprintf( stderr, "\n" );
1363
1252 fprintf(stderr, " -");
1253
1254 fprintf(stderr, "\n");
13641255 }
13651256 }
13661257 #endif
13671258 }
13681259 }
13691260
1370
13711261 /************************************************************
13721262
13731263 Function: print_netdata
13811271
13821272 ************************************************************/
13831273
1384 void print_netdata( void )
1274 void print_netdata(void)
13851275 {
13861276 static int sent_charts = 0;
13871277
13881278 int i, avg;
1389 HOST_ENTRY *h;
1390
1391 fflush( stdout );
1392
1393 for( i = 0; i < num_hosts; i++ )
1394 {
1279 HOST_ENTRY* h;
1280
1281 fflush(stdout);
1282
1283 for (i = 0; i < num_hosts; i++) {
13951284 h = table[i];
13961285
1397 if(!sent_charts) {
1286 if (!sent_charts) {
13981287 printf("CHART fping.%s_packets '' 'FPing Packets for host %s' packets '%s' fping.packets line 110020 %d\n", h->name, h->host, h->name, report_interval / 100000);
13991288 printf("DIMENSION xmt sent absolute 1 1\n");
14001289 printf("DIMENSION rcv received absolute 1 1\n");
14051294 printf("SET rcv = %d\n", h->num_recv_i);
14061295 printf("END\n");
14071296
1408 if(!sent_charts) {
1297 if (!sent_charts) {
14091298 printf("CHART fping.%s_quality '' 'FPing Quality for host %s' percentage '%s' fping.quality area 110010 %d\n", h->name, h->host, h->name, report_interval / 100000);
14101299 printf("DIMENSION returned '' absolute 1 1\n");
14111300 /* printf("DIMENSION lost '' absolute 1 1\n"); */
14121301 }
14131302
14141303 /* if we just sent the probe and didn't receive a reply, we shouldn't count it */
1415 h->discard_next_recv_i=0;
1416 if( h->waiting && timeval_diff(&current_time, &h->last_send_time) < h->timeout) {
1417 if(h->num_sent_i) {
1304 h->discard_next_recv_i = 0;
1305 if (h->waiting && timeval_diff(&current_time, &h->last_send_time) < h->timeout) {
1306 if (h->num_sent_i) {
14181307 h->num_sent_i--;
1419 h->discard_next_recv_i=1;
1420 }
1421 }
1422
1308 h->discard_next_recv_i = 1;
1309 }
1310 }
14231311
14241312 printf("BEGIN fping.%s_quality\n", h->name);
1425 /*
1313 /*
14261314 if( h->num_recv_i <= h->num_sent_i )
14271315 printf("SET lost = %d\n", h->num_sent_i > 0 ? ( ( h->num_sent_i - h->num_recv_i ) * 100 ) / h->num_sent_i : 0 );
14281316 else
14291317 printf("SET lost = 0\n");
14301318 */
14311319
1432 printf("SET returned = %d\n", h->num_sent_i > 0 ? ( ( h->num_recv_i * 100 ) / h->num_sent_i ) : 0 );
1320 printf("SET returned = %d\n", h->num_sent_i > 0 ? ((h->num_recv_i * 100) / h->num_sent_i) : 0);
14331321 printf("END\n");
14341322
1435 if(!sent_charts) {
1323 if (!sent_charts) {
14361324 printf("CHART fping.%s_latency '' 'FPing Latency for host %s' ms '%s' fping.latency area 110000 %d\n", h->name, h->host, h->name, report_interval / 100000);
14371325 printf("DIMENSION min minimum absolute 10 1000\n");
14381326 printf("DIMENSION max maximum absolute 10 1000\n");
14401328 }
14411329
14421330 printf("BEGIN fping.%s_latency\n", h->name);
1443 if( h->num_recv_i )
1444 {
1331 if (h->num_recv_i) {
14451332 avg = h->total_time_i / h->num_recv_i;
14461333 printf("SET min = %d\n", h->min_reply_i);
14471334 printf("SET avg = %d\n", avg);
14481335 printf("SET max = %d\n", h->max_reply_i);
14491336
1450 }/* IF */
1337 }
14511338 printf("END\n");
14521339
1453 h->num_sent_i = h->num_recv_i = h->max_reply_i =
1454 h->min_reply_i = h->total_time_i = 0;
1455
1456 }/* FOR */
1340 h->num_sent_i = h->num_recv_i = h->max_reply_i = h->min_reply_i = h->total_time_i = 0;
1341
1342 }
14571343
14581344 sent_charts = 1;
1459 } /* print_per_system_splits() */
1345 }
14601346
14611347 /************************************************************
14621348
14711357
14721358 ************************************************************/
14731359
1474 void print_per_system_splits( void )
1360 void print_per_system_splits(void)
14751361 {
14761362 int i, avg, outage_ms_i;
1477 HOST_ENTRY *h;
1478 struct tm *curr_tm;
1479
1480 fflush( stdout );
1481
1482 if( verbose_flag || per_recv_flag )
1483 fprintf( stderr, "\n" );
1484
1485 gettimeofday( &current_time, &tz );
1486 curr_tm = localtime( ( time_t* )&current_time.tv_sec );
1487 fprintf( stderr, "[%2.2d:%2.2d:%2.2d]\n", curr_tm->tm_hour,
1488 curr_tm->tm_min, curr_tm->tm_sec );
1489
1490 for( i = 0; i < num_hosts; i++ ) {
1363 HOST_ENTRY* h;
1364 struct tm* curr_tm;
1365
1366 fflush(stdout);
1367
1368 if (verbose_flag || per_recv_flag)
1369 fprintf(stderr, "\n");
1370
1371 gettimeofday(&current_time, &tz);
1372 curr_tm = localtime((time_t*)&current_time.tv_sec);
1373 fprintf(stderr, "[%2.2d:%2.2d:%2.2d]\n", curr_tm->tm_hour,
1374 curr_tm->tm_min, curr_tm->tm_sec);
1375
1376 for (i = 0; i < num_hosts; i++) {
14911377 h = table[i];
1492 fprintf( stderr, "%s%s :", h->host, h->pad );
1378 fprintf(stderr, "%s%s :", h->host, h->pad);
14931379
14941380 /* if we just sent the probe and didn't receive a reply, we shouldn't count it */
1495 h->discard_next_recv_i=0;
1496 if( h->waiting && timeval_diff(&current_time, &h->last_send_time) < h->timeout) {
1497 if(h->num_sent_i) {
1381 h->discard_next_recv_i = 0;
1382 if (h->waiting && timeval_diff(&current_time, &h->last_send_time) < h->timeout) {
1383 if (h->num_sent_i) {
14981384 h->num_sent_i--;
1499 h->discard_next_recv_i=1;
1500 }
1501 }
1502
1503 if( h->num_recv_i <= h->num_sent_i ) {
1504 fprintf( stderr, " xmt/rcv/%%loss = %d/%d/%d%%",
1505 h->num_sent_i, h->num_recv_i, h->num_sent_i > 0 ?
1506 ( ( h->num_sent_i - h->num_recv_i ) * 100 ) / h->num_sent_i : 0 );
1385 h->discard_next_recv_i = 1;
1386 }
1387 }
1388
1389 if (h->num_recv_i <= h->num_sent_i) {
1390 fprintf(stderr, " xmt/rcv/%%loss = %d/%d/%d%%",
1391 h->num_sent_i, h->num_recv_i, h->num_sent_i > 0 ? ((h->num_sent_i - h->num_recv_i) * 100) / h->num_sent_i : 0);
15071392
15081393 if (outage_flag) {
15091394 /* Time outage */
1510 outage_ms_i = (h->num_sent_i - h->num_recv_i) * perhost_interval/100;
1511 fprintf( stderr, ", outage(ms) = %d", outage_ms_i );
1512 }
1513 }
1514 else {
1515 fprintf( stderr, " xmt/rcv/%%return = %d/%d/%d%%",
1516 h->num_sent_i, h->num_recv_i, h->num_sent_i > 0 ?
1517 ( ( h->num_recv_i * 100 ) / h->num_sent_i ) : 0 );
1518 }
1519
1520 if( h->num_recv_i ) {
1395 outage_ms_i = (h->num_sent_i - h->num_recv_i) * perhost_interval / 100;
1396 fprintf(stderr, ", outage(ms) = %d", outage_ms_i);
1397 }
1398 } else {
1399 fprintf(stderr, " xmt/rcv/%%return = %d/%d/%d%%",
1400 h->num_sent_i, h->num_recv_i, h->num_sent_i > 0 ? ((h->num_recv_i * 100) / h->num_sent_i) : 0);
1401 }
1402
1403 if (h->num_recv_i) {
15211404 avg = h->total_time_i / h->num_recv_i;
1522 fprintf( stderr, ", min/avg/max = %s", sprint_tm( h->min_reply_i ) );
1523 fprintf( stderr, "/%s", sprint_tm( avg ) );
1524 fprintf( stderr, "/%s", sprint_tm( h->max_reply_i ) );
1525
1526 }
1527
1528 fprintf( stderr, "\n" );
1529 h->num_sent_i = h->num_recv_i = h->max_reply_i =
1530 h->min_reply_i = h->total_time_i = 0;
1531
1532 }
1533 } /* print_per_system_splits() */
1534
1405 fprintf(stderr, ", min/avg/max = %s", sprint_tm(h->min_reply_i));
1406 fprintf(stderr, "/%s", sprint_tm(avg));
1407 fprintf(stderr, "/%s", sprint_tm(h->max_reply_i));
1408 }
1409
1410 fprintf(stderr, "\n");
1411 h->num_sent_i = h->num_recv_i = h->max_reply_i = h->min_reply_i = h->total_time_i = 0;
1412 }
1413 }
15351414
15361415 /************************************************************
15371416
15461425
15471426 ************************************************************/
15481427
1549 void print_global_stats( void )
1550 {
1551 fflush( stdout );
1552 fprintf( stderr, "\n" );
1553 fprintf( stderr, " %7d targets\n", num_hosts );
1554 fprintf( stderr, " %7d alive\n", num_alive );
1555 fprintf( stderr, " %7d unreachable\n" ,num_unreachable );
1556 fprintf( stderr, " %7d unknown addresses\n", num_noaddress );
1557 fprintf( stderr, "\n" );
1558 fprintf( stderr, " %7d timeouts (waiting for response)\n", num_timeout );
1559 fprintf( stderr, " %7d ICMP Echos sent\n", num_pingsent );
1560 fprintf( stderr, " %7d ICMP Echo Replies received\n", num_pingreceived );
1561 fprintf( stderr, " %7d other ICMP received\n", num_othericmprcvd );
1562 fprintf( stderr, "\n" );
1563
1564 if( total_replies == 0 )
1565 {
1428 void print_global_stats(void)
1429 {
1430 fflush(stdout);
1431 fprintf(stderr, "\n");
1432 fprintf(stderr, " %7d targets\n", num_hosts);
1433 fprintf(stderr, " %7d alive\n", num_alive);
1434 fprintf(stderr, " %7d unreachable\n", num_unreachable);
1435 fprintf(stderr, " %7d unknown addresses\n", num_noaddress);
1436 fprintf(stderr, "\n");
1437 fprintf(stderr, " %7d timeouts (waiting for response)\n", num_timeout);
1438 fprintf(stderr, " %7d ICMP Echos sent\n", num_pingsent);
1439 fprintf(stderr, " %7d ICMP Echo Replies received\n", num_pingreceived);
1440 fprintf(stderr, " %7d other ICMP received\n", num_othericmprcvd);
1441 fprintf(stderr, "\n");
1442
1443 if (total_replies == 0) {
15661444 min_reply = 0;
15671445 max_reply = 0;
15681446 total_replies = 1;
15691447 sum_replies = 0;
15701448
1571 }/* IF */
1572
1573 fprintf( stderr, " %s ms (min round trip time)\n", sprint_tm( min_reply ) );
1574 fprintf( stderr, " %s ms (avg round trip time)\n",
1575 sprint_tm( ( int )( sum_replies / total_replies ) ) );
1576 fprintf( stderr, " %s ms (max round trip time)\n", sprint_tm( max_reply ) );
1577 fprintf( stderr, " %12.3f sec (elapsed real time)\n",
1578 timeval_diff( &end_time, &start_time ) / 100000.0 );
1579 fprintf( stderr, "\n" );
1580
1581 } /* print_global_stats() */
1582
1449 }
1450
1451 fprintf(stderr, " %s ms (min round trip time)\n", sprint_tm(min_reply));
1452 fprintf(stderr, " %s ms (avg round trip time)\n",
1453 sprint_tm((int)(sum_replies / total_replies)));
1454 fprintf(stderr, " %s ms (max round trip time)\n", sprint_tm(max_reply));
1455 fprintf(stderr, " %12.3f sec (elapsed real time)\n",
1456 timeval_diff(&end_time, &start_time) / 100000.0);
1457 fprintf(stderr, "\n");
1458
1459 }
15831460
15841461 /************************************************************
15851462
15991476
16001477 ************************************************************/
16011478
1602 int send_ping( HOST_ENTRY *h )
1479 int send_ping(int s, HOST_ENTRY* h)
16031480 {
16041481 int n;
16051482 int myseq;
16061483 int ret = 1;
16071484
1608 gettimeofday( &h->last_send_time, &tz );
1485 gettimeofday(&h->last_send_time, &tz);
16091486 myseq = seqmap_add(h->i, h->num_sent, &h->last_send_time);
16101487
16111488 #if defined(DEBUG) || defined(_DEBUG)
1612 if( trace_flag )
1613 printf( "sending [%d] to %s\n", h->num_sent, h->host );
1489 if (trace_flag)
1490 printf("sending [%d] to %s\n", h->num_sent, h->host);
16141491 #endif /* DEBUG || _DEBUG */
16151492
1616 if(h->saddr.ss_family == AF_INET) {
1617 n = socket_sendto_ping_ipv4(socket4, (struct sockaddr *) &h->saddr, h->saddr_len, myseq, ident);
1618 }
1619 #ifdef IPV6
1620 else if(h->saddr.ss_family == AF_INET6) {
1621 n = socket_sendto_ping_ipv6(socket6, (struct sockaddr *) &h->saddr, h->saddr_len, myseq, ident);
1622 }
1623 #endif
1624 else {
1625 return 0;
1626 }
1627
1628 if(
1493 n = socket_sendto_ping(s, (struct sockaddr*)&h->saddr, h->saddr_len, myseq, ident);
1494
1495 if (
16291496 (n < 0)
1630 #if defined( EHOSTDOWN )
1497 #if defined(EHOSTDOWN)
16311498 && errno != EHOSTDOWN
16321499 #endif
1633 ) {
1634 if( verbose_flag ) {
1635 print_warning( "%s: error while sending ping: %s\n", h->host, strerror( errno ) );
1636 }
1637
1638 if( !loop_flag )
1500 ) {
1501 if (verbose_flag) {
1502 print_warning("%s: error while sending ping: %s\n", h->host, strerror(errno));
1503 }
1504
1505 if (!loop_flag)
16391506 h->resp_times[h->num_sent] = RESP_ERROR;
16401507
16411508 ret = 0;
1642 }
1643 else {
1509 } else {
16441510 /* mark this trial as outstanding */
1645 if( !loop_flag )
1511 if (!loop_flag)
16461512 h->resp_times[h->num_sent] = RESP_WAITING;
16471513
1648 #if defined( DEBUG ) || defined( _DEBUG )
1649 if( sent_times_flag )
1650 h->sent_times[h->num_sent] = timeval_diff( &h->last_send_time, &start_time );
1514 #if defined(DEBUG) || defined(_DEBUG)
1515 if (sent_times_flag)
1516 h->sent_times[h->num_sent] = timeval_diff(&h->last_send_time, &start_time);
16511517 #endif
16521518 }
16531519
16561522 h->waiting++;
16571523 num_pingsent++;
16581524 last_send_time = h->last_send_time;
1659 h->discard_next_recv_i=0;
1660
1661 return(ret);
1662 }
1663
1664 int socket_can_read(struct timeval *timeout)
1525 h->discard_next_recv_i = 0;
1526
1527 return (ret);
1528 }
1529
1530 int wait_on_socket(int socket, struct timeval* timeout)
16651531 {
16661532 int nfound;
16671533 fd_set readset, writeset;
1668 int socketmax;
1669
1670 #ifndef IPV6
1671 socketmax = socket4;
1672 #else
1673 socketmax = socket4 > socket6 ? socket4 : socket6;
1674 #endif
16751534
16761535 select_again:
1677 FD_ZERO( &readset );
1678 FD_ZERO( &writeset );
1679 FD_SET( socket4, &readset );
1680 #ifdef IPV6
1681 FD_SET( socket6, &readset );
1682 #endif
1683
1684 nfound = select(socketmax + 1, &readset, &writeset, NULL, timeout);
1685 if(nfound < 0) {
1686 if(errno == EINTR) {
1536 FD_ZERO(&readset);
1537 FD_ZERO(&writeset);
1538 FD_SET(s, &readset);
1539
1540 nfound = select(socket + 1, &readset, &writeset, NULL, timeout);
1541 if (nfound < 0) {
1542 if (errno == EINTR) {
16871543 /* interrupted system call: redo the select */
16881544 goto select_again;
1689 }
1690 else {
1545 } else {
16911546 perror("select");
16921547 }
16931548 }
16941549
1695 if(nfound > 0) {
1696 if(FD_ISSET(socket4, &readset)) {
1697 return socket4;
1698 }
1699 #ifdef IPV6
1700 if(FD_ISSET(socket6, &readset)) {
1701 return socket6;
1550 if (nfound == 0)
1551 return 0;
1552 else
1553 return 1;
1554 }
1555
1556 int receive_reply(int socket,
1557 struct timeval* timeout,
1558 struct timeval* reply_timestamp,
1559 struct sockaddr* reply_src_addr,
1560 size_t reply_src_addr_len,
1561 char* reply_buf,
1562 size_t reply_buf_len)
1563 {
1564 int recv_len;
1565
1566 /* Wait for input on the socket */
1567 if (timeout && !wait_on_socket(socket, timeout)) {
1568 return 0; /* timeout */
1569 }
1570
1571 /* Receive data */
1572 {
1573 static unsigned char msg_control[40];
1574 struct iovec msg_iov = {
1575 reply_buf,
1576 reply_buf_len
1577 };
1578 struct msghdr recv_msghdr = {
1579 reply_src_addr,
1580 reply_src_addr_len,
1581 &msg_iov,
1582 1,
1583 &msg_control,
1584 sizeof(msg_control),
1585 0
1586 };
1587 int timestamp_set = 0;
1588
1589 recv_len = recvmsg(socket, &recv_msghdr, 0);
1590 if (recv_len <= 0) {
1591 return 0;
1592 }
1593
1594 #if HAVE_SO_TIMESTAMP
1595 /* ancilliary data */
1596 struct cmsghdr* cmsg;
1597 for (cmsg = CMSG_FIRSTHDR(&recv_msghdr);
1598 cmsg != NULL;
1599 cmsg = CMSG_NXTHDR(&recv_msghdr, cmsg)) {
1600 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMP) {
1601 memcpy(reply_timestamp, CMSG_DATA(cmsg), sizeof(*reply_timestamp));
1602 timestamp_set = 1;
1603 }
17021604 }
17031605 #endif
1704 }
1705
1706 return 0;
1707 }
1708
1709 int receive_packet(int socket,
1710 struct timeval *reply_timestamp,
1711 struct sockaddr *reply_src_addr,
1712 size_t reply_src_addr_len,
1713 char *reply_buf,
1714 size_t reply_buf_len)
1715 {
1716 int recv_len;
1717 static unsigned char msg_control[40];
1718 struct iovec msg_iov = {
1719 reply_buf,
1720 reply_buf_len
1721 };
1722 struct msghdr recv_msghdr = {
1723 reply_src_addr,
1724 reply_src_addr_len,
1725 &msg_iov,
1726 1,
1727 &msg_control,
1728 sizeof(msg_control),
1729 0
1730 };
1731 int timestamp_set = 0;
1732 struct cmsghdr *cmsg;
1733
1734 recv_len = recvmsg(socket, &recv_msghdr, 0);
1735 if(recv_len <= 0) {
1736 return 0;
1737 }
1738
1739 #if HAVE_SO_TIMESTAMP
1740 /* ancilliary data */
1741 for(cmsg = CMSG_FIRSTHDR(&recv_msghdr);
1742 cmsg != NULL;
1743 cmsg = CMSG_NXTHDR(&recv_msghdr, cmsg))
1606
1607 if (!timestamp_set) {
1608 gettimeofday(reply_timestamp, NULL);
1609 }
1610 }
1611
1612 return recv_len;
1613 }
1614
1615 int wait_for_reply(long wait_time)
1616 {
1617 int result;
1618 static char buffer[4096];
1619 struct sockaddr_storage response_addr;
1620 int hlen = 0;
1621 FPING_ICMPHDR* icp;
1622 int n, avg;
1623 HOST_ENTRY* h;
1624 long this_reply;
1625 int this_count;
1626 struct timeval* sent_time;
1627 struct timeval recv_time;
1628 SEQMAP_VALUE* seqmap_value;
1629 #ifndef IPV6
1630 struct ip* ip;
1631 #endif
1632
1633 /* receive packet */
17441634 {
1745 if(cmsg->cmsg_level == SOL_SOCKET &&
1746 cmsg->cmsg_type == SCM_TIMESTAMP)
1747 {
1748 memcpy(reply_timestamp, CMSG_DATA(cmsg), sizeof(*reply_timestamp));
1749 timestamp_set = 1;
1750 }
1635 struct timeval to;
1636 if (wait_time) {
1637 if (wait_time < 100000) {
1638 to.tv_sec = 0;
1639 to.tv_usec = wait_time * 10;
1640 } else {
1641 to.tv_sec = wait_time / 100000;
1642 to.tv_usec = (wait_time % 100000) * 10;
1643 }
1644 }
1645
1646 result = receive_reply(s, /* socket */
1647 wait_time ? &to : NULL, /* timeout */
1648 &recv_time, /* reply_timestamp */
1649 (struct sockaddr*)&response_addr, /* reply_src_addr */
1650 sizeof(response_addr), /* reply_src_addr_len */
1651 buffer, /* reply_buf */
1652 sizeof(buffer) /* reply_buf_len */
1653 );
1654
1655 if (result <= 0) {
1656 return 0;
1657 }
1658 }
1659
1660 #if defined(DEBUG) || defined(_DEBUG)
1661 if (randomly_lose_flag) {
1662 if ((random() & 0x07) <= lose_factor)
1663 return 0;
17511664 }
17521665 #endif
17531666
1754 if(! timestamp_set) {
1755 gettimeofday(reply_timestamp, NULL);
1756 }
1757
1758 #if defined( DEBUG ) || defined( _DEBUG )
1759 if( randomly_lose_flag )
1760 {
1761 if( ( random() & 0x07 ) <= lose_factor )
1762 return 0;
1763 }
1764 #endif
1765
1766 return recv_len;
1767 }
1768
1769 int decode_icmp_ipv4(
1770 struct sockaddr *response_addr,
1771 size_t response_addr_len,
1772 char *reply_buf,
1773 size_t reply_buf_len,
1774 unsigned short *id,
1775 unsigned short *seq
1776 )
1777 {
1778 struct ip *ip = (struct ip *) reply_buf;
1779 struct icmp *icp;
1780 int hlen = 0;
1781
1782 #if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ )
1667 #ifndef IPV6
1668 ip = (struct ip*)buffer;
1669 #if defined(__alpha__) && __STDC__ && !defined(__GLIBC__)
17831670 /* The alpha headers are decidedly broken.
17841671 * Using an ANSI compiler, it provides ip_vhl instead of ip_hl and
17851672 * ip_v. So, to get ip_hl, we mask off the bottom four bits.
17861673 */
1787 hlen = ( ip->ip_vhl & 0x0F ) << 2;
1674 hlen = (ip->ip_vhl & 0x0F) << 2;
17881675 #else
17891676 hlen = ip->ip_hl << 2;
1677 #endif /* defined(__alpha__) && __STDC__ */
1678 if (result < hlen + ICMP_MINLEN)
1679 #else
1680 if (result < sizeof(FPING_ICMPHDR))
17901681 #endif
1791
1792 if( reply_buf_len < hlen + ICMP_MINLEN ) {
1793 /* too short */
1794 if( verbose_flag )
1795 {
1682 {
1683 if (verbose_flag) {
17961684 char buf[INET6_ADDRSTRLEN];
1797 getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1798 printf( "received packet too short for ICMP (%d bytes from %s)\n", (int) reply_buf_len, buf);
1799 }
1800 return 0;
1801 }
1802
1803 icp = (struct icmp *)(reply_buf + hlen);
1804
1805 if( icp->icmp_type != ICMP_ECHOREPLY )
1685 getnameinfo((struct sockaddr*)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1686 printf("received packet too short for ICMP (%d bytes from %s)\n", result, buf);
1687 }
1688 return (1); /* too short */
1689 }
1690
1691 gettimeofday(&current_time, &tz);
1692
1693 icp = (FPING_ICMPHDR*)(buffer + hlen);
1694 #ifndef IPV6
1695 if (icp->icmp_type != ICMP_ECHOREPLY)
1696 #else
1697 if (icp->icmp6_type != ICMP6_ECHO_REPLY)
1698 #endif
18061699 {
1807 /* Handle other ICMP packets */
1808 struct icmp *sent_icmp;
1809 SEQMAP_VALUE *seqmap_value;
1810 char addr_ascii[INET6_ADDRSTRLEN];
1811 HOST_ENTRY *h;
1812
1813 /* reply icmp packet (hlen + ICMP_MINLEN) followed by "sent packet" (ip + icmp headers) */
1814 if(reply_buf_len < hlen + ICMP_MINLEN + sizeof(struct ip) + ICMP_MINLEN) {
1815 /* discard ICMP message if we can't tell that it was caused by us (i.e. if the "sent packet" is not included). */
1816 return 0;
1817 }
1818
1819 sent_icmp = (struct icmp *) (reply_buf + hlen + ICMP_MINLEN + sizeof(struct ip));
1820
1821 if(sent_icmp->icmp_type != ICMP_ECHO || ntohs(sent_icmp->icmp_id) != ident) {
1822 /* not caused by us */
1823 return 0;
1824 }
1825
1826 seqmap_value = seqmap_fetch(ntohs(sent_icmp->icmp_seq), &current_time);
1827 if(seqmap_value == NULL) {
1828 return 0;
1829 }
1830
1831 getnameinfo(response_addr, response_addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1832
1833 switch(icp->icmp_type) {
1834 case ICMP_UNREACH:
1835 h = table[seqmap_value->host_nr];
1836 if( icp->icmp_code > ICMP_UNREACH_MAXTYPE ) {
1837 print_warning("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
1838 addr_ascii, h->host );
1839 }
1840 else {
1841 print_warning("%s from %s for ICMP Echo sent to %s",
1842 icmp_unreach_str[icp->icmp_code], addr_ascii, h->host);
1843 }
1844
1845 print_warning("\n" );
1846 num_othericmprcvd++;
1847 break;
1848
1849 case ICMP_SOURCEQUENCH:
1850 case ICMP_REDIRECT:
1851 case ICMP_TIMXCEED:
1852 case ICMP_PARAMPROB:
1853 h = table[seqmap_value->host_nr];
1854 if(icp->icmp_type <= ICMP_TYPE_STR_MAX) {
1855 print_warning("%s from %s for ICMP Echo sent to %s",
1856 icmp_type_str[icp->icmp_type], addr_ascii, h->host );
1857 }
1858 else {
1859 print_warning("ICMP %d from %s for ICMP Echo sent to %s",
1860 icp->icmp_type, addr_ascii, h->host );
1861 }
1862 print_warning( "\n" );
1863 num_othericmprcvd++;
1864 break;
1865 }
1866
1867 return 0;
1868 }
1869
1870 *id = ntohs(icp->icmp_id);
1871 *seq = ntohs(icp->icmp_seq);
1872
1873 return 1;
1874 }
1875
1876 #ifdef IPV6
1877 int decode_icmp_ipv6(
1878 struct sockaddr *response_addr,
1879 size_t response_addr_len,
1880 char *reply_buf,
1881 size_t reply_buf_len,
1882 unsigned short *id,
1883 unsigned short *seq
1884 )
1885 {
1886 struct icmp6_hdr *icp;
1887
1888 if( reply_buf_len < sizeof(struct icmp6_hdr) )
1889 {
1890 if( verbose_flag )
1891 {
1892 char buf[INET6_ADDRSTRLEN];
1893 getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1894 printf( "received packet too short for ICMP (%d bytes from %s)\n", (int) reply_buf_len, buf);
1895 }
1896 return 0; /* too short */
1897 }
1898
1899 icp = (struct icmp6_hdr *) reply_buf;
1900
1901 if( icp->icmp6_type != ICMP6_ECHO_REPLY )
1902 {
1903 /* Handle other ICMP packets */
1904 struct icmp6_hdr *sent_icmp;
1905 SEQMAP_VALUE *seqmap_value;
1906 char addr_ascii[INET6_ADDRSTRLEN];
1907 HOST_ENTRY *h;
1908
1909 /* reply icmp packet (ICMP_MINLEN) followed by "sent packet" (ip + icmp headers) */
1910 if(reply_buf_len < ICMP_MINLEN + sizeof(struct ip) + ICMP_MINLEN) {
1911 /* discard ICMP message if we can't tell that it was caused by us (i.e. if the "sent packet" is not included). */
1912 return 0;
1913 }
1914
1915 sent_icmp = (struct icmp6_hdr *) (reply_buf + sizeof(struct icmp6_hdr) + sizeof(struct ip));
1916
1917 if(sent_icmp->icmp6_type != ICMP_ECHO || ntohs(sent_icmp->icmp6_id) != ident) {
1918 /* not caused by us */
1919 return 0;
1920 }
1921
1922 seqmap_value = seqmap_fetch(ntohs(sent_icmp->icmp6_seq), &current_time);
1923 if(seqmap_value == NULL) {
1924 return 0;
1925 }
1926
1927 getnameinfo(response_addr, response_addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1928
1929 switch(icp->icmp6_type) {
1930 case ICMP_UNREACH:
1931 h = table[seqmap_value->host_nr];
1932 if( icp->icmp6_code > ICMP_UNREACH_MAXTYPE ) {
1933 print_warning("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
1934 addr_ascii, h->host );
1935 }
1936 else {
1937 print_warning("%s from %s for ICMP Echo sent to %s",
1938 icmp_unreach_str[icp->icmp6_code], addr_ascii, h->host);
1939 }
1940
1941 print_warning("\n" );
1942 num_othericmprcvd++;
1943 break;
1944
1945 case ICMP_SOURCEQUENCH:
1946 case ICMP_REDIRECT:
1947 case ICMP_TIMXCEED:
1948 case ICMP_PARAMPROB:
1949 h = table[seqmap_value->host_nr];
1950 if(icp->icmp6_type <= ICMP_TYPE_STR_MAX) {
1951 print_warning("%s from %s for ICMP Echo sent to %s",
1952 icmp_type_str[icp->icmp6_type], addr_ascii, h->host );
1953 }
1954 else {
1955 print_warning("ICMP %d from %s for ICMP Echo sent to %s",
1956 icp->icmp6_type, addr_ascii, h->host );
1957 }
1958 print_warning( "\n" );
1959 num_othericmprcvd++;
1960 break;
1961 }
1962
1963 return 0;
1964 }
1965
1966 *id = ntohs(icp->icmp6_id);
1967 *seq = ntohs(icp->icmp6_seq);
1968
1969 return 1;
1970 }
1700 /* handle some problem */
1701 if (handle_random_icmp(icp, (struct sockaddr*)&response_addr, sizeof(response_addr)))
1702 num_othericmprcvd++;
1703 return 1;
1704 }
1705
1706 #ifndef IPV6
1707 if (ntohs(icp->icmp_id) != ident)
1708 #else
1709 if (ntohs(icp->icmp6_id) != ident)
19711710 #endif
1972
1973
1974 int wait_for_reply(long wait_time)
1975 {
1976 int result;
1977 static char buffer[4096];
1978 struct sockaddr_storage response_addr;
1979 int n, avg;
1980 HOST_ENTRY *h;
1981 long this_reply;
1982 int this_count;
1983 struct timeval *sent_time;
1984 struct timeval recv_time;
1985 SEQMAP_VALUE *seqmap_value;
1986 unsigned short id;
1987 unsigned short seq;
1988 struct timeval to;
1989 int s = 0;
1990
1991 /* Wait for a socket to become ready */
1992 if(wait_time) {
1993 if(wait_time < 100000) {
1994 to.tv_sec = 0;
1995 to.tv_usec = wait_time * 10;
1996 }
1997 else {
1998 to.tv_sec = wait_time / 100000 ;
1999 to.tv_usec = (wait_time % 100000) * 10 ;
2000 }
2001 }
2002 else {
2003 to.tv_sec = 0;
2004 to.tv_usec = 0;
2005 }
2006 s = socket_can_read(&to);
2007 if(s == 0) {
2008 return 0; /* timeout */
2009 }
2010
2011 /* Receive packet */
2012 result = receive_packet(s, /* socket */
2013 &recv_time, /* reply_timestamp */
2014 (struct sockaddr *) &response_addr, /* reply_src_addr */
2015 sizeof(response_addr), /* reply_src_addr_len */
2016 buffer, /* reply_buf */
2017 sizeof(buffer) /* reply_buf_len */
2018 );
2019
2020 if(result <= 0) {
2021 return 0;
2022 }
2023
2024 gettimeofday( &current_time, &tz );
2025
2026 /* Process ICMP packet and retrieve id/seq */
2027 if(response_addr.ss_family == AF_INET) {
2028 if(!decode_icmp_ipv4(
2029 (struct sockaddr *) &response_addr,
2030 sizeof(response_addr),
2031 buffer,
2032 sizeof(buffer),
2033 &id,
2034 &seq)
2035 ) {
2036 return 1;
2037 }
2038 }
2039 #ifdef IPV6
2040 else if(response_addr.ss_family == AF_INET6) {
2041 if(!decode_icmp_ipv6(
2042 (struct sockaddr *) &response_addr,
2043 sizeof(response_addr),
2044 buffer,
2045 sizeof(buffer),
2046 &id,
2047 &seq)
2048 ) {
2049 return 1;
2050 }
2051 }
1711 return 1; /* packet received, but not the one we are looking for! */
1712
1713 #ifndef IPV6
1714 seqmap_value = seqmap_fetch(ntohs(icp->icmp_seq), &current_time);
1715 #else
1716 seqmap_value = seqmap_fetch(ntohs(icp->icmp6_seq), &current_time);
20521717 #endif
2053 else {
2054 return 1;
2055 }
2056
2057 if( id != ident ) {
2058 return 1; /* packet received, but not the one we are looking for! */
2059 }
2060
2061 seqmap_value = seqmap_fetch(seq, &current_time);
2062 if(seqmap_value == NULL) {
1718 if (seqmap_value == NULL) {
20631719 return 1;
20641720 }
20651721
20671723
20681724 n = seqmap_value->host_nr;
20691725 h = table[n];
2070 sent_time = &seqmap_value->ping_ts;
1726 sent_time = &seqmap_value->ping_ts;
20711727 this_count = seqmap_value->ping_count;
2072 this_reply = timeval_diff( &recv_time, sent_time );
2073
2074 if( loop_flag || h->resp_times[this_count] == RESP_WAITING )
2075 {
1728 this_reply = timeval_diff(&recv_time, sent_time);
1729
1730 if (loop_flag || h->resp_times[this_count] == RESP_WAITING) {
20761731 /* only for non-duplicates: */
20771732 h->waiting = 0;
20781733 h->timeout = timeout;
20791734 h->num_recv++;
20801735
2081 if(h->discard_next_recv_i) {
2082 h->discard_next_recv_i=0;
2083 }
2084 else {
1736 if (h->discard_next_recv_i) {
1737 h->discard_next_recv_i = 0;
1738 } else {
20851739 h->num_recv_i++;
2086 if( !h->max_reply_i || this_reply > h->max_reply_i ) h->max_reply_i = this_reply;
2087 if( !h->min_reply_i || this_reply < h->min_reply_i ) h->min_reply_i = this_reply;
1740 if (!h->max_reply_i || this_reply > h->max_reply_i)
1741 h->max_reply_i = this_reply;
1742 if (!h->min_reply_i || this_reply < h->min_reply_i)
1743 h->min_reply_i = this_reply;
20881744 h->total_time_i += this_reply;
20891745 }
20901746
2091 if( !max_reply || this_reply > max_reply ) max_reply = this_reply;
2092 if( !min_reply || this_reply < min_reply ) min_reply = this_reply;
2093 if( !h->max_reply || this_reply > h->max_reply ) h->max_reply = this_reply;
2094 if( !h->min_reply || this_reply < h->min_reply ) h->min_reply = this_reply;
1747 if (!max_reply || this_reply > max_reply)
1748 max_reply = this_reply;
1749 if (!min_reply || this_reply < min_reply)
1750 min_reply = this_reply;
1751 if (!h->max_reply || this_reply > h->max_reply)
1752 h->max_reply = this_reply;
1753 if (!h->min_reply || this_reply < h->min_reply)
1754 h->min_reply = this_reply;
20951755 sum_replies += this_reply;
20961756 h->total_time += this_reply;
20971757 total_replies++;
21001760 /* received ping is cool, so process it */
21011761 h->num_recv_total++;
21021762
2103 #if defined( DEBUG ) || defined( _DEBUG )
2104 if( trace_flag )
2105 printf( "received [%d] from %s\n", this_count, h->host );
1763 #if defined(DEBUG) || defined(_DEBUG)
1764 if (trace_flag)
1765 printf("received [%d] from %s\n", this_count, h->host);
21061766 #endif /* DEBUG || _DEBUG */
21071767
21081768 /* note reply time in array, probably */
2109 if( !loop_flag )
2110 {
2111 if( ( this_count >= 0 ) && ( this_count < trials ) )
2112 {
2113 if( h->resp_times[this_count] >= 0 )
2114 {
2115 if( !per_recv_flag )
2116 {
2117 fprintf( stderr, "%s : duplicate for [%d], %d bytes, %s ms",
2118 h->host, this_count, result, sprint_tm( this_reply ) );
2119
2120 if(addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
1769 if (!loop_flag) {
1770 if ((this_count >= 0) && (this_count < trials)) {
1771 if (h->resp_times[this_count] >= 0) {
1772 if (!per_recv_flag) {
1773 fprintf(stderr, "%s : duplicate for [%d], %d bytes, %s ms",
1774 h->host, this_count, result, sprint_tm(this_reply));
1775
1776 if (addr_cmp((struct sockaddr*)&response_addr, (struct sockaddr*)&h->saddr)) {
21211777 char buf[INET6_ADDRSTRLEN];
2122 getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
2123 fprintf( stderr, " [<- %s]", buf);
1778 getnameinfo((struct sockaddr*)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1779 fprintf(stderr, " [<- %s]", buf);
21241780 }
2125 fprintf( stderr, "\n" );
2126
2127 }/* IF */
2128 }/* IF */
1781 fprintf(stderr, "\n");
1782
1783 }
1784 }
21291785 else
21301786 h->resp_times[this_count] = this_reply;
21311787
2132 }/* IF */
2133 else
2134 {
1788 }
1789 else {
21351790 /* count is out of bounds?? */
2136 fprintf( stderr, "%s : duplicate for [%d], %d bytes, %s ms\n",
2137 h->host, this_count, result, sprint_tm( this_reply ) );
2138
2139 }/* ELSE */
2140 }/* IF */
2141
2142 if( h->num_recv == 1 )
2143 {
1791 fprintf(stderr, "%s : duplicate for [%d], %d bytes, %s ms\n",
1792 h->host, this_count, result, sprint_tm(this_reply));
1793
1794 }
1795 }
1796
1797 if (h->num_recv == 1) {
21441798 num_alive++;
2145 if( verbose_flag || alive_flag )
2146 {
2147 printf( "%s", h->host );
2148
2149 if( verbose_flag )
2150 printf( " is alive" );
2151
2152 if( elapsed_flag )
2153 printf( " (%s ms)", sprint_tm( this_reply ) );
2154
2155 if(addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
1799 if (verbose_flag || alive_flag) {
1800 printf("%s", h->host);
1801
1802 if (verbose_flag)
1803 printf(" is alive");
1804
1805 if (elapsed_flag)
1806 printf(" (%s ms)", sprint_tm(this_reply));
1807
1808 if (addr_cmp((struct sockaddr*)&response_addr, (struct sockaddr*)&h->saddr)) {
21561809 char buf[INET6_ADDRSTRLEN];
2157 getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
2158 fprintf( stderr, " [<- %s]", buf);
2159 }
2160
2161 printf( "\n" );
2162
2163 }/* IF */
2164 }/* IF */
2165
2166 if( per_recv_flag )
2167 {
2168 if(timestamp_flag) {
1810 getnameinfo((struct sockaddr*)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1811 fprintf(stderr, " [<- %s]", buf);
1812 }
1813
1814 printf("\n");
1815 }
1816 }
1817
1818 if (per_recv_flag) {
1819 if (timestamp_flag) {
21691820 printf("[%lu.%06lu] ",
2170 (unsigned long)recv_time.tv_sec,
2171 (unsigned long)recv_time.tv_usec);
1821 (unsigned long)recv_time.tv_sec,
1822 (unsigned long)recv_time.tv_usec);
21721823 }
21731824 avg = h->total_time / h->num_recv;
2174 printf( "%s%s : [%d], %d bytes, %s ms",
2175 h->host, h->pad, this_count, result, sprint_tm( this_reply ) );
2176 printf( " (%s avg, ", sprint_tm( avg ) );
2177
2178 if( h->num_recv <= h->num_sent ) {
2179 printf( "%d%% loss)",
2180 ( ( h->num_sent - h->num_recv ) * 100 ) / h->num_sent );
2181
2182 }
2183 else {
2184 printf( "%d%% return)",
2185 ( h->num_recv_total * 100 ) / h->num_sent );
2186
2187 }
2188
2189 if(addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
1825 printf("%s%s : [%d], %d bytes, %s ms",
1826 h->host, h->pad, this_count, result, sprint_tm(this_reply));
1827 printf(" (%s avg, ", sprint_tm(avg));
1828
1829 if (h->num_recv <= h->num_sent) {
1830 printf("%d%% loss)",
1831 ((h->num_sent - h->num_recv) * 100) / h->num_sent);
1832
1833 } else {
1834 printf("%d%% return)",
1835 (h->num_recv_total * 100) / h->num_sent);
1836 }
1837
1838 if (addr_cmp((struct sockaddr*)&response_addr, (struct sockaddr*)&h->saddr)) {
21901839 char buf[INET6_ADDRSTRLEN];
2191 getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
2192 fprintf( stderr, " [<- %s]", buf);
2193 }
2194
2195 printf( "\n" );
2196
2197 }/* IF */
1840 getnameinfo((struct sockaddr*)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1841 fprintf(stderr, " [<- %s]", buf);
1842 }
1843
1844 printf("\n");
1845
1846 }
21981847
21991848 /* remove this job, if we are done */
2200 if((count_flag && h->num_recv >= count) ||
2201 (!loop_flag && !count_flag && h->num_recv))
2202 {
1849 if ((count_flag && h->num_recv >= count) || (!loop_flag && !count_flag && h->num_recv)) {
22031850 remove_job(h);
22041851 }
22051852
2206 fflush( stdout );
1853 fflush(stdout);
22071854 return num_jobs;
2208
2209 } /* wait_for_reply() */
1855 }
1856
1857 /************************************************************
1858
1859 Function: handle_random_icmp
1860
1861 ************************************************************/
1862
1863 int handle_random_icmp(FPING_ICMPHDR* p, struct sockaddr* addr, socklen_t addr_len)
1864 {
1865 FPING_ICMPHDR* sent_icmp;
1866 unsigned char* c;
1867 HOST_ENTRY* h;
1868 SEQMAP_VALUE* seqmap_value;
1869 char addr_ascii[INET6_ADDRSTRLEN];
1870 unsigned short icmp_type;
1871 unsigned short icmp_code;
1872 unsigned short sent_icmp_type;
1873 unsigned short sent_icmp_seq;
1874 unsigned short sent_icmp_id;
1875
1876 getnameinfo((struct sockaddr*)addr, addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
1877
1878 c = (unsigned char*)p;
1879
1880 sent_icmp = (FPING_ICMPHDR*)(c + 28);
1881 #ifndef IPV6
1882 icmp_type = p->icmp_type;
1883 icmp_code = p->icmp_code;
1884 sent_icmp_type = sent_icmp->icmp_type;
1885 sent_icmp_seq = sent_icmp->icmp_seq;
1886 sent_icmp_id = sent_icmp->icmp_id;
1887 #else
1888 icmp_type = p->icmp6_type;
1889 icmp_code = p->icmp6_code;
1890 sent_icmp_type = sent_icmp->icmp6_type;
1891 sent_icmp_seq = sent_icmp->icmp6_seq;
1892 sent_icmp_id = sent_icmp->icmp6_id;
1893 #endif
1894
1895 switch (icmp_type) {
1896 case ICMP_UNREACH:
1897 seqmap_value = seqmap_fetch(ntohs(sent_icmp_seq), &current_time);
1898
1899 if ((sent_icmp_type == ICMP_ECHO) && (ntohs(sent_icmp_id) == ident) && (seqmap_value != NULL)) {
1900 /* this is a response to a ping we sent */
1901 h = table[ntohs(sent_icmp_seq) % num_hosts];
1902
1903 if (icmp_code > ICMP_UNREACH_MAXTYPE) {
1904 print_warning("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
1905 addr_ascii, h->host);
1906 } else {
1907 print_warning("%s from %s for ICMP Echo sent to %s",
1908 icmp_unreach_str[icmp_code], addr_ascii, h->host);
1909 }
1910
1911 if (inet_addr(h->host) == INADDR_NONE)
1912 print_warning(" (%s)", addr_ascii);
1913
1914 print_warning("\n");
1915 }
1916 return 1;
1917
1918 case ICMP_SOURCEQUENCH:
1919 case ICMP_REDIRECT:
1920 case ICMP_TIMXCEED:
1921 case ICMP_PARAMPROB:
1922 seqmap_value = seqmap_fetch(ntohs(sent_icmp_seq), &current_time);
1923
1924 if ((sent_icmp_type == ICMP_ECHO) && (ntohs(sent_icmp_id) == ident) && (seqmap_value != NULL)) {
1925 /* this is a response to a ping we sent */
1926 h = table[ntohs(sent_icmp_seq) % num_hosts];
1927 if (icmp_type <= ICMP_TYPE_STR_MAX) {
1928 print_warning("%s from %s for ICMP Echo sent to %s",
1929 icmp_type_str[icmp_type], addr_ascii, h->host);
1930 } else {
1931 print_warning("ICMP %d from %s for ICMP Echo sent to %s",
1932 icmp_type, addr_ascii, h->host);
1933 }
1934
1935 if (inet_addr(h->host) == INADDR_NONE)
1936 print_warning(" (%s)", addr_ascii);
1937
1938 print_warning("\n");
1939
1940 }
1941
1942 return 2;
1943
1944 /* no way to tell whether any of these are sent due to our ping */
1945 /* or not (shouldn't be, of course), so just discard */
1946 case ICMP_TSTAMP:
1947 case ICMP_TSTAMPREPLY:
1948 case ICMP_IREQ:
1949 case ICMP_IREQREPLY:
1950 case ICMP_MASKREQ:
1951 case ICMP_MASKREPLY:
1952 default:
1953 return 0;
1954
1955 }
1956 }
22101957
22111958 /************************************************************
22121959
22241971
22251972 ************************************************************/
22261973
2227 void add_name( char *name )
2228 {
2229 struct addrinfo *res0, *res, hints;
2230 int ret_ga;
2231 char *printname;
2232 char namebuf[256];
2233 char addrbuf[256];
1974 void add_name(char* name)
1975 {
1976 struct addrinfo *res0, *res, hints;
1977 int ret_ga;
1978 char* printname;
1979 char namebuf[256];
1980 char addrbuf[256];
22341981
22351982 /* getaddrinfo */
22361983 bzero(&hints, sizeof(struct addrinfo));
22371984 hints.ai_flags = 0;
22381985 hints.ai_socktype = SOCK_RAW;
2239 hints.ai_family = hints_ai_family;
2240 if(hints_ai_family == AF_INET) {
2241 hints.ai_protocol = IPPROTO_ICMP;
2242 }
2243 #ifdef IPV6
2244 else if(hints_ai_family == AF_INET6) {
2245 hints.ai_protocol = IPPROTO_ICMPV6;
2246 }
1986 #ifndef IPV6
1987 hints.ai_family = AF_INET;
1988 hints.ai_protocol = IPPROTO_ICMP;
1989 #else
1990 hints.ai_family = AF_INET6;
1991 hints.ai_protocol = IPPROTO_ICMPV6;
22471992 #endif
2248 else {
2249 hints.ai_protocol = 0;
2250 }
22511993 ret_ga = getaddrinfo(name, NULL, &hints, &res0);
22521994 if (ret_ga) {
2253 if(!quiet_flag)
1995 if (!quiet_flag)
22541996 print_warning("%s: %s\n", name, gai_strerror(ret_ga));
22551997 num_noaddress++;
22561998 return;
22632005 */
22642006 for (res = res0; res; res = res->ai_next) {
22652007 /* name_flag: addr -> name lookup requested) */
2266 if(!name_flag) {
2008 if (!name_flag) {
22672009 printname = name;
2268 }
2269 else {
2010 } else {
22702011 int ret;
22712012 ret = getnameinfo(res->ai_addr, res->ai_addrlen, namebuf,
2272 sizeof(namebuf)/sizeof(char), NULL, 0, 0);
2013 sizeof(namebuf) / sizeof(char), NULL, 0, 0);
22732014 if (ret) {
2274 if(!quiet_flag) {
2275 ret = getnameinfo(res->ai_addr, res->ai_addrlen, namebuf,
2276 sizeof(namebuf)/sizeof(char), NULL, 0, 0);
2277 print_warning("%s: can't reverse-lookup (%s)\n", name, gai_strerror(ret_ga));
2015 if (!quiet_flag) {
2016 print_warning("%s: can't reverse-lookup (%s)\n", name, gai_strerror(ret));
22782017 }
22792018 printname = name;
2280 }
2281 else {
2019 } else {
22822020 printname = namebuf;
22832021 }
22842022 }
22852023
22862024 /* addr_flag: name -> addr lookup requested */
2287 if(addr_flag) {
2025 if (addr_flag) {
22882026 int ret;
22892027 ret = getnameinfo(res->ai_addr, res->ai_addrlen, addrbuf,
2290 sizeof(addrbuf)/sizeof(char), NULL, 0, NI_NUMERICHOST);
2028 sizeof(addrbuf) / sizeof(char), NULL, 0, NI_NUMERICHOST);
22912029 if (ret) {
2292 if(!quiet_flag) {
2293 print_warning("%s: can't forward-lookup address (%s)\n", name, gai_strerror(ret_ga));
2030 if (!quiet_flag) {
2031 print_warning("%s: can't forward-lookup address (%s)\n", name, gai_strerror(ret));
22942032 }
22952033 continue;
22962034 }
22972035
2298 if(name_flag) {
2036 if (name_flag) {
22992037 char nameaddrbuf[512];
2300 snprintf(nameaddrbuf, sizeof(nameaddrbuf)/sizeof(char), "%s (%s)", printname, addrbuf);
2038 snprintf(nameaddrbuf, sizeof(nameaddrbuf) / sizeof(char), "%s (%s)", printname, addrbuf);
23012039 add_addr(name, nameaddrbuf, res->ai_addr, res->ai_addrlen);
2302 }
2303 else {
2040 } else {
23042041 add_addr(name, addrbuf, res->ai_addr, res->ai_addrlen);
23052042 }
2306 }
2307 else {
2043 } else {
23082044 add_addr(name, printname, res->ai_addr, res->ai_addrlen);
23092045 }
23102046
2311 if(!multif_flag) {
2047 if (!multif_flag) {
23122048 break;
23132049 }
23142050 }
23292065
23302066 ************************************************************/
23312067
2332 void add_addr( char *name, char *host, struct sockaddr *ipaddr, socklen_t ipaddr_len )
2333 {
2334 HOST_ENTRY *p;
2068 void add_addr(char* name, char* host, struct sockaddr* ipaddr, socklen_t ipaddr_len)
2069 {
2070 HOST_ENTRY* p;
23352071 int n, *i;
23362072
2337 p = ( HOST_ENTRY* )malloc( sizeof( HOST_ENTRY ) );
2338 if( !p )
2339 crash_and_burn( "can't allocate HOST_ENTRY" );
2340
2341 memset( ( char* ) p, 0, sizeof( HOST_ENTRY ) );
2073 p = (HOST_ENTRY*)malloc(sizeof(HOST_ENTRY));
2074 if (!p)
2075 crash_and_burn("can't allocate HOST_ENTRY");
2076
2077 memset((char*)p, 0, sizeof(HOST_ENTRY));
23422078
23432079 p->name = strdup(name);
23442080 p->host = strdup(host);
23482084 p->running = 1;
23492085 p->min_reply = 0;
23502086
2351 if(netdata_flag) {
2352 char *s = p->name;
2353 while(*s) {
2354 if(!isalnum(*s)) *s = '_';
2087 if (netdata_flag) {
2088 char* s = p->name;
2089 while (*s) {
2090 if (!isalnum(*s))
2091 *s = '_';
23552092 s++;
23562093 }
23572094 }
23582095
2359 if( strlen( p->host ) > max_hostname_len )
2360 max_hostname_len = strlen( p->host );
2096 if (strlen(p->host) > max_hostname_len)
2097 max_hostname_len = strlen(p->host);
23612098
23622099 /* array for response time results */
2363 if( !loop_flag )
2364 {
2365 i = ( int* )malloc( trials * sizeof( int ) );
2366 if( !i )
2367 crash_and_burn( "can't allocate resp_times array" );
2368
2369 for( n = 1; n < trials; n++ )
2100 if (!loop_flag) {
2101 i = (int*)malloc(trials * sizeof(int));
2102 if (!i)
2103 crash_and_burn("can't allocate resp_times array");
2104
2105 for (n = 1; n < trials; n++)
23702106 i[n] = RESP_UNUSED;
23712107
23722108 p->resp_times = i;
23732109
2374 }/* IF */
2375
2376 #if defined( DEBUG ) || defined( _DEBUG )
2110 }
2111
2112 #if defined(DEBUG) || defined(_DEBUG)
23772113 /* likewise for sent times */
2378 if( sent_times_flag )
2379 {
2380 i = ( int* )malloc( trials * sizeof( int ) );
2381 if( !i )
2382 crash_and_burn( "can't allocate sent_times array" );
2383
2384 for( n = 1; n < trials; n++ )
2114 if (sent_times_flag) {
2115 i = (int*)malloc(trials * sizeof(int));
2116 if (!i)
2117 crash_and_burn("can't allocate sent_times array");
2118
2119 for (n = 1; n < trials; n++)
23852120 i[n] = RESP_UNUSED;
23862121
23872122 p->sent_times = i;
23882123
2389 }/* IF */
2124 }
23902125 #endif /* DEBUG || _DEBUG */
23912126
23922127 /* schedule first ping */
23932128 p->ev_type = EV_TYPE_PING;
2394 p->ev_time.tv_sec = 0;
2129 p->ev_time.tv_sec = 0;
23952130 p->ev_time.tv_usec = 0;
23962131 ev_enqueue(p);
23972132
23982133 num_hosts++;
2399
2400 } /* add_addr() */
2401
2134 }
24022135
24032136 /************************************************************
24042137
24122145
24132146 ************************************************************/
24142147
2415 void remove_job( HOST_ENTRY *h )
2416 {
2417 #if defined( DEBUG ) || defined( _DEBUG )
2418 if( trace_flag )
2419 printf( "removing job for %s\n", h->host );
2148 void remove_job(HOST_ENTRY* h)
2149 {
2150 #if defined(DEBUG) || defined(_DEBUG)
2151 if (trace_flag)
2152 printf("removing job for %s\n", h->host);
24202153 #endif /* DEBUG || _DEBUG */
24212154
24222155 h->running = 0;
24242157 --num_jobs;
24252158
24262159 ev_remove(h);
2427
2428 } /* remove_job() */
2160 }
24292161
24302162 /************************************************************
24312163
24392171
24402172 ************************************************************/
24412173
2442 void crash_and_burn( char *message )
2443 {
2444 if( verbose_flag )
2445 fprintf( stderr, "%s: %s\n", prog, message );
2446
2447 exit( 4 );
2448
2449 } /* crash_and_burn() */
2450
2174 void crash_and_burn(char* message)
2175 {
2176 if (verbose_flag)
2177 fprintf(stderr, "%s: %s\n", prog, message);
2178
2179 exit(4);
2180 }
24512181
24522182 /************************************************************
24532183
24612191
24622192 ************************************************************/
24632193
2464 void errno_crash_and_burn( char *message )
2465 {
2466 fprintf( stderr, "%s: %s : %s\n", prog, message, strerror( errno ) );
2467 exit( 4 );
2468 } /* errno_crash_and_burn() */
2469
2194 void errno_crash_and_burn(char* message)
2195 {
2196 fprintf(stderr, "%s: %s : %s\n", prog, message, strerror(errno));
2197 exit(4);
2198 }
24702199
24712200 /************************************************************
24722201
24762205
24772206 *************************************************************/
24782207
2479 void print_warning(char *format, ...) {
2208 void print_warning(char* format, ...)
2209 {
24802210 va_list args;
2481 if(!quiet_flag) {
2482 va_start(args, format );
2211 if (!quiet_flag) {
2212 va_start(args, format);
24832213 vfprintf(stderr, format, args);
24842214 va_end(args);
24852215 }
24862216 }
24872217
2488
2489
24902218 /************************************************************
24912219
24922220 Function: timeval_diff
25042232
25052233 ************************************************************/
25062234
2507 long timeval_diff( struct timeval *a, struct timeval *b )
2235 long timeval_diff(struct timeval* a, struct timeval* b)
25082236 {
25092237 long sec_diff = a->tv_sec - b->tv_sec;
2510 if(sec_diff == 0) {
2238 if (sec_diff == 0) {
25112239 return (a->tv_usec - b->tv_usec) / 10;
2512 }
2513 else if(sec_diff < 100) {
2240 } else if (sec_diff < 100) {
25142241 return (sec_diff * 1000000 + a->tv_usec - b->tv_usec) / 10;
2515 }
2516 else {
2242 } else {
25172243 /* For such large differences, we don't really care about the microseconds... */
25182244 return sec_diff * 100000;
25192245 }
2520 } /* timeval_diff() */
2246 }
25212247
25222248 /************************************************************
25232249
25242250 Function: timeval_add
25252251
25262252 *************************************************************/
2527 void timeval_add(struct timeval *a, long t_10u)
2253 void timeval_add(struct timeval* a, long t_10u)
25282254 {
25292255 t_10u *= 10;
25302256 a->tv_sec += (t_10u + a->tv_usec) / 1000000;
25482274
25492275 ************************************************************/
25502276
2551 char * sprint_tm( int t )
2277 char* sprint_tm(int t)
25522278 {
25532279 static char buf[10];
25542280
2555 if( t < 0 ) {
2281 if (t < 0) {
25562282 /* negative (unexpected) */
2557 sprintf( buf, "%.2g", (double) t / 100 );
2558 }
2559 else if( t < 100 ) {
2283 sprintf(buf, "%.2g", (double)t / 100);
2284 } else if (t < 100) {
25602285 /* <= 0.99 ms */
2561 sprintf( buf, "0.%02d", t );
2562 }
2563 else if( t < 1000 ) {
2286 sprintf(buf, "0.%02d", t);
2287 } else if (t < 1000) {
25642288 /* 1.00 - 9.99 ms */
2565 sprintf( buf, "%d.%02d", t / 100, t % 100 );
2566 }
2567 else if( t < 10000 ) {
2289 sprintf(buf, "%d.%02d", t / 100, t % 100);
2290 } else if (t < 10000) {
25682291 /* 10.0 - 99.9 ms */
2569 sprintf( buf, "%d.%d", t / 100, ( t % 100 ) / 10 );
2570 }
2571 else if( t < 100000000 ) {
2292 sprintf(buf, "%d.%d", t / 100, (t % 100) / 10);
2293 } else if (t < 100000000) {
25722294 /* 100 - 1'000'000 ms */
2573 sprintf( buf, "%d", t / 100 );
2574 }
2575 else {
2576 sprintf( buf, "%.2e", (double) (t / 100) );
2577 }
2578
2579 return( buf );
2295 sprintf(buf, "%d", t / 100);
2296 } else {
2297 sprintf(buf, "%.2e", (double)(t / 100));
2298 }
2299
2300 return (buf);
25802301 }
25812302
25822303 /************************************************************
2304 Function: recvfrom_wto
2305 *************************************************************
2306 Description:
2307
2308 receive with timeout
2309 returns length of data read or -1 if timeout
2310 crash_and_burn on any other errrors
2311 ************************************************************/
2312
2313 int recvfrom_wto(int s, char* buf, int len, struct sockaddr* saddr, socklen_t* saddr_len, long timo)
2314 {
2315 int nfound, n;
2316 struct timeval to;
2317 fd_set readset, writeset;
2318
2319 select_again:
2320 if (timo < 100000) {
2321 to.tv_sec = 0;
2322 to.tv_usec = timo * 10;
2323 } else {
2324 to.tv_sec = timo / 100000;
2325 to.tv_usec = (timo % 100000) * 10;
2326 }
2327
2328 FD_ZERO(&readset);
2329 FD_ZERO(&writeset);
2330 FD_SET(s, &readset);
2331
2332 nfound = select(s + 1, &readset, &writeset, NULL, &to);
2333 if (nfound < 0) {
2334 if (errno == EINTR) {
2335 /* interrupted system call: redo the select */
2336 goto select_again;
2337 } else {
2338 errno_crash_and_burn("select");
2339 }
2340 }
2341
2342 if (nfound == 0)
2343 return -1; /* timeout */
2344
2345 /* recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct sockaddr *restrict address, socklen_t *restrict address_len); */
2346 n = recvfrom(s, buf, len, 0, saddr, saddr_len);
2347 if (n < 0)
2348 errno_crash_and_burn("recvfrom");
2349
2350 return n;
2351 }
2352
2353 /************************************************************
25832354
25842355 Function: addr_cmp
25852356
25862357 *************************************************************/
2587 int addr_cmp(struct sockaddr *a, struct sockaddr *b)
2588 {
2589 if(a->sa_family != b->sa_family) {
2358 int addr_cmp(struct sockaddr* a, struct sockaddr* b)
2359 {
2360 if (a->sa_family != b->sa_family) {
25902361 return a->sa_family - b->sa_family;
2591 }
2592 else {
2593 if(a->sa_family == AF_INET) {
2594 return ((struct sockaddr_in *) a)->sin_addr.s_addr - ((struct sockaddr_in *) b)->sin_addr.s_addr;
2595 }
2596 else if(a->sa_family == AF_INET6) {
2597 return memcmp(&((struct sockaddr_in6 *) a)->sin6_addr,
2598 &((struct sockaddr_in6 *) b)->sin6_addr,
2599 sizeof(((struct sockaddr_in6 *) a)->sin6_addr));
2362 } else {
2363 if (a->sa_family == AF_INET) {
2364 return ((struct sockaddr_in*)a)->sin_addr.s_addr - ((struct sockaddr_in*)b)->sin_addr.s_addr;
2365 } else if (a->sa_family == AF_INET6) {
2366 return memcmp(&((struct sockaddr_in6*)a)->sin6_addr,
2367 &((struct sockaddr_in6*)b)->sin6_addr,
2368 sizeof(((struct sockaddr_in6*)a)->sin6_addr));
26002369 }
26012370 }
26022371
26182387 than the others.
26192388
26202389 *************************************************************/
2621 void ev_enqueue(HOST_ENTRY *h)
2622 {
2623 HOST_ENTRY *i;
2624 HOST_ENTRY *i_prev;
2625
2626 #if defined( DEBUG ) || defined( _DEBUG )
2627 if( trace_flag ) {
2390 void ev_enqueue(HOST_ENTRY* h)
2391 {
2392 HOST_ENTRY* i;
2393 HOST_ENTRY* i_prev;
2394
2395 #if defined(DEBUG) || defined(_DEBUG)
2396 if (trace_flag) {
26282397 long st = timeval_diff(&h->ev_time, &current_time);
2629 fprintf(stderr, "Enqueue: host=%s, when=%d ms (%d, %d)\n", h->host, st/100, h->ev_time.tv_sec, h->ev_time.tv_usec);
2398 fprintf(stderr, "Enqueue: host=%s, when=%d ms (%d, %d)\n", h->host, st / 100, h->ev_time.tv_sec, h->ev_time.tv_usec);
26302399 }
26312400 #endif
26322401
26332402 /* Empty list */
2634 if(ev_last == NULL) {
2403 if (ev_last == NULL) {
26352404 h->ev_next = NULL;
26362405 h->ev_prev = NULL;
26372406 ev_first = h;
26402409 }
26412410
26422411 /* Insert on tail? */
2643 if(h->ev_time.tv_sec > ev_last->ev_time.tv_sec ||
2644 (h->ev_time.tv_sec == ev_last->ev_time.tv_sec &&
2645 h->ev_time.tv_usec >= ev_last->ev_time.tv_usec))
2646 {
2412 if (h->ev_time.tv_sec > ev_last->ev_time.tv_sec || (h->ev_time.tv_sec == ev_last->ev_time.tv_sec && h->ev_time.tv_usec >= ev_last->ev_time.tv_usec)) {
26472413 h->ev_next = NULL;
26482414 h->ev_prev = ev_last;
26492415 ev_last->ev_next = h;
26532419
26542420 /* Find insertion point */
26552421 i = ev_last;
2656 while(1) {
2422 while (1) {
26572423 i_prev = i->ev_prev;
2658 if(i_prev == NULL ||
2659 h->ev_time.tv_sec > i_prev->ev_time.tv_sec ||
2660 (h->ev_time.tv_sec == i_prev->ev_time.tv_sec &&
2661 h->ev_time.tv_usec >= i_prev->ev_time.tv_usec))
2662 {
2424 if (i_prev == NULL || h->ev_time.tv_sec > i_prev->ev_time.tv_sec || (h->ev_time.tv_sec == i_prev->ev_time.tv_sec && h->ev_time.tv_usec >= i_prev->ev_time.tv_usec)) {
26632425 h->ev_prev = i_prev;
26642426 h->ev_next = i;
26652427 i->ev_prev = h;
2666 if(i_prev != NULL) {
2428 if (i_prev != NULL) {
26672429 i_prev->ev_next = h;
2668 }
2669 else {
2430 } else {
26702431 ev_first = h;
26712432 }
26722433 return;
26802441 Function: ev_dequeue
26812442
26822443 *************************************************************/
2683 HOST_ENTRY *ev_dequeue()
2684 {
2685 HOST_ENTRY *dequeued;
2686
2687 if(ev_first == NULL) {
2444 HOST_ENTRY* ev_dequeue()
2445 {
2446 HOST_ENTRY* dequeued;
2447
2448 if (ev_first == NULL) {
26882449 return NULL;
26892450 }
26902451 dequeued = ev_first;
26982459 Function: ev_remove
26992460
27002461 *************************************************************/
2701 void ev_remove(HOST_ENTRY *h)
2702 {
2703 if(ev_first == h) {
2462 void ev_remove(HOST_ENTRY* h)
2463 {
2464 if (ev_first == h) {
27042465 ev_first = h->ev_next;
27052466 }
2706 if(ev_last == h) {
2467 if (ev_last == h) {
27072468 ev_last = h->ev_prev;
27082469 }
2709 if(h->ev_prev) {
2470 if (h->ev_prev) {
27102471 h->ev_prev->ev_next = h->ev_next;
27112472 }
2712 if(h->ev_next) {
2473 if (h->ev_next) {
27132474 h->ev_next->ev_prev = h->ev_prev;
27142475 }
27152476 h->ev_prev = NULL;
27162477 h->ev_next = NULL;
27172478 }
27182479
2719
27202480 /************************************************************
27212481
27222482 Function: usage
27312491
27322492 void usage(int is_error)
27332493 {
2734 FILE *out = is_error ? stderr : stdout;
2735 fprintf(out, "\n" );
2736 fprintf(out, "Usage: %s [options] [targets...]\n", prog );
2737 fprintf(out, " -4 only use IPv4 addresses\n" );
2738 fprintf(out, " -6 only use IPv6 addresses\n" );
2739 fprintf(out, " -a show targets that are alive\n" );
2740 fprintf(out, " -A show targets by address\n" );
2494 FILE* out = is_error ? stderr : stdout;
2495 fprintf(out, "\n");
2496 fprintf(out, "Usage: %s [options] [targets...]\n", prog);
2497 fprintf(out, " -a show targets that are alive\n");
2498 fprintf(out, " -A show targets by address\n");
27412499 fprintf(out, " -b n amount of ping data to send, in bytes (default %d)\n", DEFAULT_PING_DATA_SIZE);
2742 fprintf(out, " -B f set exponential backoff factor to f\n" );
2743 fprintf(out, " -c n count of pings to send to each target (default %d)\n", count );
2744 fprintf(out, " -C n same as -c, report results in verbose format\n" );
2745 fprintf(out, " -D print timestamp before each output line\n" );
2746 fprintf(out, " -e show elapsed time on return packets\n" );
2747 fprintf(out, " -f file read list of targets from a file ( - means stdin) (only if no -g specified)\n" );
2748 fprintf(out, " -g generate target list (only if no -f specified)\n" );
2749 fprintf(out, " (specify the start and end IP in the target list, or supply a IP netmask)\n" );
2750 fprintf(out, " (ex. %s -g 192.168.1.0 192.168.1.255 or %s -g 192.168.1.0/24)\n", prog, prog );
2500 fprintf(out, " -B f set exponential backoff factor to f\n");
2501 fprintf(out, " -c n count of pings to send to each target (default %d)\n", count);
2502 fprintf(out, " -C n same as -c, report results in verbose format\n");
2503 fprintf(out, " -D print timestamp before each output line\n");
2504 fprintf(out, " -e show elapsed time on return packets\n");
2505 fprintf(out, " -f file read list of targets from a file ( - means stdin) (only if no -g specified)\n");
2506 fprintf(out, " -g generate target list (only if no -f specified)\n");
2507 fprintf(out, " (specify the start and end IP in the target list, or supply a IP netmask)\n");
2508 fprintf(out, " (ex. %s -g 192.168.1.0 192.168.1.255 or %s -g 192.168.1.0/24)\n", prog, prog);
27512509 fprintf(out, " -H n Set the IP TTL value (Time To Live hops)\n");
2752 fprintf(out, " -i n interval between sending ping packets (in millisec) (default %d)\n", interval / 100 );
2510 fprintf(out, " -i n interval between sending ping packets (in millisec) (default %d)\n", interval / 100);
27532511 #ifdef SO_BINDTODEVICE
2754 fprintf(out, " -I if bind to a particular interface\n");
2512 fprintf(out, " -I if bind to a particular interface\n");
27552513 #endif
2756 fprintf(out, " -l loop sending pings forever\n" );
2757 fprintf(out, " -m use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A\n" );
2758 fprintf(out, " -M set the Don't Fragment flag\n" );
2759 fprintf(out, " -n show targets by name (-d is equivalent)\n" );
2760 fprintf(out, " -N output compatible for netdata (-l -Q are required)\n" );
2761 fprintf(out, " -o show the accumulated outage time (lost packets * packet interval)\n" );
2762 fprintf(out, " -O n set the type of service (tos) flag on the ICMP packets\n" );
2763 fprintf(out, " -p n interval between ping packets to one target (in millisec)\n" );
2764 fprintf(out, " (in looping and counting modes, default %d)\n", perhost_interval / 100 );
2765 fprintf(out, " -q quiet (don't show per-target/per-ping results)\n" );
2766 fprintf(out, " -Q n same as -q, but show summary every n seconds\n" );
2767 fprintf(out, " -r n number of retries (default %d)\n", DEFAULT_RETRY );
2768 fprintf(out, " -R random packet data (to foil link data compression)\n" );
2769 fprintf(out, " -s print final stats\n" );
2770 fprintf(out, " -S addr set source address\n" );
2771 fprintf(out, " -t n individual target initial timeout (in millisec) (default %d)\n", timeout / 100 );
2514 fprintf(out, " -l loop sending pings forever\n");
2515 fprintf(out, " -m use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A\n");
2516 fprintf(out, " -M set the Don't Fragment flag\n");
2517 fprintf(out, " -n show targets by name (-d is equivalent)\n");
2518 fprintf(out, " -N output compatible for netdata (-l -Q are required)\n");
2519 fprintf(out, " -o show the accumulated outage time (lost packets * packet interval)\n");
2520 fprintf(out, " -O n set the type of service (tos) flag on the ICMP packets\n");
2521 fprintf(out, " -p n interval between ping packets to one target (in millisec)\n");
2522 fprintf(out, " (in looping and counting modes, default %d)\n", perhost_interval / 100);
2523 fprintf(out, " -q quiet (don't show per-target/per-ping results)\n");
2524 fprintf(out, " -Q n same as -q, but show summary every n seconds\n");
2525 fprintf(out, " -r n number of retries (default %d)\n", DEFAULT_RETRY);
2526 fprintf(out, " -R random packet data (to foil link data compression)\n");
2527 fprintf(out, " -s print final stats\n");
2528 fprintf(out, " -S addr set source address\n");
2529 fprintf(out, " -t n individual target initial timeout (in millisec) (default %d)\n", timeout / 100);
27722530 fprintf(out, " -T n ignored (for compatibility with fping 2.4)\n");
2773 fprintf(out, " -u show targets that are unreachable\n" );
2774 fprintf(out, " -v show version\n" );
2775 fprintf(out, " targets list of targets to check (if no -f specified)\n" );
2531 fprintf(out, " -u show targets that are unreachable\n");
2532 fprintf(out, " -v show version\n");
2533 fprintf(out, " targets list of targets to check (if no -f specified)\n");
27762534 fprintf(out, "\n");
27772535 exit(is_error);
2778 } /* usage() */
2536 }
66 #include <sys/types.h>
77 #include <netinet/in.h>
88
9 #ifndef IPV6
10 #define FPING_INADDR struct in_addr
11 #define FPING_ICMPHDR struct icmp
12 #else
13 #define FPING_INADDR struct in6_addr
14 #define FPING_ICMPHDR struct icmp6_hdr
15 #endif
16
917 /* fping.c */
1018 void crash_and_burn( char *message );
1119 void errno_crash_and_burn( char *message );
1321 int random_data_flag;
1422
1523 /* socket.c */
16 int open_ping_socket_ipv4();
17 void init_ping_buffer_ipv4(size_t ping_data_size);
18 void socket_set_src_addr_ipv4(int s, struct in_addr *src_addr);
19 int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
20 #ifdef IPV6
21 int open_ping_socket_ipv6();
22 void init_ping_buffer_ipv6(size_t ping_data_size);
23 void socket_set_src_addr_ipv6(int s, struct in6_addr *src_addr);
24 int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
25 #endif
24 int open_ping_socket();
25 void init_ping_buffer(size_t ping_data_size);
26 void socket_set_src_addr(int s, FPING_INADDR src_addr);
27 int socket_sendto_ping(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq, uint16_t icmp_id);
2628
2729 #endif
0 /*
0 /*
11 * fping: fast-ping, file-ping, favorite-ping, funky-ping
22 *
33 * Ping a list of target hosts in a round robin fashion.
2121 * duplicated in all such forms and that any documentation,
2222 * advertising materials, and other materials related to such
2323 * distribution and use acknowledge that the software was developed
24 * by Stanford University. The name of the University may not be used
25 * to endorse or promote products derived from this software without
24 * by Stanford University. The name of the University may not be used
25 * to endorse or promote products derived from this software without
2626 * specific prior written permission.
2727 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
2828 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
3535 */
3636
3737 #include "seqmap.h"
38 #include "limits.h"
3839 #include "options.h"
39 #include "limits.h"
4040
41 #include <stdio.h>
4142 #include <stdlib.h>
42 #include <stdio.h>
4343
4444 /* description of the data structure used:
4545 *
5050 * - when entering a value, we check that the current entry is expired
5151 */
5252
53 static SEQMAP_VALUE *seqmap_map = NULL;
53 static SEQMAP_VALUE* seqmap_map = NULL;
5454 static unsigned int seqmap_next_id = 0;
5555
56 #define SEQMAP_TIMEOUT_IN_S 10
56 #define SEQMAP_TIMEOUT_IN_S 10
5757 #define SEQMAP_UNASSIGNED_HOST_NR UINT_MAX
5858
5959 void seqmap_init()
6060 {
6161 seqmap_map = calloc(SEQMAP_MAXSEQ, sizeof(SEQMAP_VALUE));
62 if(seqmap_map == NULL) {
62 if (seqmap_map == NULL) {
6363 perror("malloc error (can't allocate seqmap_map)");
6464 }
6565 }
6666
67 unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct timeval *now)
67 unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, struct timeval* now)
6868 {
6969 unsigned int current_id;
70 SEQMAP_VALUE *next_value;
70 SEQMAP_VALUE* next_value;
7171
72 if(!seqmap_map) {
72 if (!seqmap_map) {
7373 fprintf(stderr, "fping internal error: seqmap not initialized.\n");
7474 exit(4);
7575 }
7777 /* check if expired (note that unused seqmap values will have fields set to
7878 * 0, so will be seen as expired */
7979 next_value = &seqmap_map[seqmap_next_id];
80 if(next_value->ping_ts.tv_sec != 0 && (now->tv_sec - next_value->ping_ts.tv_sec) < SEQMAP_TIMEOUT_IN_S) {
80 if (next_value->ping_ts.tv_sec != 0 && (now->tv_sec - next_value->ping_ts.tv_sec) < SEQMAP_TIMEOUT_IN_S) {
8181 fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%d, host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
8282 SEQMAP_TIMEOUT_IN_S, host_nr, ping_count, seqmap_next_id);
8383 exit(4);
9696 return current_id;
9797 }
9898
99 SEQMAP_VALUE *seqmap_fetch(unsigned int id, struct timeval *now)
99 SEQMAP_VALUE* seqmap_fetch(unsigned int id, struct timeval* now)
100100 {
101 SEQMAP_VALUE *value;
101 SEQMAP_VALUE* value;
102102
103 if(id > SEQMAP_MAXSEQ) {
103 if (id > SEQMAP_MAXSEQ) {
104104 return NULL;
105105 }
106106
107107 value = &seqmap_map[id];
108108
109109 /* verify that value is not expired */
110 if(now->tv_sec - value->ping_ts.tv_sec >= SEQMAP_TIMEOUT_IN_S) {
110 if (now->tv_sec - value->ping_ts.tv_sec >= SEQMAP_TIMEOUT_IN_S) {
111111 return NULL;
112112 }
113113
0 /*
1 * fping: fast-ping, file-ping, favorite-ping, funky-ping
2 *
3 * Ping a list of target hosts in a round robin fashion.
4 * A better ping overall.
5 *
6 * fping website: http://www.fping.org
7 *
8 * Current maintainer of fping: David Schweikert
9 * Please send suggestions and patches to: david@schweikert.ch
10 *
11 *
12 * Original author: Roland Schemers <schemers@stanford.edu>
13 * IPv6 Support: Jeroen Massar <jeroen@unfix.org / jeroen@ipng.nl>
14 * Improved main loop: David Schweikert <david@schweikert.ch>
15 * Debian Merge, TOS settings: Tobi Oetiker <tobi@oetiker.ch>
16 * Bugfixes, byte order & senseful seq.-numbers: Stephan Fuhrmann (stephan.fuhrmann AT 1und1.de)
17 *
18 *
19 * Redistribution and use in source and binary forms are permitted
20 * provided that the above copyright notice and this paragraph are
21 * duplicated in all such forms and that any documentation,
22 * advertising materials, and other materials related to such
23 * distribution and use acknowledge that the software was developed
24 * by Stanford University. The name of the University may not be used
25 * to endorse or promote products derived from this software without
26 * specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
29 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 */
31
32 #include "config.h"
33 #include "fping.h"
34
35 int open_ping_socket_ipv4();
36 int open_ping_socket_ipv6();
37 void init_ping_buffer_ipv4(size_t ping_data_size);
38 void init_ping_buffer_ipv6(size_t ping_data_size);
39 void socket_set_src_addr_ipv4(int s, FPING_INADDR src_addr);
40 void socket_set_src_addr_ipv6(int s, FPING_INADDR src_addr);
41 int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
42 int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr);
43
44 int open_ping_socket()
45 {
46 #ifndef IPV6
47 return open_ping_socket_ipv4();
48 #else
49 return open_ping_socket_ipv6();
50 #endif
51 }
52
53 void init_ping_buffer(size_t ping_data_size)
54 {
55 #ifndef IPV6
56 return init_ping_buffer_ipv4(ping_data_size);
57 #else
58 return init_ping_buffer_ipv6(ping_data_size);
59 #endif
60 }
61
62 void socket_set_src_addr(int s, FPING_INADDR src_addr)
63 {
64 #ifndef IPV6
65 socket_set_src_addr_ipv4(s, src_addr);
66 #else
67 socket_set_src_addr_ipv6(s, src_addr);
68 #endif
69 }
70
71 int socket_sendto_ping(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
72 {
73 #ifndef IPV6
74 return socket_sendto_ping_ipv4(s, saddr, saddr_len, icmp_seq_nr, icmp_id_nr);
75 #else
76 return socket_sendto_ping_ipv6(s, saddr, saddr_len, icmp_seq_nr, icmp_id_nr);
77 #endif
78 }
0 /*
0 /*
11 * fping: fast-ping, file-ping, favorite-ping, funky-ping
22 *
33 * Ping a list of target hosts in a round robin fashion.
2121 * duplicated in all such forms and that any documentation,
2222 * advertising materials, and other materials related to such
2323 * distribution and use acknowledge that the software was developed
24 * by Stanford University. The name of the University may not be used
25 * to endorse or promote products derived from this software without
24 * by Stanford University. The name of the University may not be used
25 * to endorse or promote products derived from this software without
2626 * specific prior written permission.
2727 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
2828 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
2929 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
3030 */
3131
32 #include "config.h"
3233 #include "fping.h"
33 #include "config.h"
3434
35 #include <fcntl.h>
36 #include <netdb.h>
37 #include <netinet/in.h>
38 #include <netinet/in_systm.h>
39 #include <netinet/ip.h>
40 #include <netinet/ip_icmp.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
3544 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <netinet/ip.h>
38 #include <netinet/in_systm.h>
39 #include <netinet/ip_icmp.h>
40 #include <netdb.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <stdlib.h>
44 #include <fcntl.h>
4545
46 char *ping_buffer_ipv4 = 0;
47 size_t ping_pkt_size_ipv4;
46 char* ping_buffer = 0;
47 size_t ping_pkt_size;
4848
4949 int open_ping_socket_ipv4()
5050 {
51 struct protoent *proto;
51 struct protoent* proto;
5252 int s;
5353
5454 /* confirm that ICMP is available on this machine */
55 if( ( proto = getprotobyname( "icmp" ) ) == NULL )
56 crash_and_burn( "icmp: unknown protocol" );
55 if ((proto = getprotobyname("icmp")) == NULL)
56 crash_and_burn("icmp: unknown protocol");
5757
5858 /* create raw socket for ICMP calls (ping) */
59 s = socket( AF_INET, SOCK_RAW, proto->p_proto );
60 if( s < 0 ) {
59 s = socket(AF_INET, SOCK_RAW, proto->p_proto);
60 if (s < 0) {
6161 /* try non-privileged icmp (works on Mac OSX without privileges, for example) */
62 s = socket( AF_INET, SOCK_DGRAM, proto->p_proto );
63 if( s < 0 ) {
64 errno_crash_and_burn( "can't create socket (must run as root?)" );
62 s = socket(AF_INET, SOCK_DGRAM, proto->p_proto);
63 if (s < 0) {
64 errno_crash_and_burn("can't create socket (must run as root?)");
6565 }
6666 }
6767
6969 {
7070 int flags;
7171
72 if((flags = fcntl(s, F_GETFL, 0)) < 0)
72 if ((flags = fcntl(s, F_GETFL, 0)) < 0)
7373 perror("fcntl");
7474
75 if(fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
75 if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
7676 perror("fcntl");
7777 }
7878
8282 void init_ping_buffer_ipv4(size_t ping_data_size)
8383 {
8484 /* allocate ping buffer */
85 ping_pkt_size_ipv4 = ping_data_size + ICMP_MINLEN;
86 ping_buffer_ipv4 = (char *) calloc(1, ping_pkt_size_ipv4);
87 if(!ping_buffer_ipv4)
88 crash_and_burn( "can't malloc ping packet" );
85 ping_pkt_size = ping_data_size + ICMP_MINLEN;
86 ping_buffer = (char*)calloc(1, ping_pkt_size);
87 if (!ping_buffer)
88 crash_and_burn("can't malloc ping packet");
8989 }
9090
91 void socket_set_src_addr_ipv4(int s, struct in_addr *src_addr)
91 void socket_set_src_addr_ipv4(int s, FPING_INADDR src_addr)
9292 {
9393 struct sockaddr_in sa;
94 memset( &sa, 0, sizeof( sa ) );
94 memset(&sa, 0, sizeof(sa));
9595 sa.sin_family = AF_INET;
96 sa.sin_addr = *src_addr;
96 sa.sin_addr = src_addr;
9797
98 if ( bind( s, (struct sockaddr *)&sa, sizeof( sa ) ) < 0 )
99 errno_crash_and_burn( "cannot bind source address" );
98 if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
99 errno_crash_and_burn("cannot bind source address");
100100 }
101101
102 unsigned short calcsum(unsigned short *buffer, int length)
102 unsigned short calcsum(unsigned short* buffer, int length)
103103 {
104104 unsigned long sum;
105105
106106 /* initialize sum to zero and loop until length (in words) is 0 */
107 for (sum=0; length>1; length-=2) /* sizeof() returns number of bytes, we're interested in number of words */
108 sum += *buffer++; /* add 1 word of buffer to sum and proceed to the next */
107 for (sum = 0; length > 1; length -= 2) /* sizeof() returns number of bytes, we're interested in number of words */
108 sum += *buffer++; /* add 1 word of buffer to sum and proceed to the next */
109109
110110 /* we may have an extra byte */
111 if (length==1)
112 sum += (char)*buffer;
111 if (length == 1)
112 sum += (char)*buffer;
113113
114114 sum = (sum >> 16) + (sum & 0xFFFF); /* add high 16 to low 16 */
115 sum += (sum >> 16); /* add carry */
115 sum += (sum >> 16); /* add carry */
116116 return ~sum;
117117 }
118118
119 int socket_sendto_ping_ipv4(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
119 int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
120120 {
121 struct icmp *icp;
121 struct icmp* icp;
122122 int n;
123123
124 icp = (struct icmp *) ping_buffer_ipv4;
124 icp = (struct icmp*)ping_buffer;
125125
126126 icp->icmp_type = ICMP_ECHO;
127127 icp->icmp_code = 0;
130130 icp->icmp_id = htons(icmp_id_nr);
131131
132132 if (random_data_flag) {
133 for (n = ((char*)&icp->icmp_data - (char *)icp); n < ping_pkt_size_ipv4; ++n) {
134 ping_buffer_ipv4[n] = random() & 0xFF;
133 for (n = ((void*)&icp->icmp_data - (void*)icp); n < ping_pkt_size; ++n) {
134 ping_buffer[n] = random() & 0xFF;
135135 }
136136 }
137137
138 icp->icmp_cksum = calcsum((unsigned short *) icp, ping_pkt_size_ipv4);
138 icp->icmp_cksum = calcsum((unsigned short*)icp, ping_pkt_size);
139139
140 n = sendto(s, icp, ping_pkt_size_ipv4, 0, saddr, saddr_len);
140 n = sendto(s, icp, ping_pkt_size, 0, saddr, saddr_len);
141141
142142 return n;
143143 }
0 /*
0 /*
11 * fping: fast-ping, file-ping, favorite-ping, funky-ping
22 *
33 * Ping a list of target hosts in a round robin fashion.
2121 * duplicated in all such forms and that any documentation,
2222 * advertising materials, and other materials related to such
2323 * distribution and use acknowledge that the software was developed
24 * by Stanford University. The name of the University may not be used
25 * to endorse or promote products derived from this software without
24 * by Stanford University. The name of the University may not be used
25 * to endorse or promote products derived from this software without
2626 * specific prior written permission.
2727 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
2828 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
2929 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
3030 */
3131
32 #include "config.h"
3233 #include "fping.h"
33 #include "config.h"
3434
35 #include <fcntl.h>
36 #include <netdb.h>
37 #include <netinet/in.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
3541 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <netdb.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <stdlib.h>
41 #include <fcntl.h>
4242
43 #include <netinet/icmp6.h>
43 #include <netinet/icmp6.h>
4444
45 char *ping_buffer_ipv6 = 0;
46 size_t ping_pkt_size_ipv6;
45 char* ping_buffer = 0;
46 size_t ping_pkt_size;
4747
4848 int open_ping_socket_ipv6()
4949 {
50 struct protoent *proto;
50 struct protoent* proto;
5151 int s;
5252
5353 /* confirm that ICMP is available on this machine */
54 if( ( proto = getprotobyname( "ipv6-icmp" ) ) == NULL )
55 crash_and_burn( "icmp: unknown protocol" );
54 if ((proto = getprotobyname("ipv6-icmp")) == NULL)
55 crash_and_burn("icmp: unknown protocol");
5656
5757 /* create raw socket for ICMP calls (ping) */
58 s = socket( AF_INET6, SOCK_RAW, proto->p_proto );
59 if( s < 0 ) {
58 s = socket(AF_INET6, SOCK_RAW, proto->p_proto);
59 if (s < 0) {
6060 /* try non-privileged icmp (works on Mac OSX without privileges, for example) */
61 s = socket( AF_INET6, SOCK_DGRAM, proto->p_proto );
62 if( s < 0 ) {
63 errno_crash_and_burn( "can't create raw socket (must run as root?)" );
61 s = socket(AF_INET6, SOCK_DGRAM, proto->p_proto);
62 if (s < 0) {
63 errno_crash_and_burn("can't create raw socket (must run as root?)");
6464 }
6565 }
6666
6868 {
6969 int flags;
7070
71 if((flags = fcntl(s, F_GETFL, 0)) < 0)
71 if ((flags = fcntl(s, F_GETFL, 0)) < 0)
7272 perror("fcntl");
7373
74 if(fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
74 if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0)
7575 perror("fcntl");
7676 }
7777
8181 void init_ping_buffer_ipv6(size_t ping_data_size)
8282 {
8383 /* allocate ping buffer */
84 ping_pkt_size_ipv6 = ping_data_size + sizeof(struct icmp6_hdr);
85 ping_buffer_ipv6 = (char *) calloc(1, ping_pkt_size_ipv6);
86 if(!ping_buffer_ipv6)
87 crash_and_burn( "can't malloc ping packet" );
84 ping_pkt_size = ping_data_size + sizeof(struct icmp6_hdr);
85 ping_buffer = (char*)calloc(1, ping_pkt_size);
86 if (!ping_buffer)
87 crash_and_burn("can't malloc ping packet");
8888 }
8989
90 void socket_set_src_addr_ipv6(int s, struct in6_addr *src_addr)
90 void socket_set_src_addr_ipv6(int s, FPING_INADDR src_addr)
9191 {
9292 struct sockaddr_in6 sa;
93 memset( &sa, 0, sizeof( sa ) );
93 memset(&sa, 0, sizeof(sa));
9494 sa.sin6_family = AF_INET6;
95 sa.sin6_addr = *src_addr;
95 sa.sin6_addr = src_addr;
9696
97 if ( bind( s, (struct sockaddr *)&sa, sizeof( sa ) ) < 0 )
98 errno_crash_and_burn( "cannot bind source address" );
97 if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
98 errno_crash_and_burn("cannot bind source address");
9999 }
100100
101 int socket_sendto_ping_ipv6(int s, struct sockaddr *saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
101 int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len, uint16_t icmp_seq_nr, uint16_t icmp_id_nr)
102102 {
103 struct icmp6_hdr *icp;
103 struct icmp6_hdr* icp;
104104 int n;
105105
106 icp = (struct icmp6_hdr *) ping_buffer_ipv6;
107 icp->icmp6_type = ICMP6_ECHO_REQUEST;
108 icp->icmp6_code = 0;
109 icp->icmp6_seq = htons(icmp_seq_nr);
110 icp->icmp6_id = htons(icmp_id_nr);
106 icp = (struct icmp6_hdr*)ping_buffer;
107 icp->icmp6_type = ICMP6_ECHO_REQUEST;
108 icp->icmp6_code = 0;
109 icp->icmp6_seq = htons(icmp_seq_nr);
110 icp->icmp6_id = htons(icmp_id_nr);
111111
112112 if (random_data_flag) {
113 for (n = sizeof(struct icmp6_hdr); n < ping_pkt_size_ipv6; ++n) {
114 ping_buffer_ipv6[n] = random() & 0xFF;
113 for (n = sizeof(struct icmp6_hdr); n < ping_pkt_size; ++n) {
114 ping_buffer[n] = random() & 0xFF;
115115 }
116116 }
117117
118 icp->icmp6_cksum = 0; /* The IPv6 stack calculates the checksum for us... */
118 icp->icmp6_cksum = 0; /* The IPv6 stack calculates the checksum for us... */
119119
120 n = sendto(s, icp, ping_pkt_size_ipv6, 0, saddr, saddr_len);
120 n = sendto(s, icp, ping_pkt_size, 0, saddr, saddr_len);
121121
122122 return n;
123123 }