Skip to content

Commit

Permalink
Pass prefix length from builder to setAsUnderlyingNetwork method.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-sevostianov-sc committed Sep 5, 2017
1 parent 1c2f97e commit 1356bbe
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public int onStartCommand(final Intent intent, int flags, final int startId) {
Toast.makeText(this, "SimpleRT Connected!", Toast.LENGTH_SHORT).show();
Native.start(tunFd.detachFd(), accessoryFd.detachFd());

setAsUnderlyingNetwork(ipAddr);
setAsUnderlyingNetwork(ipAddr + "/" + prefixLength);
return START_NOT_STICKY;
}

private void setAsUnderlyingNetwork(String ipAddress) {
private void setAsUnderlyingNetwork(String Address) {
if (Build.VERSION.SDK_INT >= 22) {
Network vpnNetwork = findVpnNetwork(ipAddress);
Network vpnNetwork = findVpnNetwork(Address);
if (vpnNetwork != null) {
// so that applications knows that network is available
setUnderlyingNetworks(new Network[]{vpnNetwork});
Expand All @@ -138,14 +138,14 @@ private void setAsUnderlyingNetwork(String ipAddress) {
}

@TargetApi(22)
private Network findVpnNetwork(String ipAddress) {
private Network findVpnNetwork(String Address) {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = cm.getAllNetworks();
for (Network network : networks) {
LinkProperties linkProperties = cm.getLinkProperties(network);
List<LinkAddress> addresses = linkProperties.getLinkAddresses();
for (LinkAddress addr : addresses) {
if (addr.toString().equals(ipAddress + "/24")) {
if (addr.toString().equals(Address)) {
return network;
}
}
Expand Down

0 comments on commit 1356bbe

Please sign in to comment.