some fixes
[PHP-P10.git] / Uplink / IPAddr.class.php
index 217fbe727dfbecb7951d51b86329694925b11801..661a8e209ac694230b790a261c92da3c60b3d2e4 100644 (file)
@@ -34,7 +34,7 @@ class IPAddr {
        
        public function __construct($initial_value) {
                for($i = 0; $i < 8; $i++) {
-                       $ip6[$i] = 0;
+                       $this->ip6[$i] = 0;
                }
                if($initial_value == null) {
                        //nothing
@@ -49,7 +49,7 @@ class IPAddr {
        
        public function parseNumeric($numeric) {
                if(strlen($numeric) == 6) { //IPv4
-                       $value = self::numToInt($numeric);
+                       $value = Numerics::numToInt($numeric);
                        $this->ip6[6] = ($value & 0xffff0000) >> 16;
                        $this->ip6[7] = ($value & 0x0000ffff);
                        $this->addr_is_ipv6 = false;
@@ -60,12 +60,14 @@ class IPAddr {
                                        $rightBlocks = (strlen($numeric) - $i - 1) / 3;
                                        $skipBlocks = 8 - $j - $rightBlocks;
                                        $j += $skipBlocks;
+                                       $i++;
                                } else {
-                                       $value = self::numToInt($numeric[$i].$numeric[$i+1].$numeric[$i+2]);
+                                       $value = Numerics::numToInt($numeric[$i].$numeric[$i+1].$numeric[$i+2]);
                                        $this->ip6[$j++] = dechex($value);
                                        $i += 3;
                                }
                        }
+                       $this->addr_is_ipv6 = true;
                }
        }
        
@@ -82,6 +84,7 @@ class IPAddr {
                                $this->ip6[$j++] = hexdec($block);
                        }
                }
+               $this->addr_is_ipv6 = true;
        }
        
        public function parseIPv4($ipv4) {
@@ -90,6 +93,7 @@ class IPAddr {
                $this->ip6[6] |= intval($ipv4blocks[1]);
                $this->ip6[7] = intval($ipv4blocks[2]) << 8;
                $this->ip6[7] |= intval($ipv4blocks[3]);
+               $this->addr_is_ipv6 = false;
        }
        
        public function isIPv6() {