1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[ticket/11765] Support IPv4 embedded IPv6 addresses in short_ipv6()

PHPBB3-11765
This commit is contained in:
Marc Alexander
2023-07-26 17:21:43 +02:00
parent 0ede362120
commit 56f0846378
2 changed files with 58 additions and 1 deletions

View File

@@ -2918,7 +2918,7 @@ function get_censor_preg_expression($word)
/**
* Returns the first block of the specified IPv6 address and as many additional
* ones as specified in the length paramater.
* ones as specified in the length parameter.
* If length is zero, then an empty string is returned.
* If length is greater than 3 the complete IP will be returned
*/
@@ -2929,6 +2929,14 @@ function short_ipv6($ip, $length)
return '';
}
// Handle IPv4 embedded IPv6 addresses
if (preg_match('/(?:\d{1,3}\.){3}\d{1,3}$/i', $ip))
{
$binary_ip = inet_pton($ip);
$ip_v6 = $binary_ip ? inet_ntop($binary_ip) : $ip;
$ip = $ip_v6 ?: $ip;
}
// extend IPv6 addresses
$blocks = substr_count($ip, ':') + 1;
if ($blocks < 9)