Documentation
¶
Overview ¶
Package androiddns makes Go's own resolver work on Android, which has no /etc/resolv.conf (#2872).
A build without cgo, as every magpie terminal build is, resolves names with Go's own resolver. It reads /etc/resolv.conf and, finding none, asks 127.0.0.1:53 and [::1]:53, where nothing listens on Android: every lookup failed with "connection refused", in Termux and in any other Android process, so magpie reached no vendor.
Android's own lookups go to netd, through its dnsproxyd socket, which follows the network the device is on: its DNS servers, a VPN's, Private DNS. Install sends a query Go aimed at those two made-up addresses to netd first, and to the servers Termux's resolv.conf names after it, so a network that drops plain DNS to a public server still resolves as every app on the phone does. A query for any other address is dialled as Go asked it, so a machine with a resolv.conf of its own resolves as before.
Index ¶
Constants ¶
const NetdSocket = "/dev/socket/dnsproxyd"
NetdSocket is where Android's netd takes lookups: bionic's getaddrinfo writes every app's there (android_getaddrinfo_proxy).
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
func Dial(netd string, servers []string) func(ctx context.Context, network, address string) (net.Conn, error)
Dial is a net.Resolver.Dial that answers a query Go aimed at one of its fallbacks from what Android resolves with: netd's socket at netd ("" when there is none), then servers, the name servers of a resolv.conf. Go tries its two fallbacks in turn, so the first goes to netd and the second to the first server; with only one of them, both go to it. netd answers a failure it can't explain with SERVFAIL, which sends Go on to the next. A query for any other address is dialled as Go asked it.
func Install ¶
func Install()
Install points net's resolver at what Android resolves with, when Go's resolver would otherwise ask the addresses it made up. The CLI calls it before anything looks a name up. GOOS=linux is here too: the Linux arm64 build runs on Android as well (#2872), and Android's GOOS includes linux. Anywhere /etc/resolv.conf names a server, or that isn't Android, nothing changes.
Types ¶
This section is empty.