1 | <?php |
||
12 | class Block extends Range |
||
13 | { |
||
14 | /** |
||
15 | * @var \JAAulde\IP\V4\SubnetMask The subnet mask of the represented block |
||
16 | */ |
||
17 | protected $subnetMask; |
||
18 | |||
19 | /** |
||
20 | * Constructor |
||
21 | * |
||
22 | * @param \JAAulde\IP\V4\Address|string $a1 The base address with which the network and broadcast addresses of this block will be calculated. This can be an |
||
23 | * an instance of \JAAulde\IP\V4\Address, in which case the second parameter will be required, or a string in dot-notated format with optional CIDR |
||
24 | * slash prefix. If a string without CIDR slash prefix, second parameter is required. If there is a CIDR slash prefix, second parameter will be ignored. |
||
25 | * @param \JAAulde\IP\V4\SubnetMask|int|string|\JAAulde\IP\V4\Address $a2 Optional depending on what was given as the first parameter. This is a subnet mask |
||
26 | * to determine the size of this block, or a CIDR prefix for calculating a subnet mask, or a second \JAAulde\IP\V4\Address instance to fit into the derived |
||
27 | * block. |
||
28 | * |
||
29 | * @throws Exception |
||
30 | */ |
||
31 | public function __construct($a1, $a2 = null) |
||
69 | |||
70 | /** |
||
71 | * Determine if a given IPV4 address is this block's network address (first address in range). |
||
72 | * |
||
73 | * @param \JAAulde\IP\V4\Address $address The address we want to know about |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function isNetworkAddress(Address $address) |
||
81 | |||
82 | /** |
||
83 | * Determine if a given IPV4 address is this block's broadcast address (last address in range). |
||
84 | * |
||
85 | * @param \JAAulde\IP\V4\Address $address The address we want to know about |
||
86 | * |
||
87 | * @return bool |
||
88 | */ |
||
89 | public function isBroadcastAddress(Address $address) |
||
93 | |||
94 | /** |
||
95 | * Retrieve the block's network address (first address in range) (Alias to \JAAulde\IP\V4\Range::getFirstAddress). |
||
96 | * |
||
97 | * @uses \JAAulde\IP\V4\Range::getFirstAddress |
||
98 | * |
||
99 | * @return \JAAulde\IP\V4\Address |
||
100 | */ |
||
101 | public function getNetworkAddress() |
||
105 | |||
106 | /** |
||
107 | * Retrieve the block's broadcast address (last address in range). (Alias to \JAAulde\IP\V4\Range::getLastAddress). |
||
108 | * |
||
109 | * @uses \JAAulde\IP\V4\Range::getLastAddress |
||
110 | * |
||
111 | * @return \JAAulde\IP\V4\Address |
||
112 | */ |
||
113 | public function getBroadcastAddress() |
||
117 | |||
118 | /** |
||
119 | * Retrieve the block's subnet mask. |
||
120 | * |
||
121 | * @return \JAAulde\IP\V4\SubnetMask |
||
122 | */ |
||
123 | public function getSubnetMask() |
||
127 | |||
128 | /** |
||
129 | * Retrieve the total number of IPV4 addresses represented in this block. |
||
130 | * |
||
131 | * @return int |
||
132 | */ |
||
133 | public function getAddressCount() |
||
137 | |||
138 | /** |
||
139 | * Retrieve the total number of usable IPV4 addresses represented in this block. |
||
140 | * |
||
141 | * The total number of usable addresses is generally considered to be 2 less than the total number represented by the block. |
||
142 | * This accounts for the fact that the first and last addresses in a block are used for the network and broadcast addresses. |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | public function getUsableAddressCount() |
||
150 | |||
151 | /** |
||
152 | * Calculate the network address of a Block given an IPV4 network address and SubnetMask. |
||
153 | * |
||
154 | * @param \JAAulde\IP\V4\Address $address The IP address from which a network address will be derived |
||
155 | * @param \JAAulde\IP\V4\SubnetMask $subnetMask The subnet mask (in address form) used in the derivation |
||
156 | * |
||
157 | * @return \JAAulde\IP\V4\Address |
||
158 | */ |
||
159 | public static function calculateNetworkAddress(Address $address, SubnetMask $subnetMask) |
||
163 | |||
164 | /** |
||
165 | * Calculate the broadcast address of a Block given an IPV4 network address and SubnetMask. |
||
166 | * |
||
167 | * @param \JAAulde\IP\V4\Address $address The IP address from which a broadcast address will be derived |
||
168 | * @param \JAAulde\IP\V4\SubnetMask $subnetMask The subnet mask (in address form) used in the derivation |
||
169 | * |
||
170 | * @return \JAAulde\IP\V4\Address |
||
171 | */ |
||
172 | public static function calculateBroadcastAddress(Address $address, SubnetMask $subnetMask) |
||
176 | } |
||
177 |