/** * Create an IPv6 network from the two addresses within the network. This will construct the smallest possible network ("longest prefix * length") which contains both addresses. * * @param one address one * @param two address two, should be bigger than address one * @return ipv6 network */ public static IPv6Network fromTwoAddresses(IPv6Address one, IPv6Address two) { final IPv6NetworkMask longestPrefixLength = IPv6NetworkMask.fromPrefixLength(IPv6NetworkHelpers.longestPrefixLength(one, two)); return new IPv6Network(one.maskWithNetworkMask(longestPrefixLength), longestPrefixLength); }
static int longestPrefixLength(IPv6Address first, IPv6Address last) { final BitSet firstBits = bitSetOf(first.getLowBits(), first.getHighBits()); final BitSet lastBits = bitSetOf(last.getLowBits(), last.getHighBits()); return countLeadingSimilarBits(firstBits, lastBits); }
static int longestPrefixLength(IPv6Address first, IPv6Address last) { final BitSet firstBits = bitSetOf(first.getLowBits(), first.getHighBits()); final BitSet lastBits = bitSetOf(last.getLowBits(), last.getHighBits()); return countLeadingSimilarBits(firstBits, lastBits); }
/** * Create an IPv6 network from the two addresses within the network. This will construct the smallest possible network ("longest prefix * length") which contains both addresses. * * @param one address one * @param two address two, should be bigger than address one * @return ipv6 network */ public static IPv6Network fromTwoAddresses(IPv6Address one, IPv6Address two) { final IPv6NetworkMask longestPrefixLength = IPv6NetworkMask.fromPrefixLength(IPv6NetworkHelpers.longestPrefixLength(one, two)); return new IPv6Network(one.maskWithNetworkMask(longestPrefixLength), longestPrefixLength); }