NeilMadden/apisecurityinaction

Errata: check for IPv6 unique local address is wrong (ch 10)

NeilMadden opened this issue · 1 comments

The check for isUniqueLocalAddress given in listing 10.15 is incorrect according to the definition of IPv6 unique local addresses. The code checks if the address starts with the bytes 0xFD, 0x00 but the correct prefix is in fact FD00/7 - i.e., only the first 7 bits are considered. (In fact the prefix is given as FC00::/7 in the RFC - the two are equivalent as they differ only in the 8th bit).

The correct definition of isUniqueLocalAddress should be the following:

private static boolean isUniqueLocalAddress(InetAddress ipAddr) {
    return ipAddr instanceof Inet6Address &&
                (ipAddr.getAddress()[0] & 0xFE) == 0xFC;
}

The definition in the code has been fixed in chapter10-end and all subsequent chapter branches. The erratum has been reported to Manning.