diff options
author | dteske <dteske@FreeBSD.org> | 2012-12-21 21:33:47 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2012-12-21 21:33:47 +0000 |
commit | 777c7fa05d0e27302d79b46b228dbbd72462832d (patch) | |
tree | fc772cd14bc7442c2e3e9fda729baa5218bad31e /usr.sbin/bsdconfig/networking/share/netmask.subr | |
parent | ddf809931fdd7bcce325e32e1cf30843342497e3 (diff) | |
download | FreeBSD-src-777c7fa05d0e27302d79b46b228dbbd72462832d.zip FreeBSD-src-777c7fa05d0e27302d79b46b228dbbd72462832d.tar.gz |
Split dialog(1)-based validators for hostname/netmask into two, providing
transparent validators that can be used free of dialog(1) where needed.
Syntax/return of the original dialog(1)-based validators remains unchanged.
Diffstat (limited to 'usr.sbin/bsdconfig/networking/share/netmask.subr')
-rw-r--r-- | usr.sbin/bsdconfig/networking/share/netmask.subr | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/usr.sbin/bsdconfig/networking/share/netmask.subr b/usr.sbin/bsdconfig/networking/share/netmask.subr index c120621..4b28743 100644 --- a/usr.sbin/bsdconfig/networking/share/netmask.subr +++ b/usr.sbin/bsdconfig/networking/share/netmask.subr @@ -69,7 +69,7 @@ f_ifconfig_netmask() echo $netmask } -# f_dialog_validate_netmask $netmask +# f_validate_netmask $netmask # # Returns zero if the given argument (a subnet mask) is of the proper format. # @@ -85,10 +85,7 @@ f_ifconfig_netmask() # invalid integer (only 0,128,192,224,240,248,252,254,255 are # valid integers). # -# If the subnet mask is determined to be invalid, the appropriate error will be -# displayed using the f_dialog_msgbox function. -# -f_dialog_validate_netmask() +f_validate_netmask() { local mask="$1" @@ -121,18 +118,44 @@ f_dialog_validate_netmask() [ $nfields -eq 4 ] || exit 4 ) +} - # - # Produce an appropriate error message if necessary. - # - local retval=$? - case $retval in +# f_dialog_maskerror $error $netmask +# +# Display a msgbox with the appropriate error message for an error returned by +# the f_validate_netmask function. +# +f_dialog_maskerror() +{ + local error="$1" netmask="$2" + + [ ${error:-0} -ne 0 ] || return $SUCCESS + + case "$error" in 1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask";; 2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask";; 3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask";; 4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask";; 5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask";; esac +} + +# f_dialog_validate_netmask $netmask +# +# Returns zero if the given argument (a subnet mask) is of the proper format. +# +# If the subnet mask is determined to be invalid, the appropriate error will be +# displayed using the f_dialog_maskerror function above. +# +f_dialog_validate_netmask() +{ + local netmask="$1" + + f_validate_netmask "$netmask" + local retval=$? + + # Produce an appropriate error message if necessary. + [ $retval -eq $SUCCESS ] || f_dialog_maskerror $retval "$netmask" return $retval } |