Search code examples
javaipv6ipv4

Inet6Address.getByName() giving odd response for 0:0:0:0:0:ffff:0:0


I'm using the following code to normalise IPv6 IP addresses:

try {
    return Inet6Address.getByName(ipAddress).getHostAddress();
} catch (final UnknownHostException e) {
    return ipAddress;
}

However, when I use IP "0:0:0:0:0:ffff:0:0", I get "0.0.0.0" as the response. I tried this code with "ffff" in each of the other octets, and they seem to be fine:

ffff:0:0:0:0:0:0:0
0:ffff:0:0:0:0:0:0
0:0:ffff:0:0:0:0:0
0:0:0:ffff:0:0:0:0
0:0:0:0:ffff:0:0:0
0.0.0.0
0:0:0:0:0:0:ffff:0
0:0:0:0:0:0:0:ffff

Any thoughts on why this IP in particular wouldn't return an IPv6 format?


Solution

  • getHostAddress() is (correctly) displaying an IPv4-mapped IPv6 address.