2 declare(strict_types = 1);
48 1 =>
'ffff:ffff:ffff:ffff:0000:0000:0000:0000',
49 2 =>
'ffff:ffff:ffff:0000:0000:0000:0000:0000',
60 public static function anonymizeIp(
string $address,
int $mask =
null): string
63 $mask = (int)
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'ipAnonymization'];
65 if ($mask < 0 || $mask > 2) {
66 throw new \UnexpectedValueException(sprintf(
'The provided value "%d" is not an allowed value for the IP mask.', $mask), 1519739203);
71 if (empty($address)) {
75 $packedAddress = @inet_pton($address);
76 if ($packedAddress ===
false) {
79 $length = strlen($packedAddress);
82 $bitMask = self::MASKV4[$mask];
83 } elseif ($length === 16) {
84 $bitMask = self::MASKV6[$mask];
88 return inet_ntop($packedAddress & inet_pton($bitMask));