diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 2c8a948d..a2d807c8 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -529,6 +529,21 @@ function psm_is_cli() { return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))); } +/** + * Check if ip is IPv6 or not + * + * @param string $ip + * @return boolean + */ +function psm_validate_ipv6($ip) { + // if $ip is a valid ipv6 address it returns true + if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){ + return true; + } else { + return false; + } +} + ############################################### # # Debug functions diff --git a/src/psm/Util/Updater/StatusUpdater.class.php b/src/psm/Util/Updater/StatusUpdater.class.php index 57d50ac4..fcfcd354 100644 --- a/src/psm/Util/Updater/StatusUpdater.class.php +++ b/src/psm/Util/Updater/StatusUpdater.class.php @@ -243,7 +243,7 @@ class StatusUpdater { //if(psm_is_cli()) { // IPv6 ready - if ($this->is_ipv6($this->server['ip'])) { + if (psm_validate_ipv6($this->server['ip'])) { $socket = socket_create(AF_INET6, SOCK_RAW, 1); } else { $socket = socket_create(AF_INET, SOCK_RAW, 1); @@ -286,23 +286,4 @@ class StatusUpdater { public function getRtime() { return $this->rtime; } - - /** - * Test if ip is IPv6 - * @param string $ip - * @return boolean - */ - private function is_ipv6($ip) { - // If it contains anything other than hex characters, periods, colons or a / it's not IPV6 - if (!preg_match("/^([0-9a-f\.\/:]+)$/",strtolower($ip))) { return false; } - - // An IPV6 address needs at minimum two colons in it - if (substr_count($ip,":") < 2) { return false; } - - // If any of the "octets" are longer than 4 characters it's not valid - $part = preg_split("/[:\/]/",$ip); - foreach ($part as $i) { if (strlen($i) > 4) { return false; } } - - return true; - } }