private static Keeper keepOneInterface(InetAddress addr, int port) {
    ServerSocket server = null;
    try {
      // (new Exception("Opening server socket on " + port)).printStackTrace();
      server = new ServerSocket();
      server.setReuseAddress(true);
      if (addr != null) {
        server.bind(new InetSocketAddress(addr, port));
      } else {
        server.bind(new InetSocketAddress(port));
      }
      Keeper result = new Keeper(server, port);
      server = null;
      return result;
    } catch (java.io.IOException ioe) {
      if (ioe.getMessage().equals("Network is unreachable")) {
        throw new RuntimeException("Network is unreachable");
      }
      // ioe.printStackTrace();
      if (addr instanceof Inet6Address) {
        byte[] addrBytes = addr.getAddress();
        if ((addrBytes[0] == (byte) 0xfe) && (addrBytes[1] == (byte) 0x80)) {
          // Hack, early Sun 1.5 versions (like Hitachi's JVM) cannot handle IPv6
          // link local addresses. Cannot trust InetAddress.isLinkLocalAddress()
          // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6558853
          // By returning true we ignore these interfaces and potentially say a
          // port is not in use when it really is.
          Keeper result = new Keeper(server, port);
          server = null;
          return result;
        }
      }
      return null;
    } catch (Exception ex) {
      return null;
    } finally {
      if (server != null) {
        try {
          server.close();
        } catch (Exception ignored) {
        }
      }
    }
  }
Returns whether or not the given port on the local host is available (that is, unused).

@param port The port to check
@param protocol The protocol to check (either {@link #SOCKET} or {@link #MULTICAST}).
@param addr the bind address (or mcast address) to use
@throws IllegalArgumentException <code>protocol</code> is unknown
geode-membership/src/main/java/org/apache/geode/internal/membership/utils/AvailablePort.java