mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
On some platforms, the gateway may not be a usable DNS. So extending the current approach to allow retrieving DNS from many sources.
30 lines
424 B
Go
30 lines
424 B
Go
package ctrld
|
|
|
|
import "net"
|
|
|
|
type dnsFn func() []string
|
|
|
|
func nameservers() []string {
|
|
var dns []string
|
|
seen := make(map[string]bool)
|
|
ch := make(chan []string)
|
|
fns := dnsFns()
|
|
|
|
for _, fn := range fns {
|
|
go func(fn dnsFn) {
|
|
ch <- fn()
|
|
}(fn)
|
|
}
|
|
for range fns {
|
|
for _, ns := range <-ch {
|
|
if seen[ns] {
|
|
continue
|
|
}
|
|
seen[ns] = true
|
|
dns = append(dns, net.JoinHostPort(ns, "53"))
|
|
}
|
|
}
|
|
|
|
return dns
|
|
}
|