diff options
Diffstat (limited to 'src/de/blinkt/openvpn/CIDRIP.java')
-rw-r--r-- | src/de/blinkt/openvpn/CIDRIP.java | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/de/blinkt/openvpn/CIDRIP.java b/src/de/blinkt/openvpn/CIDRIP.java index c2f0d821..ccb3836a 100644 --- a/src/de/blinkt/openvpn/CIDRIP.java +++ b/src/de/blinkt/openvpn/CIDRIP.java @@ -5,13 +5,7 @@ class CIDRIP{ int len; public CIDRIP(String ip, String mask){ mIp=ip; - String[] ipt = mask.split("\\."); - long netmask=0; - - netmask += Long.parseLong(ipt[0])<< 24; - netmask += Integer.parseInt(ipt[1])<< 16; - netmask += Integer.parseInt(ipt[2])<< 8; - netmask += Integer.parseInt(ipt[3]); + long netmask=getInt(mask); // Add 33. bit to ensure the loop terminates netmask += 1l << 32; @@ -36,14 +30,7 @@ class CIDRIP{ } public boolean normalise(){ - long ip=0; - - String[] ipt = mIp.split("\\."); - - ip += Long.parseLong(ipt[0])<< 24; - ip += Integer.parseInt(ipt[1])<< 16; - ip += Integer.parseInt(ipt[2])<< 8; - ip += Integer.parseInt(ipt[3]); + long ip=getInt(mIp); long newip = ip & (0xffffffffl << (32 -len)); if (newip != ip){ @@ -53,4 +40,19 @@ class CIDRIP{ return false; } } + static long getInt(String ipaddr) { + String[] ipt = ipaddr.split("\\."); + long ip=0; + + ip += Long.parseLong(ipt[0])<< 24; + ip += Integer.parseInt(ipt[1])<< 16; + ip += Integer.parseInt(ipt[2])<< 8; + ip += Integer.parseInt(ipt[3]); + + return ip; + } + public long getInt() { + return getInt(mIp); + } + }
\ No newline at end of file |