Esempio n. 1
0
 /**
  * Determine whether address is in the given subnet
  *
  * @param   string net
  * @return  bool
  * @throws  lang.FormatException in case net has invalid format
  */
 public function inSubnet(Network $net)
 {
     if (!$net->getAddress() instanceof self) {
         return false;
     }
     $addrn = $net->getAddress()->addr;
     $mask = $net->getNetmask();
     return $this->addr >> 32 - $mask == $addrn >> 32 - $mask;
 }
Esempio n. 2
0
 /**
  * Determine whether address is in the given subnet
  *
  * @param   string net
  * @return  bool
  * @throws  lang.FormatException in case net has invalid format
  */
 public function inSubnet(Network $net)
 {
     $addr = $net->getAddress();
     $mask = $net->getNetmask();
     $position = 0;
     while ($mask > 8) {
         if ($addr->addr[$position] != $this->addr[$position]) {
             return false;
         }
         $position++;
         $mask -= 8;
     }
     if ($mask > 0) {
         return ord($addr->addr[$position]) >> 8 - $mask == ord($this->addr[$position]) >> 8 - $mask;
     }
     return true;
 }