improve DNS utils

This commit is contained in:
Max Lv
2014-12-06 11:29:11 +08:00
parent 4df7634fae
commit e22ffa8601
2 changed files with 57 additions and 7 deletions
@@ -0,0 +1,17 @@
package com.github.shadowsocks.utils
import java.net.InetAddress
import android.net.{Network, ConnectivityManager}
object DnsUtils {
def getDnsServers(mgr: ConnectivityManager, network: Network): java.util.List[InetAddress] = {
val getLinkProperties = mgr.getClass.getMethod("getLinkProperties", network.getClass)
getLinkProperties.invoke(mgr, network).asInstanceOf[java.util.List[InetAddress]]
}
def getNetId(network: Network): Int = {
network.getClass.getDeclaredField("netId").get(network).asInstanceOf[Int]
}
}