Changeset 888 for trunk/Packages/Common/NetworkAddress.php
- Timestamp:
- Nov 24, 2020, 10:58:56 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/NetworkAddress.php
r874 r888 5 5 class NetworkAddressIPv4 6 6 { 7 var$Address;8 var$Prefix;7 public int $Address; 8 public int $Prefix; 9 9 10 10 function __construct() … … 14 14 } 15 15 16 function GetNetMask() 16 function GetNetMask(): int 17 17 { 18 18 return ((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1); 19 19 } 20 20 21 function AddressToString() 21 function AddressToString(): string 22 22 { 23 23 return implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))); 24 24 } 25 25 26 function AddressFromString( $Value)26 function AddressFromString(string $Value): void 27 27 { 28 28 $Parts = explode('.', $Value); … … 30 30 } 31 31 32 function GetRange() 32 function GetRange(): array 33 33 { 34 34 $From = new NetworkAddressIPv4(); … … 42 42 } 43 43 44 function ChangePrefix( $NewPrefix)44 function ChangePrefix(int $NewPrefix): void 45 45 { 46 46 $this->Prefix = $NewPrefix; … … 50 50 } 51 51 52 function Contain( $Address)52 function Contain(NetworkAddressIPv4 $Address): bool 53 53 { 54 54 $UpperNetmask = $this->GetNetMask(); … … 63 63 class NetworkAddressIPv6 64 64 { 65 var$Address;66 var$Prefix;65 public string $Address; 66 public int $Prefix; 67 67 68 68 function __construct() … … 72 72 } 73 73 74 function GetNetMask() 74 function GetNetMask(): string 75 75 { 76 76 return Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)), … … 78 78 } 79 79 80 function AddressToString() 80 function AddressToString(): string 81 81 { 82 82 return inet_ntop($this->Address); 83 83 } 84 84 85 function AddressFromString( $Value)85 function AddressFromString(string $Value) 86 86 { 87 87 $this->Address = inet_pton($Value); 88 88 } 89 89 90 function ChangePrefix( $NewPrefix)90 function ChangePrefix(int $NewPrefix): void 91 91 { 92 92 $this->Prefix = $NewPrefix; … … 96 96 } 97 97 98 function GetOctets() 98 function GetOctets(): array 99 99 { 100 100 $Result = array(); … … 109 109 } 110 110 111 function EncodeMAC( $MAC)111 function EncodeMAC(string $MAC): void 112 112 { 113 113 $MAC = explode(':', $MAC); … … 124 124 } 125 125 126 function Contain( $Address)126 function Contain(NetworkAddressIPv6 $Address): bool 127 127 { 128 128 $UpperNetmask = $this->GetNetMask();
Note:
See TracChangeset
for help on using the changeset viewer.