diff options
author | Arne Schwabe <arne@rfc2549.org> | 2015-09-13 03:23:16 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2015-10-08 07:53:33 +0200 |
commit | be4ccc12b9224cd1dac434838a78dc3a8f6706c5 (patch) | |
tree | 9d636f22d6f3718f89d4eb58d7995aed870c0f90 /main/src | |
parent | d9356e5bb32f410c6f47fa6c59be1fb60e7817e9 (diff) |
Fix Logic to print v6 addresses
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java b/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java index a12ef76b..ab94f3e4 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java +++ b/main/src/main/java/de/blinkt/openvpn/core/NetworkSpace.java @@ -23,9 +23,6 @@ import de.blinkt.openvpn.BuildConfig; public class NetworkSpace { - - - static class ipAddress implements Comparable<ipAddress> { private BigInteger netAddress; public int networkMask; @@ -162,16 +159,20 @@ public class NetworkSpace { String getIPv6Address() { if (BuildConfig.DEBUG) Assert.assertTrue (!isV4); BigInteger r = netAddress; - if (r.compareTo(BigInteger.ZERO)==0 && networkMask==0) - return "::"; Vector<String> parts = new Vector<String>(); - while (r.compareTo(BigInteger.ZERO) == 1) { - parts.add(0, String.format(Locale.US, "%x", r.mod(BigInteger.valueOf(0x10000)).longValue())); + while (r.compareTo(BigInteger.ZERO) == 1 || parts.size() <3) { + long part = r.mod(BigInteger.valueOf(0x10000)).longValue(); + if (part!=0) + parts.add(0, String.format(Locale.US, "%x", part)); + else + parts.add(0, ""); r = r.shiftRight(16); } - - return TextUtils.join(":", parts); + String ipv6str = TextUtils.join(":", parts); + while (ipv6str.contains(":::")) + ipv6str = ipv6str.replace(":::", "::"); + return ipv6str; } public boolean containsNet(ipAddress network) { |