Debian Codegraph @

tests/traceroute-localhost.sh

raw
1 #!/bin/sh
2
3 # Copyright (C) 2009-2026 Free Software Foundation, Inc.
4 #
5 # This file is part of GNU Inetutils.
6 #
7 # GNU Inetutils is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # GNU Inetutils is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see `http://www.gnu.org/licenses/'.
19
20 # Prerequisites:
21 #
22 # * Shell: SVR3 Bourne shell, or newer.
23 #
24 # * id(1)
25
26 . ./tools.sh
27
28 PROTOCOLS=/etc/protocols
29 if test ! -r $PROTOCOLS; then
30 cat <<-EOT >&2
31 This test requires the availability of "$PROTOCOLS",
32 a file which can not be found in the current system.
33 Therefore skipping this test.
34 EOT
35 exit 77
36 fi
37
38 TRACEROUTE=${TRACEROUTE:-../src/traceroute$EXEEXT}
39 TARGET=${TARGET:-127.0.0.1}
40
41 if [ ! -x $TRACEROUTE ]; then
42 echo 'No executable "'$TRACEROUTE'" available. Skipping test.' >&2
43 exit 77
44 fi
45
46 if [ $VERBOSE ]; then
47 set -x
48 $TRACEROUTE --version
49 fi
50
51 if test "$TEST_IPV4" = "no"; then
52 echo >&2 "Disabled IPv4 testing. Skipping test."
53 exit 77
54 fi
55
56 if test `func_id_uid` != 0; then
57 echo "traceroute needs to run as root"
58 exit 77
59 fi
60
61 errno=0
62 errno2=0
63
64 if test "$TEST_IPV4" != "no" && test -n "$TARGET"; then
65 $TRACEROUTE --type=udp $TARGET || errno=$?
66 test $errno -eq 0 || echo "Failed at UDP tracing." >&2
67
68 $TRACEROUTE --type=icmp $TARGET || errno2=$?
69 test $errno2 -eq 0 || echo "Failed at ICMP tracing." >&2
70 fi
71
72 test $errno -eq 0 || exit $errno
73
74 exit $errno2