/** * Determines whether a given IP prefix is contained within this prefix. * * @param other the IP prefix to test * @return true if the other IP prefix is contained in this prefix, * otherwise false */ public boolean contains(IpPrefix other) { if (version() != other.version()) { return false; } if (this.prefixLength > other.prefixLength) { return false; // This prefix has smaller prefix size } // // Mask the other address with my prefix length. // If the other prefix is within this prefix, the masked address must // be same as the address of this prefix. // IpAddress maskedAddr = IpAddress.makeMaskedAddress(other.address, this.prefixLength); return this.address.equals(maskedAddr); }
/** * Determines whether a given IP address is contained within this prefix. * * @param other the IP address to test * @return true if the IP address is contained in this prefix, otherwise * false */ public boolean contains(IpAddress other) { if (version() != other.version()) { return false; } // // Mask the other address with my prefix length. // If the other prefix is within this prefix, the masked address must // be same as the address of this prefix. // IpAddress maskedAddr = IpAddress.makeMaskedAddress(other, this.prefixLength); return this.address.equals(maskedAddr); }