summaryrefslogtreecommitdiff
path: root/src/se/leap/openvpn/CIDRIP.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-04-07 20:43:34 +0200
committerParménides GV <parmegv@sdf.org>2014-04-08 11:43:27 +0200
commitc206a91d320995f37f8abb33188bfd384249da3d (patch)
tree10a7d8a9dd7f24437ac4851b8d01edbd5dd3ee3b /src/se/leap/openvpn/CIDRIP.java
parent910b0e1746ab3f63e63808b198ad51fec5b635e5 (diff)
Next step: compile jni sources correctly.
Diffstat (limited to 'src/se/leap/openvpn/CIDRIP.java')
-rw-r--r--src/se/leap/openvpn/CIDRIP.java58
1 files changed, 0 insertions, 58 deletions
diff --git a/src/se/leap/openvpn/CIDRIP.java b/src/se/leap/openvpn/CIDRIP.java
deleted file mode 100644
index 8c4b6709..00000000
--- a/src/se/leap/openvpn/CIDRIP.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package se.leap.openvpn;
-
-class CIDRIP{
- String mIp;
- int len;
- public CIDRIP(String ip, String mask){
- mIp=ip;
- long netmask=getInt(mask);
-
- // 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() {
- return String.format("%s/%d",mIp,len);
- }
-
- public boolean normalise(){
- long ip=getInt(mIp);
-
- long newip = ip & (0xffffffffl << (32 -len));
- if (newip != ip){
- mIp = String.format("%d.%d.%d.%d", (newip & 0xff000000) >> 24,(newip & 0xff0000) >> 16, (newip & 0xff00) >> 8 ,newip & 0xff);
- return true;
- } else {
- 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