Source File
conf.go
Belonging Package
net
package net
import (
)
func () *conf {
confOnce.Do(initConfVal)
return confVal
}
func () {
, := goDebugNetDNS()
confVal.dnsDebugLevel =
confVal.netGo = netGo || == "go"
confVal.netCgo = netCgo || == "cgo"
if confVal.dnsDebugLevel > 0 {
defer func() {
switch {
case confVal.netGo:
if netGo {
println("go package net: built with netgo build tag; using Go's DNS resolver")
} else {
println("go package net: GODEBUG setting forcing use of Go's resolver")
}
case confVal.forceCgoLookupHost:
println("go package net: using cgo DNS resolver")
default:
println("go package net: dynamic selection of DNS resolver")
}
}()
}
if runtime.GOOS == "openbsd" && os.Getenv("ASR_CONFIG") != "" {
confVal.forceCgoLookupHost = true
return
}
if runtime.GOOS != "openbsd" {
confVal.nss = parseNSSConfFile("/etc/nsswitch.conf")
}
confVal.resolv = dnsReadConfig("/etc/resolv.conf")
if confVal.resolv.err != nil && !os.IsNotExist(confVal.resolv.err) &&
confVal.forceCgoLookupHost = true
}
if , := os.Stat("/etc/mdns.allow"); == nil {
confVal.hasMDNSAllow = true
}
}
func ( *conf) () bool {
return .hostLookupOrder(nil, "") == hostLookupCgo
}
func ( *conf) ( *Resolver, string) ( hostLookupOrder) {
if .dnsDebugLevel > 1 {
defer func() {
print("go package net: hostLookupOrder(", , ") = ", .String(), "\n")
}()
}
:= hostLookupCgo
if .netGo || .preferGo() {
= hostLookupFilesDNS
}
if .forceCgoLookupHost || .resolv.unknownOpt || .goos == "android" {
return
}
return
}
if os.IsNotExist(.resolv.err) {
return hostLookupFiles
}
:= .resolv.lookup
return hostLookupDNSFiles
}
if len() < 1 || len() > 2 {
return
}
switch [0] {
case "bind":
if len() == 2 {
if [1] == "file" {
return hostLookupDNSFiles
}
return
}
return hostLookupDNS
case "file":
if len() == 2 {
if [1] == "bind" {
return hostLookupFilesDNS
}
return
}
return hostLookupFiles
default:
return
}
}
if stringsHasSuffix(, ".") {
= [:len()-1]
}
return
}
:= .nss
return
}
return hostLookupFilesDNS
}
return
}
var , , bool
var string
for , := range {
if .source == "myhostname" {
if isLocalhost() || isGateway() {
return
}
, := getHostname()
if != nil || stringsEqualFold(, ) {
return
}
continue
}
if .source == "files" || .source == "dns" {
if !.standardCriteria() {
return // non-standard; let libc deal with it.
}
if .source == "files" {
= true
} else if .source == "dns" {
= true
}
if == "" {
= .source
}
continue
}
= true
continue
return
}
if && .hasMDNSAllow {
return
}
switch {
case && :
if == "files" {
return hostLookupFilesDNS
} else {
return hostLookupDNSFiles
}
case :
return hostLookupFiles
case :
return hostLookupDNS
}
return
}
func () ( string, int) {
:= goDebugString("netdns")
:= func( string) {
if == "" {
return
}
if '0' <= [0] && [0] <= '9' {
, _, _ = dtoi()
} else {
=
}
}
if := bytealg.IndexByteString(, '+'); != -1 {
([:])
([+1:])
return
}
()
return
}
func ( string) bool {
return stringsEqualFold(, "localhost") || stringsEqualFold(, "localhost.localdomain") || stringsHasSuffixFold(, ".localhost") || stringsHasSuffixFold(, ".localhost.localdomain")
}
func ( string) bool {
return stringsEqualFold(, "gateway")
![]() |
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. |