Example #1
0
  public static IP4Address next(IP4Address address) throws UnknownHostException {
    byte[] addr = address.toByteArray();

    int i = addr.length - 1;
    while (i >= 0 && addr[i] == (byte) 0xff) {
      addr[i] = 0;
      i--;
    }

    if (i >= 0) {
      addr[i]++;
      return new IP4Address(addr);
    } else return null;
  }
    @Override
    public void run() {
      Logger.debug("UdpProber started ...");

      mStopped = false;

      int i, nhosts = 0;
      IP4Address current = null;

      try {
        mNetwork = System.getNetwork();
        nhosts = mNetwork.getNumberOfAddresses();
      } catch (Exception e) {
        System.errorLogging(e);
      }

      while (!mStopped && mNetwork != null && nhosts > 0) {
        try {
          for (i = 1, current = IP4Address.next(mNetwork.getStartAddress());
              current != null && i <= nhosts;
              current = IP4Address.next(current), i++) {
            // rescanning the gateway could cause an issue when the gateway itself has multiple
            // interfaces ( LAN, WAN ... )
            if (!current.equals(mNetwork.getGatewayAddress())
                && !current.equals(mNetwork.getLocalAddress())) {
              InetAddress address = current.toInetAddress();

              try {
                mExecutor.execute(new SingleProber(address));
              } catch (RejectedExecutionException e) {
                // ignore since this is happening because the executor was shut down.
                break;
              } catch (OutOfMemoryError m) {
                // wait until the thread queue gets freed
                break;
              }
            }
          }

          Thread.sleep(1000);
        } catch (Exception e) {
        }
      }
    }
Example #3
0
 public boolean equals(IP4Address address) {
   return mInteger == address.toInteger();
 }