* @throws NullPointerException if addr is null
*/
public final @NonNull A6 ipv6AddressFor(final @NonNull InetAddress addr) {
- requireNonNull(addr, "Address must not be null");
- checkArgument(addr instanceof Inet6Address, "Address has to be an Inet6Address");
return address6Factory.newInstance(addressStringV6(addr));
}
* @throws NullPointerException if addr is null
*/
public final @NonNull A6NZ ipv6AddressNoZoneFor(final @NonNull InetAddress addr) {
- requireNonNull(addr, "Address must not be null");
- checkArgument(addr instanceof Inet6Address, "Address has to be an Inet6Address");
return address6NoZoneFactory.newInstance(addressStringV6(addr));
}
}
/**
- * Create a /128 Ipv6Prefix by interpreting input bytes as an IPv4 address.
+ * Create a /128 Ipv6Prefix by interpreting input bytes as an IPv6 address.
*
* @param addr an {@link Inet6Address}
* @return An Ipv6Prefix object
- * @throws IllegalArgumentException if addr is not an Inet6Address or if mask is not in range 0-128
+ * @throws IllegalArgumentException if addr is not an Inet6Address
* @throws NullPointerException if addr is null
*/
public final @NonNull P6 ipv6PrefixFor(final @NonNull InetAddress addr) {
* @throws NullPointerException if addr is null
*/
public final @NonNull P6 ipv6PrefixFor(final @NonNull InetAddress addr, final int mask) {
- requireNonNull(addr, "Address must not be null");
- checkArgument(addr instanceof Inet6Address, "Address has to be an Inet6Address");
checkArgument(mask >= 0 && mask <= 128, "Invalid mask %s", mask);
return prefix6Factory.newInstance(addressStringV6(addr) + '/' + mask);
}
checkArgument(bytes.length == INET6_LENGTH, "IPv6 address length is 16 bytes");
try {
- return addressStringV6(Inet6Address.getByAddress(bytes));
+ return addressStringV6(Inet6Address.getByAddress(null, bytes, null));
} catch (UnknownHostException e) {
throw new IllegalArgumentException(String.format("Invalid input %s", bytes), e);
}
}
private static String addressStringV6(final InetAddress addr) {
+ requireNonNull(addr, "Address must not be null");
+ checkArgument(addr instanceof Inet6Address, "Address has to be an Inet6Address");
+ return addressStringV6((Inet6Address) addr);
+ }
+
+ private static String addressStringV6(final Inet6Address addr) {
return InetAddresses.toAddrString(addr);
}
assertTrue(UTIL.splitIpv6Prefix(new IpClass("::/32")).getValue().equals(32));
assertArrayEquals(new byte[] { 0, 10, 0, 0, 0, 0, 0, 0, 0, 11, 0, 12, 0, 13, 0, 14, 64 },
UTIL.ipv6PrefixToBytes(new IpClass("A::B:C:D:E/64")));
+
+ // verify that an IPv4-mapped IPv6 address gets parsed as an IPv6 address
+ assertEquals("::ffff:ab0:eb", UTIL.ipv6AddressFor(
+ new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xff, (byte) 0xff, 0x0a, (byte) 0xb0, 0, (byte) 0xeb})
+ .getValue());
}
@Test