@Test public void testAddressMatcherFail() { try { AddressUtil.getAddressMatcher("fe80::62c5:47ff::fe05:480a%en0"); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof InvalidAddressException); } try { AddressUtil.getAddressMatcher("fe80:62c5:47ff:fe05:480a%en0"); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof InvalidAddressException); } try { AddressUtil.getAddressMatcher("[fe80:62c5:47ff:fe05:480a%en0"); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof InvalidAddressException); } try { AddressUtil.getAddressMatcher("::ffff.192.0.2.128"); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof InvalidAddressException); } }
public static AddressMatcher getAddressMatcher(String address) { final AddressMatcher matcher; final int indexColon = address.indexOf(':'); final int lastIndexColon = address.lastIndexOf(':'); final int indexDot = address.indexOf('.'); final int lastIndexDot = address.lastIndexOf('.'); if (indexColon > -1 && lastIndexColon > indexColon) { if (indexDot == -1) { matcher = new Ip6AddressMatcher(); parseIpv6(matcher, address); } else { if (indexDot >= lastIndexDot) { throw new InvalidAddressException(address); } final int lastIndexColon2 = address.lastIndexOf(':'); final String host2 = address.substring(lastIndexColon2 + 1); matcher = new Ip4AddressMatcher(); parseIpv4(matcher, host2); } } else if (indexDot > -1 && lastIndexDot > indexDot && indexColon == -1) { matcher = new Ip4AddressMatcher(); parseIpv4(matcher, address); } else { throw new InvalidAddressException(address); } return matcher; }
AddressUtil { public static AddressMatcher getAddressMatcher(String address) { final AddressMatcher matcher; final int indexColon = address.indexOf(':'); final int lastIndexColon = address.lastIndexOf(':'); final int indexDot = address.indexOf('.'); final int lastIndexDot = address.lastIndexOf('.'); if (indexColon > -1 && lastIndexColon > indexColon) { if (indexDot == -1) { matcher = new Ip6AddressMatcher(); parseIpv6(matcher, address); } else { if (indexDot >= lastIndexDot) { throw new InvalidAddressException(address); } final int lastIndexColon2 = address.lastIndexOf(':'); final String host2 = address.substring(lastIndexColon2 + 1); matcher = new Ip4AddressMatcher(); parseIpv4(matcher, host2); } } else if (indexDot > -1 && lastIndexDot > indexDot && indexColon == -1) { matcher = new Ip4AddressMatcher(); parseIpv4(matcher, address); } else { throw new InvalidAddressException(address); } return matcher; } }
AddressUtil { public static AddressMatcher getAddressMatcher(String address) { final AddressMatcher matcher; final int indexColon = address.indexOf(':'); final int lastIndexColon = address.lastIndexOf(':'); final int indexDot = address.indexOf('.'); final int lastIndexDot = address.lastIndexOf('.'); if (indexColon > -1 && lastIndexColon > indexColon) { if (indexDot == -1) { matcher = new Ip6AddressMatcher(); parseIpv6(matcher, address); } else { if (indexDot >= lastIndexDot) { throw new InvalidAddressException(address); } final int lastIndexColon2 = address.lastIndexOf(':'); final String host2 = address.substring(lastIndexColon2 + 1); matcher = new Ip4AddressMatcher(); parseIpv4(matcher, host2); } } else if (indexDot > -1 && lastIndexDot > indexDot && indexColon == -1) { matcher = new Ip4AddressMatcher(); parseIpv4(matcher, address); } else { throw new InvalidAddressException(address); } return matcher; } private  AddressUtil(); }
AddressUtil { public static AddressMatcher getAddressMatcher(String address) { final AddressMatcher matcher; final int indexColon = address.indexOf(':'); final int lastIndexColon = address.lastIndexOf(':'); final int indexDot = address.indexOf('.'); final int lastIndexDot = address.lastIndexOf('.'); if (indexColon > -1 && lastIndexColon > indexColon) { if (indexDot == -1) { matcher = new Ip6AddressMatcher(); parseIpv6(matcher, address); } else { if (indexDot >= lastIndexDot) { throw new InvalidAddressException(address); } final int lastIndexColon2 = address.lastIndexOf(':'); final String host2 = address.substring(lastIndexColon2 + 1); matcher = new Ip4AddressMatcher(); parseIpv4(matcher, host2); } } else if (indexDot > -1 && lastIndexDot > indexDot && indexColon == -1) { matcher = new Ip4AddressMatcher(); parseIpv4(matcher, address); } else { throw new InvalidAddressException(address); } return matcher; } private  AddressUtil(); static boolean matchAnyInterface(final String address, final Collection<String> interfaces); static boolean matchInterface(final String address, final String interfaceMask); static AddressHolder getAddressHolder(String address); static AddressHolder getAddressHolder(final String address, int defaultPort); static boolean isIpAddress(String address); static InetAddress fixScopeIdAndGetInetAddress(final InetAddress inetAddress); static Inet6Address getInetAddressFor(final Inet6Address inetAddress, String scope); static Collection<Inet6Address> getPossibleInetAddressesFor(final Inet6Address inet6Address); static Collection<String> getMatchingIpv4Addresses(final AddressMatcher addressMatcher); static AddressMatcher getAddressMatcher(String address); }
AddressUtil { public static AddressMatcher getAddressMatcher(String address) { final AddressMatcher matcher; final int indexColon = address.indexOf(':'); final int lastIndexColon = address.lastIndexOf(':'); final int indexDot = address.indexOf('.'); final int lastIndexDot = address.lastIndexOf('.'); if (indexColon > -1 && lastIndexColon > indexColon) { if (indexDot == -1) { matcher = new Ip6AddressMatcher(); parseIpv6(matcher, address); } else { if (indexDot >= lastIndexDot) { throw new InvalidAddressException(address); } final int lastIndexColon2 = address.lastIndexOf(':'); final String host2 = address.substring(lastIndexColon2 + 1); matcher = new Ip4AddressMatcher(); parseIpv4(matcher, host2); } } else if (indexDot > -1 && lastIndexDot > indexDot && indexColon == -1) { matcher = new Ip4AddressMatcher(); parseIpv4(matcher, address); } else { throw new InvalidAddressException(address); } return matcher; } private  AddressUtil(); static boolean matchAnyInterface(final String address, final Collection<String> interfaces); static boolean matchInterface(final String address, final String interfaceMask); static AddressHolder getAddressHolder(String address); static AddressHolder getAddressHolder(final String address, int defaultPort); static boolean isIpAddress(String address); static InetAddress fixScopeIdAndGetInetAddress(final InetAddress inetAddress); static Inet6Address getInetAddressFor(final Inet6Address inetAddress, String scope); static Collection<Inet6Address> getPossibleInetAddressesFor(final Inet6Address inet6Address); static Collection<String> getMatchingIpv4Addresses(final AddressMatcher addressMatcher); static AddressMatcher getAddressMatcher(String address);  }