From bd120bbda7410dde85088412ba18f1db83fdeb3a Mon Sep 17 00:00:00 2001 From: discomrade Date: Thu, 14 Oct 2021 07:04:26 +0000 Subject: [PATCH] Clean up duplicate code for IPv6 --- inc/functions.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 09072999..93938923 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -12,6 +12,8 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) { $microtime_start = microtime(true); +use Lifo\IP\IP; // for expanding IPv6 address in DNSBL() + // the user is not currently logged in as a moderator $mod = false; @@ -2271,23 +2273,7 @@ function ReverseIPv4Octets($ip) { } function ReverseIPv6Octets($ip) { - return strrev(implode(".", str_split(str_replace(':', '', inet_expand($ip))))); -} - -// copypastad from lib/IP/Lifo/IP.php, TODO replace this with a proper include -function inet_expand($ip) -{ - // strip possible cidr notation off - if (($pos = strpos($ip, '/')) !== false) { - $ip = substr($ip, 0, $pos); - } - $bytes = unpack('n*', inet_pton($ip)); - if (count($bytes) > 2) { - return implode(':', array_map(function ($b) { - return sprintf("%04x", $b); - }, $bytes)); - } - return $ip; + return strrev(implode(".", str_split(str_replace(':', '', IP::inet_expand($ip))))); } function wordfilters(&$body) {