code: public static boolean sameNetwork(int prefixLength, InetAddress address1, InetAddress address2) {
          if (logger.isDebugEnabled()) {
              logger.debug("Comparing address " + address1.getHostAddress() + " with " + address2.getHostAddress() + ", prefixLength=" + prefixLength);
          }
          long prefixMask = 0xffffffffL & (-1 << (32 - prefixLength));
          return (addressToLong(address1) & prefixMask) == (addressToLong(address2) & prefixMask);
      }
docs: Checks whether two internet addresses are on the same subnet.
  
  @param prefixLength the number of bits within an address that identify the network
  @param address1 the first address to be compared
  @param address2 the second address to be compared
  
  @return true if both addresses share the same network bits