Exemplo n.º 1
0
 /**
  * \brief Compute the first and the last address of a network.
  * That is usefull, for instance, to compute the "real" network address (the first address)
  * or the broadcast address of the network
  *
  * @param $address                              (see \ref parameterType) the address of the network
  * @param $netmask                              (see \ref parameterType) its netmask
  * @param $firstAddress                         (see \ref parameterType - in/out)
  *                                              the first address (ie real address of the network)
  * @param $lastAddress                          (see \ref parameterType - in/out)
  *                                              the lastAddress of the network
  *                                              (ie. : the broadcast address) (default NULL)
  * @param $excludeBroadcastAndNetwork  boolean  exclude broadcast and network address from the
  *                                              result (false by default)
  **/
 static function computeNetworkRangeFromAdressAndNetmask($address, $netmask, &$firstAddress, &$lastAddress = NULL, $excludeBroadcastAndNetwork = false)
 {
     if ($address instanceof IPAddress) {
         $address = $address->getBinary();
     }
     if ($netmask instanceof IPNetmask) {
         $netmask = $netmask->getBinary();
     }
     $start = array();
     $end = array();
     for ($i = 0; $i < 4; ++$i) {
         $start[$i] = IPAddress::convertNegativeIntegerToPositiveFloat($address[$i] & $netmask[$i]);
         $end[$i] = IPAddress::convertNegativeIntegerToPositiveFloat($address[$i] | ~$netmask[$i]);
     }
     if ($excludeBroadcastAndNetwork) {
         IPAddress::addValueToAddress($start, 1);
         IPAddress::addValueToAddress($end, -1);
     }
     if ($firstAddress instanceof IPAddress) {
         $firstAddress->setAddressFromBinary($start);
     } else {
         $firstAddress = $start;
     }
     if ($lastAddress instanceof IPAddress) {
         $lastAddress->setAddressFromBinary($end);
     } else {
         $lastAddress = $end;
     }
 }