/** * Returns an InetAddress representing the literal IPv4 or IPv6 host portion of a URL, encoded in * the format specified by RFC 3986 section 3.2.2. * * <p>This function is similar to {@link InetAddresses#forString(String)}, however, it requires * that IPv6 addresses are surrounded by square brackets. * * <p>This function is the inverse of {@link InetAddresses#toUriString(java.net.InetAddress)}. * * @param hostAddr A RFC 3986 section 3.2.2 encoded IPv4 or IPv6 address * @return an InetAddress representing the address in {@code hostAddr} * @throws IllegalArgumentException if {@code hostAddr} is not a valid IPv4 address, or IPv6 * address surrounded by square brackets */ public static InetAddress forUriString(String hostAddr) { InetAddress addr = forUriStringNoThrow(hostAddr); if (addr == null) { throw formatIllegalArgumentException("Not a valid URI IP literal: '%s'", hostAddr); } return addr; }
/** * Returns an InetAddress representing the literal IPv4 or IPv6 host portion of a URL, encoded in * the format specified by RFC 3986 section 3.2.2. * * <p>This function is similar to {@link InetAddresses#forString(String)}, however, it requires * that IPv6 addresses are surrounded by square brackets. * * <p>This function is the inverse of {@link InetAddresses#toUriString(java.net.InetAddress)}. * * @param hostAddr A RFC 3986 section 3.2.2 encoded IPv4 or IPv6 address * @return an InetAddress representing the address in {@code hostAddr} * @throws IllegalArgumentException if {@code hostAddr} is not a valid IPv4 address, or IPv6 * address surrounded by square brackets */ public static InetAddress forUriString(String hostAddr) { InetAddress addr = forUriStringNoThrow(hostAddr); if (addr == null) { throw formatIllegalArgumentException("Not a valid URI IP literal: '%s'", hostAddr); } return addr; }
/** * Returns the {@link InetAddress} having the given string representation. * * <p>This deliberately avoids all nameservice lookups (e.g. no DNS). * * @param ipString {@code String} containing an IPv4 or IPv6 string literal, e.g. {@code * "192.168.0.1"} or {@code "2001:db8::1"} * @return {@link InetAddress} representing the argument * @throws IllegalArgumentException if the argument is not a valid IP string literal */ public static InetAddress forString(String ipString) { byte[] addr = ipStringToBytes(ipString); // The argument was malformed, i.e. not an IP string literal. if (addr == null) { throw formatIllegalArgumentException("'%s' is not an IP string literal.", ipString); } return bytesToInetAddress(addr); }
/** * Returns an InetAddress representing the literal IPv4 or IPv6 host portion of a URL, encoded in * the format specified by RFC 3986 section 3.2.2. * * <p>This function is similar to {@link InetAddresses#forString(String)}, however, it requires * that IPv6 addresses are surrounded by square brackets. * * <p>This function is the inverse of {@link InetAddresses#toUriString(java.net.InetAddress)}. * * @param hostAddr A RFC 3986 section 3.2.2 encoded IPv4 or IPv6 address * @return an InetAddress representing the address in {@code hostAddr} * @throws IllegalArgumentException if {@code hostAddr} is not a valid IPv4 address, or IPv6 * address surrounded by square brackets */ public static InetAddress forUriString(String hostAddr) { InetAddress addr = forUriStringNoThrow(hostAddr); if (addr == null) { throw formatIllegalArgumentException("Not a valid URI IP literal: '%s'", hostAddr); } return addr; }
/** * Returns the {@link InetAddress} having the given string representation. * * <p>This deliberately avoids all nameservice lookups (e.g. no DNS). * * @param ipString {@code String} containing an IPv4 or IPv6 string literal, e.g. {@code * "192.168.0.1"} or {@code "2001:db8::1"} * @return {@link InetAddress} representing the argument * @throws IllegalArgumentException if the argument is not a valid IP string literal */ public static InetAddress forString(String ipString) { byte[] addr = ipStringToBytes(ipString); // The argument was malformed, i.e. not an IP string literal. if (addr == null) { throw formatIllegalArgumentException("'%s' is not an IP string literal.", ipString); } return bytesToInetAddress(addr); }
/** * Returns the {@link InetAddress} having the given string representation. * * <p>This deliberately avoids all nameservice lookups (e.g. no DNS). * * @param ipString {@code String} containing an IPv4 or IPv6 string literal, e.g. {@code * "192.168.0.1"} or {@code "2001:db8::1"} * @return {@link InetAddress} representing the argument * @throws IllegalArgumentException if the argument is not a valid IP string literal */ public static InetAddress forString(String ipString) { byte[] addr = ipStringToBytes(ipString); // The argument was malformed, i.e. not an IP string literal. if (addr == null) { throw formatIllegalArgumentException("'%s' is not an IP string literal.", ipString); } return bytesToInetAddress(addr); }
/** * Examines the Inet6Address to extract the embedded IPv4 client address if the InetAddress is an * IPv6 address of one of the specified address types that contain an embedded IPv4 address. * * <p>NOTE: ISATAP addresses are explicitly excluded from this method due to their trivial * spoofability. With other transition addresses spoofing involves (at least) infection of one's * BGP routing table. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 client address * @return {@link Inet4Address} of embedded IPv4 client address * @throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address */ public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isCompatIPv4Address(ip)) { return getCompatIPv4Address(ip); } if (is6to4Address(ip)) { return get6to4IPv4Address(ip); } if (isTeredoAddress(ip)) { return getTeredoInfo(ip).getClient(); } throw formatIllegalArgumentException("'%s' has no embedded IPv4 address.", toAddrString(ip)); }
/** * Examines the Inet6Address to extract the embedded IPv4 client address if the InetAddress is an * IPv6 address of one of the specified address types that contain an embedded IPv4 address. * * <p>NOTE: ISATAP addresses are explicitly excluded from this method due to their trivial * spoofability. With other transition addresses spoofing involves (at least) infection of one's * BGP routing table. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 client address * @return {@link Inet4Address} of embedded IPv4 client address * @throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address */ public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isCompatIPv4Address(ip)) { return getCompatIPv4Address(ip); } if (is6to4Address(ip)) { return get6to4IPv4Address(ip); } if (isTeredoAddress(ip)) { return getTeredoInfo(ip).getClient(); } throw formatIllegalArgumentException("'%s' has no embedded IPv4 address.", toAddrString(ip)); }
/** * Examines the Inet6Address to extract the embedded IPv4 client address if the InetAddress is an * IPv6 address of one of the specified address types that contain an embedded IPv4 address. * * <p>NOTE: ISATAP addresses are explicitly excluded from this method due to their trivial * spoofability. With other transition addresses spoofing involves (at least) infection of one's * BGP routing table. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 client address * @return {@link Inet4Address} of embedded IPv4 client address * @throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address */ public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isCompatIPv4Address(ip)) { return getCompatIPv4Address(ip); } if (is6to4Address(ip)) { return get6to4IPv4Address(ip); } if (isTeredoAddress(ip)) { return getTeredoInfo(ip).getClient(); } throw formatIllegalArgumentException("'%s' has no embedded IPv4 address.", toAddrString(ip)); }
/** * Returns an InetAddress representing the literal IPv4 or IPv6 host portion of a URL, encoded in * the format specified by RFC 3986 section 3.2.2. * * <p>This function is similar to {@link InetAddresses#forString(String)}, however, it requires * that IPv6 addresses are surrounded by square brackets. * * <p>This function is the inverse of {@link InetAddresses#toUriString(java.net.InetAddress)}. * * @param hostAddr A RFC 3986 section 3.2.2 encoded IPv4 or IPv6 address * @return an InetAddress representing the address in {@code hostAddr} * @throws IllegalArgumentException if {@code hostAddr} is not a valid IPv4 address, or IPv6 * address surrounded by square brackets */ public static InetAddress forUriString(String hostAddr) { InetAddress addr = forUriStringNoThrow(hostAddr); if (addr == null) { throw formatIllegalArgumentException("Not a valid URI IP literal: '%s'", hostAddr); } return addr; }
/** * Returns an InetAddress representing the literal IPv4 or IPv6 host portion of a URL, encoded in * the format specified by RFC 3986 section 3.2.2. * * <p>This function is similar to {@link InetAddresses#forString(String)}, however, it requires * that IPv6 addresses are surrounded by square brackets. * * <p>This function is the inverse of {@link InetAddresses#toUriString(java.net.InetAddress)}. * * @param hostAddr A RFC 3986 section 3.2.2 encoded IPv4 or IPv6 address * @return an InetAddress representing the address in {@code hostAddr} * @throws IllegalArgumentException if {@code hostAddr} is not a valid IPv4 address, or IPv6 * address surrounded by square brackets */ public static InetAddress forUriString(String hostAddr) { InetAddress addr = forUriStringNoThrow(hostAddr); if (addr == null) { throw formatIllegalArgumentException("Not a valid URI IP literal: '%s'", hostAddr); } return addr; }
throw formatIllegalArgumentException("Not a valid URI IP literal: '%s'", hostAddr);
/** * Returns the {@link InetAddress} having the given string representation. * * <p>This deliberately avoids all nameservice lookups (e.g. no DNS). * * @param ipString {@code String} containing an IPv4 or IPv6 string literal, e.g. * {@code "192.168.0.1"} or {@code "2001:db8::1"} * @return {@link InetAddress} representing the argument * @throws IllegalArgumentException if the argument is not a valid IP string literal */ public static InetAddress forString(String ipString) { byte[] addr = ipStringToBytes(ipString); // The argument was malformed, i.e. not an IP string literal. if (addr == null) { throw formatIllegalArgumentException("'%s' is not an IP string literal.", ipString); } return bytesToInetAddress(addr); }
/** * Returns the {@link InetAddress} having the given string representation. * * <p>This deliberately avoids all nameservice lookups (e.g. no DNS). * * @param ipString {@code String} containing an IPv4 or IPv6 string literal, e.g. {@code * "192.168.0.1"} or {@code "2001:db8::1"} * @return {@link InetAddress} representing the argument * @throws IllegalArgumentException if the argument is not a valid IP string literal */ public static InetAddress forString(String ipString) { byte[] addr = ipStringToBytes(ipString); // The argument was malformed, i.e. not an IP string literal. if (addr == null) { throw formatIllegalArgumentException("'%s' is not an IP string literal.", ipString); } return bytesToInetAddress(addr); }
/** * Returns the {@link InetAddress} having the given string representation. * * <p>This deliberately avoids all nameservice lookups (e.g. no DNS). * * @param ipString {@code String} containing an IPv4 or IPv6 string literal, e.g. {@code * "192.168.0.1"} or {@code "2001:db8::1"} * @return {@link InetAddress} representing the argument * @throws IllegalArgumentException if the argument is not a valid IP string literal */ public static InetAddress forString(String ipString) { byte[] addr = ipStringToBytes(ipString); // The argument was malformed, i.e. not an IP string literal. if (addr == null) { throw formatIllegalArgumentException("'%s' is not an IP string literal.", ipString); } return bytesToInetAddress(addr); }
/** * Examines the Inet6Address to extract the embedded IPv4 client address if the InetAddress is an * IPv6 address of one of the specified address types that contain an embedded IPv4 address. * * <p>NOTE: ISATAP addresses are explicitly excluded from this method due to their trivial * spoofability. With other transition addresses spoofing involves (at least) infection of one's * BGP routing table. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 client address * @return {@link Inet4Address} of embedded IPv4 client address * @throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address */ public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isCompatIPv4Address(ip)) { return getCompatIPv4Address(ip); } if (is6to4Address(ip)) { return get6to4IPv4Address(ip); } if (isTeredoAddress(ip)) { return getTeredoInfo(ip).getClient(); } throw formatIllegalArgumentException("'%s' has no embedded IPv4 address.", toAddrString(ip)); }
/** * Examines the Inet6Address to extract the embedded IPv4 client address * if the InetAddress is an IPv6 address of one of the specified address * types that contain an embedded IPv4 address. * * <p>NOTE: ISATAP addresses are explicitly excluded from this method * due to their trivial spoofability. With other transition addresses * spoofing involves (at least) infection of one's BGP routing table. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 client address * @return {@link Inet4Address} of embedded IPv4 client address * @throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address */ public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isCompatIPv4Address(ip)) { return getCompatIPv4Address(ip); } if (is6to4Address(ip)) { return get6to4IPv4Address(ip); } if (isTeredoAddress(ip)) { return getTeredoInfo(ip).getClient(); } throw formatIllegalArgumentException("'%s' has no embedded IPv4 address.", toAddrString(ip)); }
/** * Examines the Inet6Address to extract the embedded IPv4 client address if the InetAddress is an * IPv6 address of one of the specified address types that contain an embedded IPv4 address. * * <p>NOTE: ISATAP addresses are explicitly excluded from this method due to their trivial * spoofability. With other transition addresses spoofing involves (at least) infection of one's * BGP routing table. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 client address * @return {@link Inet4Address} of embedded IPv4 client address * @throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address */ public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) { if (isCompatIPv4Address(ip)) { return getCompatIPv4Address(ip); } if (is6to4Address(ip)) { return get6to4IPv4Address(ip); } if (isTeredoAddress(ip)) { return getTeredoInfo(ip).getClient(); } throw formatIllegalArgumentException("'%s' has no embedded IPv4 address.", toAddrString(ip)); }