original_string: public static function cmpIPv6($baseIP, $list) {
  		$success = FALSE; // Policy default: Deny connection
  		$baseIP = self::normalizeIPv6($baseIP);
  
  		$values = self::trimExplode(',', $list, 1);
  		foreach ($values as $test) {
  			$testList = explode('/', $test);
  			if (count($testList) == 2) {
  				list($test, $mask) = $testList;
  			} else {
  				$mask = FALSE;
  			}
  
  			if (self::validIPv6($test)) {
  				$test = self::normalizeIPv6($test);
  				$maskInt = intval($mask) ? intval($mask) : 128;
  				if ($mask === '0') { // special case; /0 is an allowed mask - equals a wildcard
  					$success = TRUE;
  				} elseif ($maskInt == 128) {
  					$success = ($test === $baseIP);
  				} else {
  					$testBin = self::IPv6Hex2Bin($test);
  					$baseIPBin = self::IPv6Hex2Bin($baseIP);
  					$success = TRUE;
  
  					// modulo is 0 if this is a 8-bit-boundary
  					$maskIntModulo = $maskInt % 8;
  					$numFullCharactersUntilBoundary = intval($maskInt / 8);
  
  					if (substr($testBin, 0, $numFullCharactersUntilBoundary) !== substr($baseIPBin, 0, $numFullCharactersUntilBoundary)) {
  						$success = FALSE;
  					} elseif ($maskIntModulo > 0) {
  						// if not an 8-bit-boundary, check bits of last character
  						$testLastBits = str_pad(decbin(ord(substr($testBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT);
  						$baseIPLastBits = str_pad(decbin(ord(substr($baseIPBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT);
  						if (strncmp($testLastBits, $baseIPLastBits, $maskIntModulo) != 0) {
  							$success = FALSE;
  						}
  					}
  				}
  			}
  			if ($success) {
  				return TRUE;
  			}
  		}
  		return FALSE;
  	}
code: public static function cmpIPv6($baseIP, $list) {
  		$success = FALSE; // Policy default: Deny connection
  		$baseIP = self::normalizeIPv6($baseIP);
  
  		$values = self::trimExplode(',', $list, 1);
  		foreach ($values as $test) {
  			$testList = explode('/', $test);
  			if (count($testList) == 2) {
  				list($test, $mask) = $testList;
  			} else {
  				$mask = FALSE;
  			}
  
  			if (self::validIPv6($test)) {
  				$test = self::normalizeIPv6($test);
  				$maskInt = intval($mask) ? intval($mask) : 128;
  				if ($mask === '0') { // special case; /0 is an allowed mask - equals a wildcard
  					$success = TRUE;
  				} elseif ($maskInt == 128) {
  					$success = ($test === $baseIP);
  				} else {
  					$testBin = self::IPv6Hex2Bin($test);
  					$baseIPBin = self::IPv6Hex2Bin($baseIP);
  					$success = TRUE;
  
  					// modulo is 0 if this is a 8-bit-boundary
  					$maskIntModulo = $maskInt % 8;
  					$numFullCharactersUntilBoundary = intval($maskInt / 8);
  
  					if (substr($testBin, 0, $numFullCharactersUntilBoundary) !== substr($baseIPBin, 0, $numFullCharactersUntilBoundary)) {
  						$success = FALSE;
  					} elseif ($maskIntModulo > 0) {
  						// if not an 8-bit-boundary, check bits of last character
  						$testLastBits = str_pad(decbin(ord(substr($testBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT);
  						$baseIPLastBits = str_pad(decbin(ord(substr($baseIPBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT);
  						if (strncmp($testLastBits, $baseIPLastBits, $maskIntModulo) != 0) {
  							$success = FALSE;
  						}
  					}
  				}
  			}
  			if ($success) {
  				return TRUE;
  			}
  		}
  		return FALSE;
  	}
code_tokens: public static function cmpIPv6 ( $ baseIP , $ list ) { $ success = FALSE ; // Policy default: Deny connection $ baseIP = self :: normalizeIPv6 ( $ baseIP ) ; $ values = self :: trimExplode ( ',' , $ list , 1 ) ; foreach ( $ values as $ test ) { $ testList = explode ( '/' , $ test ) ; if ( count ( $ testList ) == 2 ) { list ( $ test , $ mask ) = $ testList ; } else { $ mask = FALSE ; } if ( self :: validIPv6 ( $ test ) ) { $ test = self :: normalizeIPv6 ( $ test ) ; $ maskInt = intval ( $ mask ) ? intval ( $ mask ) : 128 ; if ( $ mask === '0' ) { // special case; /0 is an allowed mask - equals a wildcard $ success = TRUE ; } elseif ( $ maskInt == 128 ) { $ success = ( $ test === $ baseIP ) ; } else { $ testBin = self :: IPv6Hex2Bin ( $ test ) ; $ baseIPBin = self :: IPv6Hex2Bin ( $ baseIP ) ; $ success = TRUE ; // modulo is 0 if this is a 8-bit-boundary $ maskIntModulo = $ maskInt % 8 ; $ numFullCharactersUntilBoundary = intval ( $ maskInt / 8 ) ; if ( substr ( $ testBin , 0 , $ numFullCharactersUntilBoundary ) !== substr ( $ baseIPBin , 0 , $ numFullCharactersUntilBoundary ) ) { $ success = FALSE ; } elseif ( $ maskIntModulo > 0 ) { // if not an 8-bit-boundary, check bits of last character $ testLastBits = str_pad ( decbin ( ord ( substr ( $ testBin , $ numFullCharactersUntilBoundary , 1 ) ) ) , 8 , '0' , STR_PAD_LEFT ) ; $ baseIPLastBits = str_pad ( decbin ( ord ( substr ( $ baseIPBin , $ numFullCharactersUntilBoundary , 1 ) ) ) , 8 , '0' , STR_PAD_LEFT ) ; if ( strncmp ( $ testLastBits , $ baseIPLastBits , $ maskIntModulo ) != 0 ) { $ success = FALSE ; } } } } if ( $ success ) { return TRUE ; } } return FALSE ; }
docstring: Match IPv6 address with a list of IPv6 prefixes
  
  @param string $baseIP is the current remote IP address for instance
  @param string $list is a comma-list of IPv6 prefixes, could also contain IPv4 addresses
  @return boolean TRUE if an baseIP matches any prefix
docstring_tokens: Match IPv6 address with a list of IPv6 prefixes