-4

I need to convert IpV6 address to long and vice-versa. I could not find any util or way to do this conversion. I am able to convert from IpV4 to long. But stuck in the above issue.So could you please suggest a suitable approach.

Please Help.....

Rahman
  • 3,755
  • 3
  • 26
  • 43

1 Answers1

2

You can't. At least not without losing information.

An IPv6 address contains 128-bits of information, while a long in Java only holds 64-bits of information, so any possible conversion scheme would lose information.

If you need to store an IPv6 address in Java, you should use the java.net.Inet6Address class.

azurefrog
  • 10,785
  • 7
  • 42
  • 56