public static boolean isInetAddressInRange(final String addrString, final String beginString, final String endString) { final byte[] addr = InetAddressUtils.toIpAddrBytes(addrString); final byte[] begin = InetAddressUtils.toIpAddrBytes(beginString); if (s_BYTE_ARRAY_COMPARATOR.compare(addr, begin) > 0) { final byte[] end = InetAddressUtils.toIpAddrBytes(endString); return (s_BYTE_ARRAY_COMPARATOR.compare(addr, end) <= 0); } else if (s_BYTE_ARRAY_COMPARATOR.compare(addr, begin) == 0) { return true; } else { return false; } }
/** * Given a list of IP addresses, return the lowest as determined by the * numeric representation and not the alphanumeric string. * * @param addresses a {@link java.util.List} object. * @return a {@link java.net.InetAddress} object. */ public static InetAddress getLowestInetAddress(final List<InetAddress> addresses) { if (addresses == null) { throw new IllegalArgumentException("Cannot take null parameters."); } InetAddress lowest = null; // Start with the highest conceivable IP address value final byte[] originalBytes = toIpAddrBytes("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); byte[] lowestBytes = originalBytes; for (final InetAddress temp : addresses) { byte[] tempBytes = temp.getAddress(); if (s_BYTE_ARRAY_COMPARATOR.compare(tempBytes, lowestBytes) < 0) { lowestBytes = tempBytes; lowest = temp; } } return s_BYTE_ARRAY_COMPARATOR.compare(originalBytes, lowestBytes) == 0 ? null : lowest; }
/** * <P> * Creates a generator object that iterates over the range from start to * end, inclusive. * </P> * * @param start * The start address. * @param end * The ending address. * * @exception java.lang.IllegalArgumentException * Thrown if the start address is greater than the ending * address. * */ IPAddressRangeGenerator(byte[] start, byte[] end) { if (new ByteArrayComparator().compare(start, end) > 0) throw new IllegalArgumentException("start must be less than or equal to end"); m_next = new BigInteger(1, Arrays.copyOf(start, start.length)); m_end = new BigInteger(1, Arrays.copyOf(end, end.length)); }
/** * returns the difference of spec1 - spec2 * * @param spec1 a {@link java.lang.String} object. * @param spec2 a {@link java.lang.String} object. * @return -1 for spec1 < spec2, 0 for spec1 == spec2, 1 for spec1 > spec2 */ @Override public int compare(final String spec1, final String spec2) { final InetAddress addr1 = InetAddressUtils.addr(spec1); final InetAddress addr2 = InetAddressUtils.addr(spec2); return new ByteArrayComparator().compare(addr1 == null? null : addr1.getAddress(), addr2 == null? null : addr2.getAddress()); } }
byte[] to = end.getAddress(); if (new ByteArrayComparator().compare(from, to) > 0) { LOG.warn("The beginning of the address range is greater than the end of the address range ({} - {}), swapping values to create a valid IP address range", InetAddressUtils.str(start), InetAddressUtils.str(end)); m_end = from;
/** * <p>compare</p> * * @param rng1 a {@link org.opennms.netmgt.config.common.Range} object. * @param rng2 a {@link org.opennms.netmgt.config.common.Range} object. * @return a int. */ @Override public int compare(final Range rng1, final Range rng2) { final InetAddress addr1 = InetAddressUtils.addr(rng1.getBegin()); final InetAddress addr2 = InetAddressUtils.addr(rng2.getBegin()); return new ByteArrayComparator().compare(addr1 == null? null : addr1.getAddress(), addr2 == null? null : addr2.getAddress()); } }
int comparison = new ByteArrayComparator().compare(addr, toIpAddrBytes(rng.getBegin())); if (comparison > 0) { int endComparison = new ByteArrayComparator().compare(addr, toIpAddrBytes(rng.getEnd())); if (endComparison <= 0) { has_range_include = true; if (new ByteArrayComparator().compare(addr, toIpAddrBytes(spec)) == 0) { has_specific = true; LOG.debug("interfaceInPackage: Interface {} defined as 'specific'", iface); int comparison = new ByteArrayComparator().compare(addr, toIpAddrBytes(rng.getBegin())); if (comparison > 0) { int endComparison = new ByteArrayComparator().compare(addr, toIpAddrBytes(rng.getEnd())); if (endComparison <= 0) { LOG.debug("interfaceInPackage: Interface {} matches an exclude range", iface);
@Override public void visitRanges(List<Range> ranges) { // if we've already matched a specific, don't bother with the ranges if (!shouldTryToMatch()) return; for (final Range range : ranges) { final byte[] addr = m_address.getAddress(); final byte[] begin = InetAddressUtils.toIpAddrBytes(range.getBegin()); final byte[] end = InetAddressUtils.toIpAddrBytes(range.getEnd()); final boolean inRange; if (BYTE_ARRAY_COMPARATOR.compare(begin, end) <= 0) { inRange = InetAddressUtils.isInetAddressInRange(addr, begin, end); } else { LOG.warn("{} has an 'end' that is earlier than its 'beginning'!", range); inRange = InetAddressUtils.isInetAddressInRange(addr, end, begin); } if (inRange) { handleMatch(); return; } } }
if (new ByteArrayComparator().compare(speca, addr) == 0) { has_specific = true; break;
if (new ByteArrayComparator().compare(speca, addr) == 0) { has_specific = true; break;
if (new ByteArrayComparator().compare(speca, addr) == 0) { has_specific = true; break;
if (new ByteArrayComparator().compare(speca, addr) == 0) { has_specific = true; break;
if (new ByteArrayComparator().compare(speca, addr) == 0) { has_specific = true; break;
final String o2ip = InetAddressUtils.str(o2.getIpAddress()); if (!"0.0.0.0".equals(o1ip) && !"0.0.0.0".equals(o2ip)) { return new ByteArrayComparator().compare(InetAddressUtils.toIpAddrBytes(o1ip), InetAddressUtils.toIpAddrBytes(o2ip)); } else {
final String o2ip = InetAddressUtils.str(o2.getIpAddress()); if (!"0.0.0.0".equals(o1ip) && !"0.0.0.0".equals(o2ip)) { return new ByteArrayComparator().compare(InetAddressUtils.toIpAddrBytes(o1ip), InetAddressUtils.toIpAddrBytes(o2ip)); } else {