Edit ip addresses a bit better in interactive commands

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5144 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2006-12-21 02:29:32 +00:00
parent 2cbb02649c
commit 5e7efa2975
2 changed files with 33 additions and 1 deletions

View File

@ -360,6 +360,32 @@ lib_avail() # $1 = Name of the Library
LEFTSHIFT='<<'
#
# Validate an IP address
#
valid_address() {
local x y
local ifs=$IFS
IFS=.
for x in $1; do
case $x in
[0-9]|[0-9][0-9]|[1-2][0-9][0-9])
[ $x -lt 256 ] || { IFS=$ifs; return 2; }
;;
*)
IFS=$ifs
return 2
;;
esac
done
IFS=$ifs
return 0
}
#
# Convert an IP address in dot quad format to an integer
#

View File

@ -1468,6 +1468,7 @@ case "$COMMAND" in
usage 1
fi
valid_address $address || fatal_error "Invalid IP address: $address"
[ -z "$vlsm" ] && exit 2
[ "x$address" = "x$vlsm" ] && usage 2
[ $vlsm -gt 32 ] && echo "Invalid VLSM: /$vlsm" >&2 && exit 2
@ -1484,6 +1485,10 @@ case "$COMMAND" in
[ -n "$debugging" ] && set -x
case $2 in
*.*.*.*-*.*.*.*)
for address in ${2%-*} ${2#*-}; do
valid_address $address || fatal_error "Invalid IP address: $address"
done
ip_range $2
;;
*)
@ -1495,6 +1500,7 @@ case "$COMMAND" in
[ -n "$debugging" ] && set -x
case $2 in
*.*.*.*)
valid_address $2 || fatal_error "Invalid IP address: $2"
echo " $(decodeaddr $2)"
;;
*)
@ -1504,7 +1510,7 @@ case "$COMMAND" in
;;
restore)
shift
r estore_command $@
restore_command $@
;;
call)
[ -n "$debugging" ] && set -x