IP_SUPPORTED_PROTOCOLS="${IP_SUPPORTED_PROTOCOLS} ipv4"
function ipv4_is_valid() {
- local address=${1}
+ ipcalc --ipv4 -c $@ >/dev/null 2>&1
- assert isset address
-
- # Cut the prefix if there is one given
- local prefix=$(ip_get_prefix ${address})
- address=$(ip_split_prefix ${address})
-
- # If address is larger than 15 characters it cannot be an IPv4 address
- [ ${#address} -gt 15 ] && return ${EXIT_ERROR}
-
- # Check for a valid IPv4 prefix if provided
- if [ -n "${prefix}" ]; then
- if [ ${prefix} -lt 4 ] || [ ${prefix} -gt 30 ]; then
+ case "$?" in
+ 0)
+ return ${EXIT_OK}
+ ;;
+ *)
return ${EXIT_ERROR}
- fi
- fi
-
- local IFS="."
- local octet
- local count
- for octet in ${address}; do
- if [ ${octet} -ge 0 ] && [ ${octet} -le 255 ]; then
- count=$(( ${count} + 1 ))
- continue
- fi
-
- # If we get here the address was not valid
- break
- done
-
- if [ ${count} -eq 4 ]; then
- return ${EXIT_OK}
- fi
-
- return ${EXIT_ERROR}
+ ;;
+ esac
}
function ipv4_detect_duplicate() {
}
function ipv6_is_valid() {
- local address=${1}
-
- assert isset address
-
- local prefix=$(ip_get_prefix ${address})
- address=$(ip_split_prefix ${address})
-
- # Check length
- [ ${#address} -gt 39 ] && return ${EXIT_ERROR}
+ ipcalc --ipv6 -c $@ >/dev/null 2>&1
- # Check prefix if provided
- if [ -n "${prefix}" ]; then
- # XXX need to check was largest prefix is
- if [ ${prefix} -lt 0 ] && [ ${prefix} -gt 64 ]; then
+ case "$?" in
+ 0)
+ return ${EXIT_OK}
+ ;;
+ *)
return ${EXIT_ERROR}
- fi
- fi
-
- # XXX find :: twice?
- # XXX check for documentation prefix?
-
- # Check for bad characters
- local char
- for char in 0 1 2 3 4 5 6 7 8 9 a b c d e f :; do
- address=${address//${char}/}
- done
- [ -n "${address}" ] && return ${EXIT_ERROR}
-
- return ${EXIT_OK}
+ ;;
+ esac
}
function ipv6_implode() {