/**
  * Gets the next available address in this address pool.
  *
  * @return the next available address
  */
 public InetAddress getNextAvailableAddress() {
   if (freeList != null) {
     BigInteger next = freeList.getNextFree();
     if (next != null) {
       try {
         InetAddress ip = InetAddress.getByAddress(next.toByteArray());
         int pingCheckTimeout =
             DhcpServerPolicies.globalPolicyAsInt(Property.V4_PINGCHECK_TIMEOUT);
         if (pingCheckTimeout > 0) {
           try {
             if (ip.isReachable(pingCheckTimeout)) {
               log.warn("Next free address answered ping check: " + ip.getHostAddress());
               setUsed(ip);
               return getNextAvailableAddress(); // try again
             }
           } catch (IOException ex) {
             log.error("Failed to perform v4 ping check: " + ex);
           }
         }
         return ip;
       } catch (UnknownHostException ex) {
         log.error("Unable to build IPv4 address from next free: " + ex);
       }
     }
   }
   return null;
 }
Example #2
0
 @Override
 public InetAddress getNextAvailableAddress() {
   InetAddress result = null;
   if (freeList != null) {
     BigInteger start = new BigInteger(subnet.getSubnetAddress().getAddress());
     BigInteger next = freeList.getNextFree();
     if (next != null) {
       // TODO: if there are no more free addresses, then find one
       //		that has been released or has been expired
       try {
         BigInteger prefix = next.multiply(calculatePrefix());
         result = InetAddress.getByAddress(start.add(prefix).toByteArray());
       } catch (Exception ex) {
         log.error("Unable to build IPv6 prefix from next free: " + ex);
       }
     }
   }
   return result;
 }