diff options
author | cyberta <cyberta@riseup.net> | 2022-12-26 14:12:10 +0000 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2022-12-26 14:12:10 +0000 |
commit | 9d64ea1f6274ca66c4e44f7bd24698a1f64c3ffe (patch) | |
tree | 1bf433d5363a437d388851e7368ee143a226f6b7 /app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java | |
parent | 6334225050f02901119812b807c29a4a07ebe182 (diff) | |
parent | 35bd57e5399e8bec5102338c7f0900fbc18970b2 (diff) |
Merge branch 'rc_fixes' into 'master'
Rc fixes
See merge request leap/bitmask_android!235
Diffstat (limited to 'app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java')
-rw-r--r-- | app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java | 68 |
1 files changed, 20 insertions, 48 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java index 5b11c0a0..25af6121 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java +++ b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java @@ -24,63 +24,35 @@ public class NetworkUtils { public static Vector<String> getLocalNetworks(Context c, boolean ipv6) { Vector<String> nets = new Vector<>(); ConnectivityManager conn = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - Network[] networks = conn.getAllNetworks(); - for (Network network : networks) { - try { - NetworkInfo ni = conn.getNetworkInfo(network); - LinkProperties li = conn.getLinkProperties(network); + Network[] networks = conn.getAllNetworks(); + for (Network network : networks) { + try { + NetworkInfo ni = conn.getNetworkInfo(network); + LinkProperties li = conn.getLinkProperties(network); - NetworkCapabilities nc = conn.getNetworkCapabilities(network); + NetworkCapabilities nc = conn.getNetworkCapabilities(network); - if (nc == null) { - continue; - } - - // Skip VPN networks like ourselves - if (nc.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) - continue; - - // Also skip mobile networks - if (nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) - continue; - - - for (LinkAddress la : li.getLinkAddresses()) { - if ((la.getAddress() instanceof Inet4Address && !ipv6) || - (la.getAddress() instanceof Inet6Address && ipv6)) - nets.add(la.toString()); - } - } catch (SecurityException se) { - se.printStackTrace(); + if (nc == null) { + continue; } - } - } else { - // Old Android Version, use native utils via ifconfig instead - // Add local network interfaces - if (ipv6) - return nets; - String[] localRoutes = NativeUtils.getIfconfig(); - - // The format of mLocalRoutes is kind of broken because I don't really like JNI - for (int i = 0; i < localRoutes.length; i += 3) { - String intf = localRoutes[i]; - String ipAddr = localRoutes[i + 1]; - String netMask = localRoutes[i + 2]; - - if (intf == null || intf.equals("lo") || - intf.startsWith("tun") || intf.startsWith("rmnet")) + // Skip VPN networks like ourselves + if (nc.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) continue; - if (ipAddr == null || netMask == null) { - VpnStatus.logError("Local routes are broken?! (Report to author) " + TextUtils.join("|", localRoutes)); + // Also skip mobile networks + if (nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) continue; - } - nets.add(ipAddr + "/" + CIDRIP.calculateLenFromMask(netMask)); - } + for (LinkAddress la : li.getLinkAddresses()) { + if ((la.getAddress() instanceof Inet4Address && !ipv6) || + (la.getAddress() instanceof Inet6Address && ipv6)) + nets.add(la.toString()); + } + } catch (SecurityException se) { + se.printStackTrace(); + } } return nets; } |