diff options
| author | czaks <marcin@6irc.net> | 2014-07-06 03:50:16 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2014-07-06 03:50:16 +0200 |
| commit | 4a0c87c7e119804cd180ce116b1af3961f24290b (patch) | |
| tree | 939374838148960e2ce3110b5f674e06bf94b2c4 /inc/lib/IP | |
| parent | 4881575b392d22f13b3d3f2249277d9e660568ba (diff) | |
Revert "Update jQuery UI to 1.11.0, GeoIPv6 and IP library"
This reverts commit dca7570b32c6d17024684f99371b0659d785b02e.
Diffstat (limited to 'inc/lib/IP')
| -rwxr-xr-x | inc/lib/IP/Lifo/IP/CIDR.php | 30 | ||||
| -rwxr-xr-x | inc/lib/IP/Lifo/IP/IP.php | 44 |
2 files changed, 21 insertions, 53 deletions
diff --git a/inc/lib/IP/Lifo/IP/CIDR.php b/inc/lib/IP/Lifo/IP/CIDR.php index 5ed92f93..e8fe32ce 100755 --- a/inc/lib/IP/Lifo/IP/CIDR.php +++ b/inc/lib/IP/Lifo/IP/CIDR.php @@ -254,9 +254,7 @@ class CIDR * and the starting IP is not on a valid network boundrary (eg: Displaying * an IP from an interface). * - * <b>Note: The CIDR block returned is NOT always bit aligned.</b> - * - * @return string IP in CIDR notation "start_ip/prefix" + * @return string IP in CIDR notation "ipaddr/prefix" */ public function getCidr() { @@ -264,22 +262,6 @@ class CIDR } /** - * Get the TRUE cidr notation for the subnet block. - * - * This is useful for when you want a string representation of the IP/prefix - * and the starting IP is not on a valid network boundrary (eg: Displaying - * an IP from an interface). - * - * <b>Note: The CIDR block returned is ALWAYS bit aligned.</b> - * - * @return string IP in CIDR notation "network/prefix" - */ - public function getTrueCidr() - { - return $this->getNetwork() . '/' . $this->prefix; - } - - /** * Get the [low,high] range of the CIDR block * * Prefix sensitive. @@ -400,9 +382,8 @@ class CIDR { // use fixed length HEX strings so we can easily do STRING comparisons // instead of using slower bccomp() math. - $map = function($v){ return sprintf("%032s", IP::inet_ptoh($v)); }; - list($lo,$hi) = array_map($map, CIDR::cidr_to_range($ip)); - list($min,$max) = array_map($map, CIDR::cidr_to_range($cidr)); + list($lo,$hi) = array_map(function($v){ return sprintf("%032s", IP::inet_ptoh($v)); }, CIDR::cidr_to_range($ip)); + list($min,$max) = array_map(function($v){ return sprintf("%032s", IP::inet_ptoh($v)); }, CIDR::cidr_to_range($cidr)); /** visualization of logic used below lo-hi = $ip to check @@ -466,8 +447,7 @@ class CIDR } // force bit length to 32 or 128 depending on type of IP - $version = IP::isIPv4($ip) ? 4 : 6; - $bitlen = $version == 4 ? 32 : 128; + $bitlen = (false === filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ? 128 : 32; if ($bits === null) { // if no prefix is given use the length of the binary string which @@ -489,7 +469,7 @@ class CIDR // calculate "broadcast" (not technically a broadcast in IPv6) $ip2 = BC::bcor($ip1, BC::bcnot($netmask)); - return array(IP::inet_dtop($ip1, $version), IP::inet_dtop($ip2, $version)); + return array(IP::inet_dtop($ip1), IP::inet_dtop($ip2)); } /** diff --git a/inc/lib/IP/Lifo/IP/IP.php b/inc/lib/IP/Lifo/IP/IP.php index 1af587ff..4d22aa76 100755 --- a/inc/lib/IP/Lifo/IP/IP.php +++ b/inc/lib/IP/Lifo/IP/IP.php @@ -26,10 +26,6 @@ abstract class IP { // shortcut for IPv4 addresses if (strpos($ip, ':') === false && strpos($ip, '.') !== false) { - // remove any cidr block notation - if (($o = strpos($ip, '/')) !== false) { - $ip = substr($ip, 0, $o); - } return sprintf('%u', ip2long($ip)); } @@ -59,11 +55,8 @@ abstract class IP /** * Convert a decimal string into a human readable IP address. - * - * @param decimal $decimal Decimal number to convert into presentational IP string. - * @param integer $version Force IP version to 4 or 6. Leave null for automatic. */ - public static function inet_dtop($decimal, $version = null) + public static function inet_dtop($decimal, $expand = false) { $parts = array(); $parts[1] = bcdiv($decimal, '79228162514264337593543950336', 0); // >> 96 @@ -81,27 +74,25 @@ abstract class IP $part = (int) $part; } - if (!$version) { - // if the first 96bits is all zeros then we can safely assume we - // actually have an IPv4 address. Even though it's technically possible - // you're not really ever going to see an IPv6 address in the range: - // ::0 - ::ffff - // It's feasible to see an IPv6 address of "::", in which case the - // caller is going to have to account for that on their own (or - // pass $version to this function). - if (($parts[1] | $parts[2] | $parts[3]) == 0) { - $version = 4; - } - } - - if ($version == 4) { + // if the first 96bits is all zeros then we can safely assume we + // actually have an IPv4 address. Even though it's technically possible + // you're not really ever going to see an IPv6 address in the range: + // ::0 - ::ffff + // It's feasible to see an IPv6 address of "::", in which case the + // caller is going to have to account for that on their own. + if (($parts[1] | $parts[2] | $parts[3]) == 0) { $ip = long2ip($parts[4]); } else { $packed = pack('N4', $parts[1], $parts[2], $parts[3], $parts[4]); $ip = inet_ntop($packed); } - return $ip; + // Turn IPv6 to IPv4 if it's IPv4 + if (preg_match('/^::\d+\./', $ip)) { + return substr($ip, 2); + } + + return $expand ? self::inet_expand($ip) : $ip; } /** @@ -116,11 +107,8 @@ abstract class IP /** * Convert a human readable (presentational) IP address into a BINARY string. */ - public static function inet_ptob($ip, $bits = null) + public static function inet_ptob($ip, $bits = 128) { - if ($bits === null) { - $bits = self::isIPv4($ip) ? 32 : 128; - } return BC::bcdecbin(self::inet_ptod($ip), $bits); } @@ -169,7 +157,7 @@ abstract class IP * One use-case for this is IP 6to4 tunnels used in networking. * * @example - * to_ipv6("10.10.10.10") == a0a:a0a + * to_ipv4("10.10.10.10") == a0a:a0a * * @param string $ip IPv4 address. * @param boolean $mapped If true a Full IPv6 address is returned within the |
