mirror of https://github.com/M66B/NetGuard.git
parent
066d18a7d1
commit
0582fad911
|
@ -667,9 +667,10 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
|
||||
if (filter) {
|
||||
// TODO multiple DNS servers
|
||||
String dns = prefs.getString("dns", Util.getDefaultDNS(SinkholeService.this));
|
||||
Log.i(TAG, "DNS " + dns);
|
||||
builder.addDnsServer(dns);
|
||||
String sysDns = Util.getDefaultDNS(SinkholeService.this);
|
||||
String vpnDns = prefs.getString("dns", sysDns);
|
||||
Log.i(TAG, "DNS system=" + sysDns + " VPN=" + vpnDns);
|
||||
builder.addDnsServer(vpnDns);
|
||||
}
|
||||
|
||||
if (tethering) {
|
||||
|
|
|
@ -66,6 +66,12 @@ public class Util {
|
|||
private static final int NETWORK_TYPE_IWLAN = 18;
|
||||
private static final String TAG = "NetGuard.Util";
|
||||
|
||||
private static native String jni_getprop(String name);
|
||||
|
||||
static {
|
||||
System.loadLibrary("netguard");
|
||||
}
|
||||
|
||||
public static String getSelfVersionName(Context context) {
|
||||
try {
|
||||
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||
|
@ -282,8 +288,7 @@ public class Util {
|
|||
}
|
||||
|
||||
public static String getDefaultDNS(Context context) {
|
||||
return "8.8.8.8";
|
||||
//return "2001:4860:4860::8888";
|
||||
return jni_getprop("net.dns1");
|
||||
}
|
||||
|
||||
public static boolean isInteractive(Context context) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/ip.h>
|
||||
|
@ -247,6 +248,18 @@ Java_eu_faircode_netguard_SinkholeService_jni_1pcap(JNIEnv *env, jclass type,
|
|||
log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed");
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_eu_faircode_netguard_Util_jni_1getprop(JNIEnv *env, jclass type, jstring name_) {
|
||||
const char *name = (*env)->GetStringUTFChars(env, name_, 0);
|
||||
|
||||
char value[250];
|
||||
__system_property_get(name, value);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, name_, name);
|
||||
|
||||
return (*env)->NewStringUTF(env, value);
|
||||
}
|
||||
|
||||
// Private functions
|
||||
|
||||
void check_allowed(const struct arguments *args) {
|
||||
|
@ -2155,6 +2168,23 @@ int jniCheckException(JNIEnv *env) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
typedef int (*PFN_SYS_PROP_GET)(const char *, char *);
|
||||
|
||||
int __system_property_get(const char *name, char *value) {
|
||||
static PFN_SYS_PROP_GET __real_system_property_get = NULL;
|
||||
if (!__real_system_property_get) {
|
||||
void *handle = dlopen("libc.so", RTLD_NOLOAD);
|
||||
if (!handle)
|
||||
log_android(ANDROID_LOG_ERROR, "dlopen(libc.so): %s", dlerror());
|
||||
else {
|
||||
__real_system_property_get = (PFN_SYS_PROP_GET) dlsym(handle, "__system_property_get");
|
||||
if (!__real_system_property_get)
|
||||
log_android(ANDROID_LOG_ERROR, "dlsym(__system_property_get()): %s", dlerror());
|
||||
}
|
||||
}
|
||||
return (*__real_system_property_get)(name, value);
|
||||
}
|
||||
|
||||
void log_android(int prio, const char *fmt, ...) {
|
||||
if (prio >= loglevel) {
|
||||
char line[1024];
|
||||
|
|
|
@ -246,6 +246,8 @@ jobject jniNewObject(JNIEnv *env, jclass cls, jmethodID constructor, const char
|
|||
|
||||
int jniCheckException(JNIEnv *env);
|
||||
|
||||
int __system_property_get(const char *name, char *value);
|
||||
|
||||
void log_android(int prio, const char *fmt, ...);
|
||||
|
||||
void log_packet(const struct arguments *args,
|
||||
|
|
Loading…
Reference in New Issue