Changeset 880 for trunk/Packages/Common/NetworkAddress.php
- Timestamp:
- Apr 7, 2020, 10:15:48 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/NetworkAddress.php
r861 r880 14 14 function GetNetMask() 15 15 { 16 return (0xffffffff ^ ((1 << (32 - $this->Prefix)) - 1));16 return 0xffffffff ^ ((1 << (32 - $this->Prefix)) - 1); 17 17 } 18 18 19 19 function AddressToString() 20 20 { 21 return (implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))));21 return implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))); 22 22 } 23 23 … … 37 37 $To->Address = $From->Address + $HostMask; 38 38 $To->Prefix = 32; 39 return (array('From' => $From, 'To' => $To));39 return array('From' => $From, 'To' => $To); 40 40 } 41 41 … … 43 43 { 44 44 $this->Prefix = $NewPrefix; 45 if ($this->Prefix > 32) $this->Prefix = 32;46 if ($this->Prefix < 0) $this->Prefix = 0;45 if ($this->Prefix > 32) $this->Prefix = 32; 46 if ($this->Prefix < 0) $this->Prefix = 0; 47 47 $this->Address = $this->Address & $this->GetNetMask(); 48 48 } … … 51 51 { 52 52 $UpperNetmask = $this->GetNetMask(); 53 if (($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true;53 if (($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true; 54 54 else $Result = false; 55 55 //echo($Address->AddressToString().'/'.$Address->Prefix.' in '.$this->AddressToString().'/'.$this->Prefix.' '.$Result."\n"); 56 return ($Result);56 return $Result; 57 57 } 58 58 } … … 71 71 function AddressToString() 72 72 { 73 return (inet_ntop($this->Address));73 return inet_ntop($this->Address); 74 74 } 75 75 … … 83 83 $Result = array(); 84 84 $Data = array_reverse(unpack('C*', $this->Address)); 85 foreach ($Data as $Item)85 foreach ($Data as $Item) 86 86 { 87 87 … … 89 89 $Result[] = dechex(($Item >> 4) & 15); 90 90 } 91 return ($Result);91 return $Result; 92 92 } 93 93
Note:
See TracChangeset
for help on using the changeset viewer.