summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/OpenVpnService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/blinkt/openvpn/OpenVpnService.java')
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index 031f2a14..644b060f 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -65,16 +65,27 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
String[] ipt = mask.split("\\.");
long netmask=0;
- netmask += Integer.parseInt(ipt[0]);
- netmask += Integer.parseInt(ipt[1])<< 8;
- netmask += Integer.parseInt(ipt[2])<< 16;
- netmask += Integer.parseInt(ipt[3])<< 24;
-
- len =0;
- while((netmask & 0x1) == 1) {
- len++;
+ netmask += Long.parseLong(ipt[0])<< 24;
+ netmask += Integer.parseInt(ipt[1])<< 16;
+ netmask += Integer.parseInt(ipt[2])<< 8;
+ netmask += Integer.parseInt(ipt[3]);
+
+ // Add 33. bit to ensure the loop terminates
+ netmask += 1l << 32;
+
+ int lenZeros = 0;
+ while((netmask & 0x1) == 0) {
+ lenZeros++;
netmask = netmask >> 1;
}
+ // Check if rest of netmask is only 1s
+ if(netmask != (0x1ffffffffl >> lenZeros)) {
+ // Asume no CIDR, set /32
+ len=32;
+ } else {
+ len =32 -lenZeros;
+ }
+
}
@Override
public String toString() {