Changeset 873 for trunk/Packages/Common/NetworkAddress.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/NetworkAddress.php
r870 r873 16 16 function GetNetMask() 17 17 { 18 return (((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1));18 return (((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1)); 19 19 } 20 20 21 21 function AddressToString() 22 22 { 23 return (implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))));23 return (implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255)))); 24 24 } 25 25 … … 39 39 $To->Address = $From->Address + $HostMask; 40 40 $To->Prefix = IPV4_BIT_WIDTH; 41 return (array('From' => $From, 'To' => $To));41 return (array('From' => $From, 'To' => $To)); 42 42 } 43 43 … … 45 45 { 46 46 $this->Prefix = $NewPrefix; 47 if ($this->Prefix > IPV4_BIT_WIDTH) $this->Prefix = IPV4_BIT_WIDTH;48 if ($this->Prefix < 0) $this->Prefix = 0;47 if ($this->Prefix > IPV4_BIT_WIDTH) $this->Prefix = IPV4_BIT_WIDTH; 48 if ($this->Prefix < 0) $this->Prefix = 0; 49 49 $this->Address = $this->Address & $this->GetNetMask(); 50 50 } … … 53 53 { 54 54 $UpperNetmask = $this->GetNetMask(); 55 if (($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true;55 if (($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true; 56 56 else $Result = false; 57 return ($Result);57 return ($Result); 58 58 } 59 59 } … … 74 74 function GetNetMask() 75 75 { 76 return (Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)),76 return (Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)), 77 77 Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH - $this->Prefix)), IntToInt128(1)))); 78 78 } … … 80 80 function AddressToString() 81 81 { 82 return (inet_ntop($this->Address));82 return (inet_ntop($this->Address)); 83 83 } 84 84 … … 91 91 { 92 92 $this->Prefix = $NewPrefix; 93 if ($this->Prefix > IPV6_BIT_WIDTH) $this->Prefix = IPV6_BIT_WIDTH;94 if ($this->Prefix < 0) $this->Prefix = 0;93 if ($this->Prefix > IPV6_BIT_WIDTH) $this->Prefix = IPV6_BIT_WIDTH; 94 if ($this->Prefix < 0) $this->Prefix = 0; 95 95 $this->Address = Int128And($this->Address, $this->GetNetMask()); 96 96 } … … 100 100 $Result = array(); 101 101 $Data = array_reverse(unpack('C*', $this->Address)); 102 foreach ($Data as $Item)102 foreach ($Data as $Item) 103 103 { 104 104 … … 106 106 $Result[] = dechex(($Item >> 4) & 15); 107 107 } 108 return ($Result);108 return ($Result); 109 109 } 110 110 … … 127 127 { 128 128 $UpperNetmask = $this->GetNetMask(); 129 if (($this->Prefix < $Address->Prefix) and ((Int128Equal(Int128And($Address->Address, $UpperNetmask), Int128And($this->Address, $UpperNetmask))))) $Result = true;129 if (($this->Prefix < $Address->Prefix) and ((Int128Equal(Int128And($Address->Address, $UpperNetmask), Int128And($this->Address, $UpperNetmask))))) $Result = true; 130 130 else $Result = false; 131 return ($Result);131 return ($Result); 132 132 } 133 133 }
Note:
See TracChangeset
for help on using the changeset viewer.