How should I perform conversion from IPv6 to long and vice versa?
So far I have:
public static long IPTo
An IPv6 address can not be stored in long. You can use BigInteger instead of long.
public static BigInteger ipv6ToNumber(String addr) {
int startIndex=addr.indexOf("::");
if(startIndex!=-1){
String firstStr=addr.substring(0,startIndex);
String secondStr=addr.substring(startIndex+2, addr.length());
BigInteger first=ipv6ToNumber(firstStr);
int x=countChar(addr, ':');
first=first.shiftLeft(16*(7-x)).add(ipv6ToNumber(secondStr));
return first;
}
String[] strArr = addr.split(":");
BigInteger retValue = BigInteger.valueOf(0);
for (int i=0;i