Source File
dnsconfig_unix.go
Belonging Package
net
package net
import (
)
var (
defaultNS = []string{"127.0.0.1:53", "[::1]:53"}
getHostname = os.Hostname // variable for testing
)
type dnsConfig struct {
servers []string // server addresses (in host:port form) to use
search []string // rooted suffixes to append to local name
ndots int // number of dots in name to trigger absolute lookup
timeout time.Duration // wait before giving up on a query, including retries
attempts int // lost packets before giving up on server
rotate bool // round robin among servers
unknownOpt bool // anything unknown was encountered
lookup []string // OpenBSD top-level database "lookup" order
err error // any error that occurs during open of resolv.conf
mtime time.Time // time of resolv.conf modification
soffset uint32 // used by serverOffset
singleRequest bool // use sequential A and AAAA queries instead of parallel queries
useTCP bool // force usage of TCP for DNS resolutions
}
func ( string) *dnsConfig {
:= &dnsConfig{
ndots: 1,
timeout: 5 * time.Second,
attempts: 2,
}
, := open()
if != nil {
.servers = defaultNS
.search = dnsDefaultSearch()
.err =
return
}
defer .close()
if , := .file.Stat(); == nil {
.mtime = .ModTime()
} else {
.servers = defaultNS
.search = dnsDefaultSearch()
.err =
return
}
for , := .readLine(); ; , = .readLine() {
if parseIPv4([1]) != nil {
.servers = append(.servers, JoinHostPort([1], "53"))
} else if , := parseIPv6Zone([1]); != nil {
.servers = append(.servers, JoinHostPort([1], "53"))
}
}
case "domain": // set search path to just this domain
if len() > 1 {
.search = []string{ensureRooted([1])}
}
case "search": // set search path to given servers
.search = make([]string, len()-1)
for := 0; < len(.search); ++ {
.search[] = ensureRooted([+1])
}
case "options": // magic options
for , := range [1:] {
switch {
case hasPrefix(, "ndots:"):
, , := dtoi([6:])
if < 0 {
= 0
} else if > 15 {
= 15
}
.ndots =
case hasPrefix(, "timeout:"):
, , := dtoi([8:])
if < 1 {
= 1
}
.timeout = time.Duration() * time.Second
case hasPrefix(, "attempts:"):
, , := dtoi([9:])
if < 1 {
= 1
}
.attempts =
case == "rotate":
.rotate = true
.useTCP = true
default:
.unknownOpt = true
}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |