diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt index c7c412b..218c8f4 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt @@ -127,7 +127,7 @@ class MainActivity : AppCompatActivity() { // No services have actually been discovered yet, so this method // can often be left blank. Code for peer discovery goes in the // onReceive method, detailed below. - showToast("discover peers success") + //showToast("discover peers success") } override fun onFailure(reasonCode: Int) { @@ -383,11 +383,11 @@ class MainActivity : AppCompatActivity() { } private fun updateThisDevice(wifiP2pDevice: WifiP2pDevice) { - showToast("update device:"+wifiP2pDevice.deviceName+" address:"+wifiP2pDevice.deviceAddress) + //showToast("update device:"+wifiP2pDevice.deviceName+" address:"+wifiP2pDevice.deviceAddress) } private fun setIsWifiP2pEnabled(b: Boolean) { - showToast("WifiP2pEnabled="+b) + //showToast("WifiP2pEnabled="+b) } /** register the BroadcastReceiver with the intent values to be matched */ @@ -413,7 +413,7 @@ class MainActivity : AppCompatActivity() { // If an AdapterView is backed by this data, notify it // of the change. For instance, if you have a ListView of available // peers, trigger an update. //((WiFiPeerListAdapter) getListAdapter()).notifyDataSetChanged(); if (peers.size() == 0) { Log.d(WiFiDirectActivity.TAG, "No devices found"); return; } } //just show message - showToast("available peers:"+this@MainActivity.wirelessPeers.size) + //showToast("available peers:"+this@MainActivity.wirelessPeers.size) } } diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt index f4e4729..ea4b323 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/YggdrasilTunService.kt @@ -1,7 +1,10 @@ package io.github.chronosx88.yggdrasil import android.app.PendingIntent +import android.content.Context import android.content.Intent +import android.net.ConnectivityManager +import android.net.Network import android.net.VpnService import android.os.ParcelFileDescriptor import android.system.OsConstants @@ -17,6 +20,7 @@ import kotlinx.coroutines.* import mobile.Mobile import mobile.Yggdrasil import java.io.* +import java.net.Inet6Address import java.nio.ByteBuffer @@ -63,7 +67,6 @@ class YggdrasilTunService : VpnService() { private fun setupIOStreams(dns: MutableSet){ address = ygg.addressString var builder = Builder() - .addAddress(address, 7) .allowFamily(OsConstants.AF_INET) .setMtu(MAX_PACKET_SIZE) if (dns.size > 0) { @@ -72,6 +75,12 @@ class YggdrasilTunService : VpnService() { builder.addDnsServer(d.address) } } + /* + fix for DNS unavailability + */ + if(!hasIpv6DefaultRoute()){ + builder.addRoute("::",0) + } if(tunInterface!=null){ tunInterface!!.close() tunInputStream!!.close() @@ -193,4 +202,20 @@ class YggdrasilTunService : VpnService() { super.onDestroy() stopSelf() } + + private fun hasIpv6DefaultRoute(): Boolean { + val cm = + getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + val networks = cm.allNetworks + for (network in networks) { + val linkProperties = cm.getLinkProperties(network) + val routes = linkProperties.routes + for (route in routes) { + if (route.isDefaultRoute && route.gateway is Inet6Address) { + return true + } + } + } + return false + } }