private function allocateNetwork($cParent, $iLevel, $iValue, $iSize)
 {
     $iRet = IP6_ERR_OK;
     // Build the address
     $cAddr = new CAddress($cParent->getAddress()->toStr());
     $cAddr->setBits($cParent->getPrefix() + 1, $iValue, $iSize);
     // Create the subnet
     $cNet = new CNetwork($cAddr, $cParent->getPrefix() + $iSize);
     $cNet->setLevel($iLevel);
     $cNet->setSubnets(NULL);
     $cNet->setNext(NULL);
     // Link the network into its parents subnet list
     if ($cParent->getSubnets()) {
         $cSubnets = $cParent->getSubnets();
         for (; $cSubnets; $cSubnets = $cSubnets->getNext()) {
             if (!$cSubnets->getNext()) {
                 $cSubnets->setNext($cNet);
                 break;
             }
         }
     } else {
         $cParent->setSubnets($cNet);
     }
     return $iRet;
 }
Example #2
0
 function compressAddr($sAddress)
 {
     $vRet = IP6_ERR_OK;
     $cAddress = new CAddress();
     // Address must be a string
     if (is_string($sAddress)) {
         // Check that the address is valid
         if (isValidAddr($sAddress)) {
             // Convert the address to a raw address
             $vRet = $cAddress . fromStr($sAddress);
             if ($vRet == IP6_ERR_OK) {
                 // Convert the address back to a string and compress it
                 $vRet = $cAddress->toStr(true);
             }
         } else {
             $vRet = IP6_ERR_BADADDR;
         }
     } else {
         $vRet = IP6_ERR_BADARG;
     }
     return $vRet;
 }