diff options
author | Phil Davis <phil.davis@inf.org> | 2016-12-20 22:07:45 +0545 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-20 22:07:45 +0545 |
commit | 24eb39e29641488c7fa970d69f42edd84e2fbb1e (patch) | |
tree | fa62c9e799cb878193716c57ccba89c62c6a7c02 /src/etc/inc/util.inc | |
parent | cf9e9e84fc07a94e41497680a98e4de10f91f933 (diff) | |
download | pfsense-24eb39e29641488c7fa970d69f42edd84e2fbb1e.zip pfsense-24eb39e29641488c7fa970d69f42edd84e2fbb1e.tar.gz |
validateipaddr return address family
Enhanced the return values from validateipaddr() so the caller can know if the validated address is IPv4 or IPv6 (or an alias if that check was requested). That makes it a better replacement for is_ipaddr().
Diffstat (limited to 'src/etc/inc/util.inc')
-rw-r--r-- | src/etc/inc/util.inc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 66b4a43..901b762 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -2481,14 +2481,20 @@ function get_smart_drive_list() { // $label: the label used by the GUI to display this value. Required to compose an error message // $err_msg: pointer to the callers error message array so that error messages can be added to it here // $alias: are aliases permitted for this address? +// Returns: +// 4 - if $addr is a valid IPv4 address +// 6 - if $addr is a valid IPv6 address +// 1 - if $alias=true and $addr is an alias +// false - otherwise + function validateipaddr(&$addr, $type, $label, &$err_msg, $alias=false) { switch ($type) { case IPV4: if (is_ipaddrv4($addr)) { - return true; + return 4; } else if ($alias) { if (is_alias($addr)) { - return true; + return 1; } else { $err_msg[] = sprintf(gettext("%s must be a valid IPv4 address or alias."), $label); return false; @@ -2501,10 +2507,10 @@ function validateipaddr(&$addr, $type, $label, &$err_msg, $alias=false) { case IPV6: if (is_ipaddrv6($addr)) { $addr = strtolower($addr); - return true; + return 6; } else if ($alias) { if (is_alias($addr)) { - return true; + return 1; } else { $err_msg[] = sprintf(gettext("%s must be a valid IPv6 address or alias."), $label); return false; @@ -2517,12 +2523,12 @@ function validateipaddr(&$addr, $type, $label, &$err_msg, $alias=false) { case IPV4V6: if (is_ipaddrv6($addr)) { $addr = strtolower($addr); - return true; + return 6; } else if (is_ipaddrv4($addr)) { - return true; + return 4; } else if ($alias) { if (is_alias($addr)) { - return true; + return 1; } else { $err_msg[] = sprintf(gettext("%s must be a valid IPv4 or IPv6 address or alias."), $label); return false; |