My IPv6 knowledge is very limited, could help me solve this question? As known, for IPv4, if the netmask is 25, the mapping address should be 255.255.255.128. Codes of arithmetic is like:
public static String getNetmaskFromBits( int bits )
{
StringBuilder b = new StringBuilder( 15 );
int tempBits = 0xFFFFFFFF;
tempBits = tempBits << 32 - bits;
b.append( ( tempBits & 0xFF000000 ) >>> 24 ).append( '.' );
b.append( ( tempBits & 0x00FF0000 ) >>> 16 ).append( '.' );
b.append( ( tempBits & 0x0000FF00 ) >>> 8 ).append( '.' );
b.append( tempBits & 0x000000FF );
return b.toString();
}
How about IPv6? It can be 128 bits. How to map it to IPv6 address? Codes should be like:
public static String getIpv6NetmaskFromBits( int bits )
{
StringBuilder b = new StringBuilder( 15 );
...
return b.toString();
}