netmask.subr (fa2e39c89210ec44b1afdceadcb999bf9acd2a67) | netmask.subr (35a157a0eb81363303899064c3078f63cda511e1) |
---|---|
1if [ ! "$_NETWORKING_NETMASK_SUBR" ]; then _NETWORKING_NETMASK_SUBR=1 2# 3# Copyright (c) 2006-2012 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 55 unchanged lines hidden (view full) --- 64 65 local octet netmask= 66 for octet in $octets; do 67 netmask="$netmask${netmask:+.}$( printf "%u" "0x$octet" )" 68 done 69 echo $netmask 70} 71 | 1if [ ! "$_NETWORKING_NETMASK_SUBR" ]; then _NETWORKING_NETMASK_SUBR=1 2# 3# Copyright (c) 2006-2012 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 55 unchanged lines hidden (view full) --- 64 65 local octet netmask= 66 for octet in $octets; do 67 netmask="$netmask${netmask:+.}$( printf "%u" "0x$octet" )" 68 done 69 echo $netmask 70} 71 |
72# f_dialog_validate_netmask $netmask | 72# f_validate_netmask $netmask |
73# 74# Returns zero if the given argument (a subnet mask) is of the proper format. 75# 76# The return status for invalid IP address is one of: 77# 1 One or more individual fields within the subnet mask (separated 78# by dots) contains one or more invalid characters. 79# 2 One or more individual fields within the subnet mask are null 80# and/or missing. 81# 3 One or more individual fields within the subnet mask exceeds 82# the maximum of 255 (a full 8-bit register). 83# 4 The subnet mask has either too few or too many fields. 84# 5 One or more individual fields within the subnet mask is an 85# invalid integer (only 0,128,192,224,240,248,252,254,255 are 86# valid integers). 87# | 73# 74# Returns zero if the given argument (a subnet mask) is of the proper format. 75# 76# The return status for invalid IP address is one of: 77# 1 One or more individual fields within the subnet mask (separated 78# by dots) contains one or more invalid characters. 79# 2 One or more individual fields within the subnet mask are null 80# and/or missing. 81# 3 One or more individual fields within the subnet mask exceeds 82# the maximum of 255 (a full 8-bit register). 83# 4 The subnet mask has either too few or too many fields. 84# 5 One or more individual fields within the subnet mask is an 85# invalid integer (only 0,128,192,224,240,248,252,254,255 are 86# valid integers). 87# |
88# If the subnet mask is determined to be invalid, the appropriate error will be 89# displayed using the f_dialog_msgbox function. 90# 91f_dialog_validate_netmask() | 88f_validate_netmask() |
92{ 93 local mask="$1" 94 95 ( # Operate within a sub-shell to protect the parent environment 96 97 # Track number of fields for error checking 98 nfields=0 99 --- 16 unchanged lines hidden (view full) --- 116 esac 117 118 nfields=$(( $nfields + 1 )) 119 120 done 121 122 [ $nfields -eq 4 ] || exit 4 123 ) | 89{ 90 local mask="$1" 91 92 ( # Operate within a sub-shell to protect the parent environment 93 94 # Track number of fields for error checking 95 nfields=0 96 --- 16 unchanged lines hidden (view full) --- 113 esac 114 115 nfields=$(( $nfields + 1 )) 116 117 done 118 119 [ $nfields -eq 4 ] || exit 4 120 ) |
121} |
|
124 | 122 |
125 # 126 # Produce an appropriate error message if necessary. 127 # 128 local retval=$? 129 case $retval in | 123# f_dialog_maskerror $error $netmask 124# 125# Display a msgbox with the appropriate error message for an error returned by 126# the f_validate_netmask function. 127# 128f_dialog_maskerror() 129{ 130 local error="$1" netmask="$2" 131 132 [ ${error:-0} -ne 0 ] || return $SUCCESS 133 134 case "$error" in |
130 1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask";; 131 2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask";; 132 3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask";; 133 4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask";; 134 5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask";; 135 esac | 135 1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask";; 136 2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask";; 137 3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask";; 138 4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask";; 139 5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask";; 140 esac |
141} |
|
136 | 142 |
143# f_dialog_validate_netmask $netmask 144# 145# Returns zero if the given argument (a subnet mask) is of the proper format. 146# 147# If the subnet mask is determined to be invalid, the appropriate error will be 148# displayed using the f_dialog_maskerror function above. 149# 150f_dialog_validate_netmask() 151{ 152 local netmask="$1" 153 154 f_validate_netmask "$netmask" 155 local retval=$? 156 157 # Produce an appropriate error message if necessary. 158 [ $retval -eq $SUCCESS ] || f_dialog_maskerror $retval "$netmask" 159 |
|
137 return $retval 138} 139 140# f_dialog_input_netmask $interface $netmask 141# 142# Edits the IP netmask of the given interface. 143# 144f_dialog_input_netmask() --- 45 unchanged lines hidden --- | 160 return $retval 161} 162 163# f_dialog_input_netmask $interface $netmask 164# 165# Edits the IP netmask of the given interface. 166# 167f_dialog_input_netmask() --- 45 unchanged lines hidden --- |