|
Packit |
71e9d6 |
#!/bin/bash
|
|
Packit |
71e9d6 |
#
|
|
Packit |
71e9d6 |
# Run some simple ipcalc tests.
|
|
Packit |
71e9d6 |
#
|
|
Packit |
71e9d6 |
# Adapted from: Matej Susta <msusta@redhat.com>
|
|
Packit |
71e9d6 |
#
|
|
Packit |
71e9d6 |
# Copyright (c) 2009 Red Hat, Inc. All rights reserved.
|
|
Packit |
71e9d6 |
#
|
|
Packit |
71e9d6 |
# This copyrighted material is made available to anyone wishing
|
|
Packit |
71e9d6 |
# to use, modify, copy, or redistribute it subject to the terms
|
|
Packit |
71e9d6 |
# and conditions of the GNU General Public License version 2.
|
|
Packit |
71e9d6 |
#
|
|
Packit |
71e9d6 |
# This program is distributed in the hope that it will be
|
|
Packit |
71e9d6 |
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
Packit |
71e9d6 |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
Packit |
71e9d6 |
# PURPOSE. See the GNU General Public License for more details.
|
|
Packit |
71e9d6 |
#
|
|
Packit |
71e9d6 |
# You should have received a copy of the GNU General Public
|
|
Packit |
71e9d6 |
# License along with this program; if not, write to the Free
|
|
Packit |
71e9d6 |
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit |
71e9d6 |
# Boston, MA 02110-1301, USA.
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
bin=./ipcalc
|
|
Packit |
71e9d6 |
exitcode=0
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
ok() {
|
|
Packit |
71e9d6 |
echo "ok."
|
|
Packit |
71e9d6 |
}
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
fail() {
|
|
Packit |
71e9d6 |
echo "FAILED!"
|
|
Packit |
71e9d6 |
exitcode=$((exitcode+1))
|
|
Packit |
71e9d6 |
echo -e "Output was:\n$output"
|
|
Packit |
71e9d6 |
}
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestSuccess() {
|
|
Packit |
71e9d6 |
echo -n "Checking $@... "
|
|
Packit |
71e9d6 |
output=$(sh -c "$1" 2>&1)
|
|
Packit |
71e9d6 |
rc=$?
|
|
Packit |
71e9d6 |
[ $rc -eq 0 ] && ok || fail $output
|
|
Packit |
71e9d6 |
}
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestFailure() {
|
|
Packit |
71e9d6 |
echo -n "Checking $@... "
|
|
Packit |
71e9d6 |
output=$(sh -c "$1" 2>&1)
|
|
Packit |
71e9d6 |
rc=$?
|
|
Packit |
71e9d6 |
[ $rc -eq 0 ] && fail $output || ok
|
|
Packit |
71e9d6 |
}
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestOutput() {
|
|
Packit |
71e9d6 |
echo -n "Checking $1... "
|
|
Packit |
71e9d6 |
output=$(sh -c "$1" 2>&1)
|
|
Packit |
71e9d6 |
rc=$?
|
|
Packit |
71e9d6 |
[ "$output" = "$2" ] && ok || fail $output
|
|
Packit |
71e9d6 |
}
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
echo -n "Checking for ipcalc binary... "
|
|
Packit |
71e9d6 |
[ -x $bin ] || { fail ; exit $exitcode ; }
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestSuccess "$bin --help"
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c 127.0.0.1"
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c -6 ::1"
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c ::1"
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c 192.168.1.1"
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c -6 2a01:198:200:300::2"
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c -6 2a01:198:200:300:0000:0000:0000:2"
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c -6 2a01:0198:0200:0300:0000:0000:0000:0002"
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c -6 ::1/128"
|
|
Packit |
71e9d6 |
TestSuccess "$bin -c -6 fec0::1:0:0:c0a8:8002/64"
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestFailure "$bin -c -6 gggg::"
|
|
Packit |
71e9d6 |
#TestFailure "$bin -b -6 ::1/128"
|
|
Packit |
71e9d6 |
TestFailure "$bin -c -4 -6 2a01:198:200:300:0000:0000:0000:2"
|
|
Packit |
71e9d6 |
TestFailure "$bin -c -4 2a01:198:200:300:0000:0000:0000:2"
|
|
Packit |
71e9d6 |
TestFailure "$bin -c -4 -6 127.0.0.1"
|
|
Packit |
71e9d6 |
TestFailure "$bin -c -6 127.0.0.1"
|
|
Packit |
71e9d6 |
TestFailure "$bin -c ::1/999"
|
|
Packit |
71e9d6 |
TestFailure "$bin -m 192.168.1.1/-1"
|
|
Packit |
71e9d6 |
TestFailure "$bin -m 192.168.1.1/64"
|
|
Packit |
71e9d6 |
TestFailure "$bin -m 192.168.1.1/99999"
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
TestOutput "$bin -b 192.168.1.1/24" "BROADCAST=192.168.1.255"
|
|
Packit |
71e9d6 |
TestOutput "$bin -b 192.168.1.1 255.255.255.0" "BROADCAST=192.168.1.255"
|
|
Packit |
71e9d6 |
TestOutput "$bin -m 192.168.1.1/24" "NETMASK=255.255.255.0"
|
|
Packit |
71e9d6 |
TestOutput "$bin -p 192.168.1.1 255.255.255.0" "PREFIX=24"
|
|
Packit |
71e9d6 |
TestOutput "$bin -p 192.168.1.1 255.255.255.255" "PREFIX=32"
|
|
Packit |
71e9d6 |
TestOutput "$bin -p 192.168.1.1 0.0.0.0" "PREFIX=0"
|
|
Packit |
71e9d6 |
TestOutput "$bin -p 172.16.59.222 255.255.252.0" "PREFIX=22"
|
|
Packit |
71e9d6 |
TestOutput "$bin -m 172.16.59.222/22" "NETMASK=255.255.252.0"
|
|
Packit |
71e9d6 |
TestOutput "$bin --class-prefix -m 192.168.1.1" "NETMASK=255.255.255.0"
|
|
Packit |
71e9d6 |
TestOutput "$bin -m 192.168.1.1" "NETMASK=255.255.255.255"
|
|
Packit |
71e9d6 |
TestOutput "$bin --class-prefix -m 10.1.2.3" "NETMASK=255.0.0.0"
|
|
Packit |
71e9d6 |
TestOutput "$bin --class-prefix -m 129.22.4.3" "NETMASK=255.255.0.0"
|
|
Packit |
71e9d6 |
TestOutput "$bin -n 192.168.1.1/32" "NETWORK=192.168.1.1"
|
|
Packit |
71e9d6 |
TestOutput "$bin -n 192.168.1.1/0" "NETWORK=0.0.0.0"
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 193.92.150.3/32" "REVERSEDNS=3.150.92.193.in-addr.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 193.92.150.3/26" "REVERSEDNS=0-63.150.92.193.in-addr.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 193.92.150.3/16" "REVERSEDNS=92.193.in-addr.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 193.92.150.3/12" "REVERSEDNS=80-95.193.in-addr.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 4321:0:1:2:3:4:567:89ab" "REVERSEDNS=b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 1::" "REVERSEDNS=0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.ip6.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns ::1" "REVERSEDNS=1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 1234::4321/128" "REVERSEDNS=1.2.3.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.ip6.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 1234::4321/124" "REVERSEDNS=2.3.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.ip6.arpa."
|
|
Packit |
71e9d6 |
TestOutput "$bin --reverse-dns 1234::4321/120" "REVERSEDNS=3.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.ip6.arpa."
|
|
Packit |
71e9d6 |
|
|
Packit |
71e9d6 |
echo "$exitcode test(s) failed."
|
|
Packit |
71e9d6 |
exit $exitcode
|