1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-29 14:21:31 +00:00
syncthing-android/patches/golang/all/dns.patch

95 lines
1.9 KiB
Diff
Raw Normal View History

diff --git a/net/dnsclient_unix.go b/net/dnsclient_unix.go
index 17188f0..15a1663 100644
--- a/net/dnsclient_unix.go
+++ b/net/dnsclient_unix.go
@@ -279,12 +279,6 @@ func (conf *resolverConfig) tryUpdate(name string) {
return
}
conf.modTime = fi.ModTime()
- } else {
- // If modTime wasn't set prior, assume nothing has changed.
- if conf.modTime.IsZero() {
- return
- }
- conf.modTime = time.Time{}
}
dnsConf := dnsReadConfig(name)
2016-03-28 14:57:42 +00:00
diff --git a/net/dnsconfig_unix.go b/net/dnsconfig_unix.go
index 6073fdb..bd6ca41 100644
2016-03-28 14:57:42 +00:00
--- a/net/dnsconfig_unix.go
+++ b/net/dnsconfig_unix.go
@@ -8,7 +8,53 @@
2016-03-28 14:57:42 +00:00
package net
-var defaultNS = []string{"127.0.0.1", "::1"}
+import (
+ "fmt"
+ "os/exec"
+ "strings"
+)
+
+var currentNS []string
2016-03-28 14:57:42 +00:00
+
+func getDefaultNS() []string {
+ var servers []string
+ for _, prop := range []string{"net.dns1", "net.dns2"} {
2016-03-28 14:57:42 +00:00
+ cmd := exec.Command("getprop", prop)
+ outputBytes, err := cmd.Output()
+ if err != nil {
+ continue
+ }
+ output := strings.Trim(string(outputBytes), "\n")
+ if ParseIP(output) != nil {
+ servers = append(servers, output)
2016-03-28 14:57:42 +00:00
+ }
+ }
+
+ if len(servers) == 0 {
2016-03-28 14:57:42 +00:00
+ servers = []string{"8.8.8.8", "8.8.4.4", "4.2.2.1"}
+ }
+
+ if !slicesEqual(currentNS, servers) {
+ fmt.Println("Using DNS servers:", servers)
+ currentNS = servers
+ }
+
+ return currentNS
+}
+
+func slicesEqual(a, b []string) bool {
+ if len(a) != len(b) {
+ return false
+ }
+
+ for i := range a {
+ if a[i] != b[i] {
+ return false
+ }
+ }
2016-03-28 14:57:42 +00:00
+
+ return true
2016-03-28 14:57:42 +00:00
+}
type dnsConfig struct {
servers []string // servers to use
@@ -33,7 +79,7 @@ func dnsReadConfig(filename string) *dnsConfig {
2016-03-28 14:57:42 +00:00
}
file, err := open(filename)
if err != nil {
- conf.servers = defaultNS
+ conf.servers = getDefaultNS()
conf.err = err
return conf
}
@@ -110,7 +156,7 @@ func dnsReadConfig(filename string) *dnsConfig {
2016-03-28 14:57:42 +00:00
}
}
if len(conf.servers) == 0 {
- conf.servers = defaultNS
+ conf.servers = getDefaultNS()
}
return conf
}