-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I1b20e0b8430c910ca6b4e980c79e6bac9460fba5
- Loading branch information
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
patches/golang/netgohacks/0001-dnsconfig-hack-for-android.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
From 0e08490d04d73fd0e70b7a744b335a95ac17ea95 Mon Sep 17 00:00:00 2001 | ||
From: Andrew Sutherland <dr3wsuth3rland@gmail.com> | ||
Date: Fri, 16 Oct 2015 23:08:08 -0500 | ||
Subject: [PATCH] dnsconfig hack for android | ||
|
||
--- | ||
src/net/dnsconfig_unix.go | 86 ++++++----------------------------------------- | ||
1 file changed, 10 insertions(+), 76 deletions(-) | ||
|
||
diff --git a/src/net/dnsconfig_unix.go b/src/net/dnsconfig_unix.go | ||
index 6073fdb..b0c612a 100644 | ||
--- a/src/net/dnsconfig_unix.go | ||
+++ b/src/net/dnsconfig_unix.go | ||
@@ -8,6 +8,11 @@ | ||
|
||
package net | ||
|
||
+import ( | ||
+ "os/exec" | ||
+ "strings" | ||
+) | ||
+ | ||
var defaultNS = []string{"127.0.0.1", "::1"} | ||
|
||
type dnsConfig struct { | ||
@@ -31,87 +36,16 @@ func dnsReadConfig(filename string) *dnsConfig { | ||
timeout: 5, | ||
attempts: 2, | ||
} | ||
- file, err := open(filename) | ||
+ //modified from https://gist.github.com/ernesto-jimenez/8042366 | ||
+ out, err := exec.Command("/system/bin/getprop", "net.dns1").Output() | ||
if err != nil { | ||
+ println("Error looking up dns", err) | ||
conf.servers = defaultNS | ||
conf.err = err | ||
return conf | ||
} | ||
- defer file.close() | ||
- for line, ok := file.readLine(); ok; line, ok = file.readLine() { | ||
- if len(line) > 0 && (line[0] == ';' || line[0] == '#') { | ||
- // comment. | ||
- continue | ||
- } | ||
- f := getFields(line) | ||
- if len(f) < 1 { | ||
- continue | ||
- } | ||
- switch f[0] { | ||
- case "nameserver": // add one name server | ||
- if len(f) > 1 && len(conf.servers) < 3 { // small, but the standard limit | ||
- // One more check: make sure server name is | ||
- // just an IP address. Otherwise we need DNS | ||
- // to look it up. | ||
- if parseIPv4(f[1]) != nil { | ||
- conf.servers = append(conf.servers, f[1]) | ||
- } else if ip, _ := parseIPv6(f[1], true); ip != nil { | ||
- conf.servers = append(conf.servers, f[1]) | ||
- } | ||
- } | ||
- | ||
- case "domain": // set search path to just this domain | ||
- if len(f) > 1 { | ||
- conf.search = []string{f[1]} | ||
- } | ||
- | ||
- case "search": // set search path to given servers | ||
- conf.search = make([]string, len(f)-1) | ||
- for i := 0; i < len(conf.search); i++ { | ||
- conf.search[i] = f[i+1] | ||
- } | ||
- | ||
- case "options": // magic options | ||
- for _, s := range f[1:] { | ||
- switch { | ||
- case hasPrefix(s, "ndots:"): | ||
- n, _, _ := dtoi(s, 6) | ||
- if n < 1 { | ||
- n = 1 | ||
- } | ||
- conf.ndots = n | ||
- case hasPrefix(s, "timeout:"): | ||
- n, _, _ := dtoi(s, 8) | ||
- if n < 1 { | ||
- n = 1 | ||
- } | ||
- conf.timeout = n | ||
- case hasPrefix(s, "attempts:"): | ||
- n, _, _ := dtoi(s, 9) | ||
- if n < 1 { | ||
- n = 1 | ||
- } | ||
- conf.attempts = n | ||
- case s == "rotate": | ||
- conf.rotate = true | ||
- default: | ||
- conf.unknownOpt = true | ||
- } | ||
- } | ||
- | ||
- case "lookup": | ||
- // OpenBSD option: | ||
- // http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/resolv.conf.5 | ||
- // "the legal space-separated values are: bind, file, yp" | ||
- conf.lookup = f[1:] | ||
- | ||
- default: | ||
- conf.unknownOpt = true | ||
- } | ||
- } | ||
- if len(conf.servers) == 0 { | ||
- conf.servers = defaultNS | ||
- } | ||
+ println("dnsReadConfig(server=" + string(out) + ")") | ||
+ conf.servers = []string{strings.Trim(string(out), "\n ")} | ||
return conf | ||
} | ||
|
||
-- | ||
2.5.2 | ||
|