Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 3 namespace GeoIp2; 4 5 class Util 6 { 7 /** 8 * This returns the network in CIDR notation for the given IP and prefix 9 * length. This is for internal use only. 10 * 11 * @internal 12 * @ignore 13 * 14 * @param mixed $ipAddress 15 * @param mixed $prefixLen 16 */ 17 public static function cidr($ipAddress, $prefixLen) 18 { 19 $ipBytes = inet_pton($ipAddress); 20 $networkBytes = str_repeat("\0", \strlen($ipBytes)); 21 22 $curPrefix = $prefixLen; 23 for ($i = 0; $i < \strlen($ipBytes) && $curPrefix > 0; $i++) { 24 $b = $ipBytes[$i]; 25 if ($curPrefix < 8) { 26 $shiftN = 8 - $curPrefix; 27 $b = \chr(0xFF & (\ord($b) >> $shiftN) << $shiftN); 28 } 29 $networkBytes[$i] = $b; 30 $curPrefix -= 8; 31 } 32 33 $network = inet_ntop($networkBytes); 34 35 return "$network/$prefixLen"; 36 } 37 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body