Linux 120.141.167.72.host.secureserver.net 4.18.0-553.150.1.el8_10.x86_64 #1 SMP Fri Jul 31 15:23:31 EDT 2026 x86_64
Apache
: 72.167.141.120 | : 216.73.217.14
808 Domain
7.4.33
bestseocompany
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
local /
go /
src /
net /
[ HOME SHELL ]
Name
Size
Permission
Action
http
[ DIR ]
drwxr-xr-x
internal
[ DIR ]
drwxr-xr-x
mail
[ DIR ]
drwxr-xr-x
netip
[ DIR ]
drwxr-xr-x
rpc
[ DIR ]
drwxr-xr-x
smtp
[ DIR ]
drwxr-xr-x
testdata
[ DIR ]
drwxr-xr-x
textproto
[ DIR ]
drwxr-xr-x
url
[ DIR ]
drwxr-xr-x
addrselect.go
9.69
KB
-rw-r--r--
addrselect_test.go
8.5
KB
-rw-r--r--
cgo_aix.go
582
B
-rw-r--r--
cgo_android.go
272
B
-rw-r--r--
cgo_bsd.go
343
B
-rw-r--r--
cgo_darwin.go
298
B
-rw-r--r--
cgo_linux.go
642
B
-rw-r--r--
cgo_netbsd.go
276
B
-rw-r--r--
cgo_openbsd.go
276
B
-rw-r--r--
cgo_resnew.go
580
B
-rw-r--r--
cgo_resold.go
579
B
-rw-r--r--
cgo_socknew.go
753
B
-rw-r--r--
cgo_sockold.go
842
B
-rw-r--r--
cgo_solaris.go
343
B
-rw-r--r--
cgo_stub.go
1.33
KB
-rw-r--r--
cgo_unix.go
11.42
KB
-rw-r--r--
cgo_unix_cgo.go
2.24
KB
-rw-r--r--
cgo_unix_cgo_res.go
892
B
-rw-r--r--
cgo_unix_cgo_resn.go
979
B
-rw-r--r--
cgo_unix_syscall.go
3
KB
-rw-r--r--
cgo_unix_test.go
1.44
KB
-rw-r--r--
conf.go
15.48
KB
-rw-r--r--
conf_test.go
12.29
KB
-rw-r--r--
conn_test.go
1.82
KB
-rw-r--r--
dial.go
26.85
KB
-rw-r--r--
dial_test.go
30.28
KB
-rw-r--r--
dial_unix_test.go
2.77
KB
-rw-r--r--
dnsclient.go
5.67
KB
-rw-r--r--
dnsclient_test.go
1.51
KB
-rw-r--r--
dnsclient_unix.go
24.66
KB
-rw-r--r--
dnsclient_unix_test.go
72.77
KB
-rw-r--r--
dnsconfig.go
2.19
KB
-rw-r--r--
dnsconfig_unix.go
4.12
KB
-rw-r--r--
dnsconfig_unix_test.go
7.07
KB
-rw-r--r--
dnsconfig_windows.go
1.61
KB
-rw-r--r--
dnsname_test.go
1.96
KB
-rw-r--r--
error_plan9.go
224
B
-rw-r--r--
error_plan9_test.go
437
B
-rw-r--r--
error_posix.go
543
B
-rw-r--r--
error_posix_test.go
981
B
-rw-r--r--
error_test.go
20.32
KB
-rw-r--r--
error_unix.go
382
B
-rw-r--r--
error_unix_test.go
723
B
-rw-r--r--
error_windows.go
355
B
-rw-r--r--
error_windows_test.go
757
B
-rw-r--r--
example_test.go
8.45
KB
-rw-r--r--
external_test.go
4.05
KB
-rw-r--r--
fd_fake.go
3.79
KB
-rw-r--r--
fd_js.go
627
B
-rw-r--r--
fd_plan9.go
3.56
KB
-rw-r--r--
fd_posix.go
4.29
KB
-rw-r--r--
fd_unix.go
5.43
KB
-rw-r--r--
fd_wasip1.go
496
B
-rw-r--r--
fd_windows.go
6.21
KB
-rw-r--r--
file.go
1.69
KB
-rw-r--r--
file_plan9.go
2.77
KB
-rw-r--r--
file_stub.go
481
B
-rw-r--r--
file_test.go
6.43
KB
-rw-r--r--
file_unix.go
2.55
KB
-rw-r--r--
file_unix_test.go
2.07
KB
-rw-r--r--
file_wasip1.go
2.2
KB
-rw-r--r--
file_wasip1_test.go
3.76
KB
-rw-r--r--
file_windows.go
521
B
-rw-r--r--
hook.go
934
B
-rw-r--r--
hook_plan9.go
211
B
-rw-r--r--
hook_unix.go
658
B
-rw-r--r--
hook_windows.go
720
B
-rw-r--r--
hosts.go
3.48
KB
-rw-r--r--
hosts_test.go
5.6
KB
-rw-r--r--
interface.go
7.57
KB
-rw-r--r--
interface_aix.go
4.46
KB
-rw-r--r--
interface_bsd.go
2.82
KB
-rw-r--r--
interface_bsd_test.go
1.44
KB
-rw-r--r--
interface_bsdvar.go
718
B
-rw-r--r--
interface_darwin.go
1.29
KB
-rw-r--r--
interface_freebsd.go
1.29
KB
-rw-r--r--
interface_linux.go
6.96
KB
-rw-r--r--
interface_linux_test.go
3.65
KB
-rw-r--r--
interface_plan9.go
4.74
KB
-rw-r--r--
interface_solaris.go
2.13
KB
-rw-r--r--
interface_stub.go
814
B
-rw-r--r--
interface_test.go
9.76
KB
-rw-r--r--
interface_unix_test.go
4.85
KB
-rw-r--r--
interface_windows.go
5.49
KB
-rw-r--r--
ip.go
13.97
KB
-rw-r--r--
ip_test.go
25.69
KB
-rw-r--r--
iprawsock.go
7.11
KB
-rw-r--r--
iprawsock_plan9.go
874
B
-rw-r--r--
iprawsock_posix.go
3.89
KB
-rw-r--r--
iprawsock_test.go
5.98
KB
-rw-r--r--
ipsock.go
9.43
KB
-rw-r--r--
ipsock_plan9.go
7.48
KB
-rw-r--r--
ipsock_plan9_test.go
645
B
-rw-r--r--
ipsock_posix.go
8.62
KB
-rw-r--r--
ipsock_test.go
6.81
KB
-rw-r--r--
listen_test.go
20.5
KB
-rw-r--r--
lookup.go
28.6
KB
-rw-r--r--
lookup_plan9.go
9.89
KB
-rw-r--r--
lookup_test.go
41.45
KB
-rw-r--r--
lookup_unix.go
3.35
KB
-rw-r--r--
lookup_windows.go
14.19
KB
-rw-r--r--
lookup_windows_test.go
8.7
KB
-rw-r--r--
mac.go
1.88
KB
-rw-r--r--
mac_test.go
3.26
KB
-rw-r--r--
main_cloexec_test.go
693
B
-rw-r--r--
main_conf_test.go
2.45
KB
-rw-r--r--
main_plan9_test.go
392
B
-rw-r--r--
main_posix_test.go
1.37
KB
-rw-r--r--
main_test.go
7.53
KB
-rw-r--r--
main_unix_test.go
1.19
KB
-rw-r--r--
main_wasm_test.go
284
B
-rw-r--r--
main_windows_test.go
1
KB
-rw-r--r--
mockserver_test.go
13.28
KB
-rw-r--r--
mptcpsock_linux.go
3.96
KB
-rw-r--r--
mptcpsock_linux_test.go
4.06
KB
-rw-r--r--
mptcpsock_stub.go
542
B
-rw-r--r--
net.go
27.12
KB
-rw-r--r--
net_fake.go
26.45
KB
-rw-r--r--
net_fake_test.go
2.79
KB
-rw-r--r--
net_test.go
13.3
KB
-rw-r--r--
net_windows_test.go
16.28
KB
-rw-r--r--
netcgo_off.go
222
B
-rw-r--r--
netcgo_on.go
220
B
-rw-r--r--
netgo_netcgo.go
453
B
-rw-r--r--
netgo_off.go
220
B
-rw-r--r--
netgo_on.go
218
B
-rw-r--r--
nss.go
5.48
KB
-rw-r--r--
nss_test.go
3.4
KB
-rw-r--r--
packetconn_test.go
3.02
KB
-rw-r--r--
parse.go
5.66
KB
-rw-r--r--
parse_test.go
1.65
KB
-rw-r--r--
pipe.go
5.43
KB
-rw-r--r--
pipe_test.go
1.2
KB
-rw-r--r--
platform_test.go
4.33
KB
-rw-r--r--
port.go
1.46
KB
-rw-r--r--
port_test.go
1.34
KB
-rw-r--r--
port_unix.go
1.24
KB
-rw-r--r--
protoconn_test.go
7.44
KB
-rw-r--r--
rawconn.go
2.7
KB
-rw-r--r--
rawconn_stub_test.go
631
B
-rw-r--r--
rawconn_test.go
4.33
KB
-rw-r--r--
rawconn_unix_test.go
2.96
KB
-rw-r--r--
rawconn_windows_test.go
3.12
KB
-rw-r--r--
resolverdialfunc_test.go
8.25
KB
-rw-r--r--
rlimit_js.go
346
B
-rw-r--r--
rlimit_unix.go
1.1
KB
-rw-r--r--
sendfile_linux.go
1.15
KB
-rw-r--r--
sendfile_stub.go
403
B
-rw-r--r--
sendfile_test.go
12.06
KB
-rw-r--r--
sendfile_unix_alt.go
2.27
KB
-rw-r--r--
sendfile_windows.go
1.05
KB
-rw-r--r--
server_test.go
11.67
KB
-rw-r--r--
sock_bsd.go
918
B
-rw-r--r--
sock_cloexec.go
730
B
-rw-r--r--
sock_cloexec_solaris.go
1.43
KB
-rw-r--r--
sock_linux.go
993
B
-rw-r--r--
sock_linux_test.go
575
B
-rw-r--r--
sock_plan9.go
262
B
-rw-r--r--
sock_posix.go
6.29
KB
-rw-r--r--
sock_stub.go
390
B
-rw-r--r--
sock_windows.go
802
B
-rw-r--r--
sockaddr_posix.go
1.45
KB
-rw-r--r--
sockopt_aix.go
1.43
KB
-rw-r--r--
sockopt_bsd.go
2.21
KB
-rw-r--r--
sockopt_fake.go
955
B
-rw-r--r--
sockopt_linux.go
1.25
KB
-rw-r--r--
sockopt_plan9.go
406
B
-rw-r--r--
sockopt_posix.go
2.13
KB
-rw-r--r--
sockopt_solaris.go
1.25
KB
-rw-r--r--
sockopt_windows.go
1.51
KB
-rw-r--r--
sockoptip_bsdvar.go
867
B
-rw-r--r--
sockoptip_linux.go
735
B
-rw-r--r--
sockoptip_posix.go
1.38
KB
-rw-r--r--
sockoptip_stub.go
769
B
-rw-r--r--
sockoptip_windows.go
786
B
-rw-r--r--
splice_linux.go
1.71
KB
-rw-r--r--
splice_linux_test.go
14.49
KB
-rw-r--r--
splice_stub.go
376
B
-rw-r--r--
sys_cloexec.go
962
B
-rw-r--r--
tcpconn_keepalive_conf_darwin_...
430
B
-rw-r--r--
tcpconn_keepalive_conf_posix_t...
1.55
KB
-rw-r--r--
tcpconn_keepalive_conf_solaris...
1.77
KB
-rw-r--r--
tcpconn_keepalive_conf_unix_te...
490
B
-rw-r--r--
tcpconn_keepalive_conf_windows...
987
B
-rw-r--r--
tcpconn_keepalive_illumos_test...
3.98
KB
-rw-r--r--
tcpconn_keepalive_posix_test.g...
2.52
KB
-rw-r--r--
tcpconn_keepalive_solaris_test...
5.67
KB
-rw-r--r--
tcpconn_keepalive_test.go
4.15
KB
-rw-r--r--
tcpsock.go
13.67
KB
-rw-r--r--
tcpsock_plan9.go
2.3
KB
-rw-r--r--
tcpsock_posix.go
6.27
KB
-rw-r--r--
tcpsock_solaris.go
1.32
KB
-rw-r--r--
tcpsock_test.go
17.68
KB
-rw-r--r--
tcpsock_unix.go
1.05
KB
-rw-r--r--
tcpsock_unix_test.go
2.34
KB
-rw-r--r--
tcpsock_windows.go
1.31
KB
-rw-r--r--
tcpsockopt_darwin.go
1.4
KB
-rw-r--r--
tcpsockopt_openbsd.go
759
B
-rw-r--r--
tcpsockopt_plan9.go
762
B
-rw-r--r--
tcpsockopt_posix.go
442
B
-rw-r--r--
tcpsockopt_solaris.go
3.35
KB
-rw-r--r--
tcpsockopt_stub.go
570
B
-rw-r--r--
tcpsockopt_unix.go
1.32
KB
-rw-r--r--
tcpsockopt_windows.go
3.76
KB
-rw-r--r--
timeout_test.go
30.01
KB
-rw-r--r--
udpsock.go
11.83
KB
-rw-r--r--
udpsock_plan9.go
4.64
KB
-rw-r--r--
udpsock_plan9_test.go
1.31
KB
-rw-r--r--
udpsock_posix.go
7.53
KB
-rw-r--r--
udpsock_test.go
17.24
KB
-rw-r--r--
unixsock.go
10.12
KB
-rw-r--r--
unixsock_linux_test.go
2.29
KB
-rw-r--r--
unixsock_plan9.go
1.24
KB
-rw-r--r--
unixsock_posix.go
6.64
KB
-rw-r--r--
unixsock_readmsg_cloexec.go
654
B
-rw-r--r--
unixsock_readmsg_cmsg_cloexec....
332
B
-rw-r--r--
unixsock_readmsg_other.go
275
B
-rw-r--r--
unixsock_readmsg_test.go
2.51
KB
-rw-r--r--
unixsock_test.go
10.64
KB
-rw-r--r--
unixsock_windows_test.go
1.83
KB
-rw-r--r--
write_unix_test.go
1.61
KB
-rw-r--r--
writev_test.go
5.03
KB
-rw-r--r--
writev_unix.go
666
B
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : conf_test.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build unix package net import ( "io/fs" "os" "testing" "time" ) type nssHostTest struct { host string localhost string want hostLookupOrder } func nssStr(t *testing.T, s string) *nssConf { f, err := os.CreateTemp(t.TempDir(), "nss") if err != nil { t.Fatal(err) } if _, err := f.WriteString(s); err != nil { t.Fatal(err) } if err := f.Close(); err != nil { t.Fatal(err) } return parseNSSConfFile(f.Name()) } // represents a dnsConfig returned by parsing a nonexistent resolv.conf var defaultResolvConf = &dnsConfig{ servers: defaultNS, ndots: 1, timeout: 5, attempts: 2, err: fs.ErrNotExist, } func TestConfHostLookupOrder(t *testing.T) { // These tests are written for a system with cgo available, // without using the netgo tag. if netGoBuildTag { t.Skip("skipping test because net package built with netgo tag") } if !cgoAvailable { t.Skip("skipping test because cgo resolver not available") } tests := []struct { name string c *conf nss *nssConf resolver *Resolver resolv *dnsConfig hostTests []nssHostTest }{ { name: "force", c: &conf{ preferCgo: true, netCgo: true, }, resolv: defaultResolvConf, nss: nssStr(t, "foo: bar"), hostTests: []nssHostTest{ {"foo.local", "myhostname", hostLookupCgo}, {"google.com", "myhostname", hostLookupCgo}, }, }, { name: "netgo_dns_before_files", c: &conf{ netGo: true, }, resolv: defaultResolvConf, nss: nssStr(t, "hosts: dns files"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupDNSFiles}, }, }, { name: "netgo_fallback_on_cgo", c: &conf{ netGo: true, }, resolv: defaultResolvConf, nss: nssStr(t, "hosts: dns files something_custom"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupDNSFiles}, }, }, { name: "ubuntu_trusty_avahi", c: &conf{ mdnsTest: mdnsAssumeDoesNotExist, }, resolv: defaultResolvConf, nss: nssStr(t, "hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4"), hostTests: []nssHostTest{ {"foo.local", "myhostname", hostLookupCgo}, {"foo.local.", "myhostname", hostLookupCgo}, {"foo.LOCAL", "myhostname", hostLookupCgo}, {"foo.LOCAL.", "myhostname", hostLookupCgo}, {"google.com", "myhostname", hostLookupFilesDNS}, }, }, { name: "freebsdlinux_no_resolv_conf", c: &conf{ goos: "freebsd", }, resolv: defaultResolvConf, nss: nssStr(t, "foo: bar"), hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFilesDNS}}, }, // On OpenBSD, no resolv.conf means no DNS. { name: "openbsd_no_resolv_conf", c: &conf{ goos: "openbsd", }, resolv: defaultResolvConf, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFiles}}, }, { name: "solaris_no_nsswitch", c: &conf{ goos: "solaris", }, resolv: defaultResolvConf, nss: &nssConf{err: fs.ErrNotExist}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupCgo}}, }, { name: "openbsd_lookup_bind_file", c: &conf{ goos: "openbsd", }, resolv: &dnsConfig{lookup: []string{"bind", "file"}}, hostTests: []nssHostTest{ {"google.com", "myhostname", hostLookupDNSFiles}, {"foo.local", "myhostname", hostLookupDNSFiles}, }, }, { name: "openbsd_lookup_file_bind", c: &conf{ goos: "openbsd", }, resolv: &dnsConfig{lookup: []string{"file", "bind"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFilesDNS}}, }, { name: "openbsd_lookup_bind", c: &conf{ goos: "openbsd", }, resolv: &dnsConfig{lookup: []string{"bind"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupDNS}}, }, { name: "openbsd_lookup_file", c: &conf{ goos: "openbsd", }, resolv: &dnsConfig{lookup: []string{"file"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFiles}}, }, { name: "openbsd_lookup_yp", c: &conf{ goos: "openbsd", }, resolv: &dnsConfig{lookup: []string{"file", "bind", "yp"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupCgo}}, }, { name: "openbsd_lookup_two", c: &conf{ goos: "openbsd", }, resolv: &dnsConfig{lookup: []string{"file", "foo"}}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupCgo}}, }, { name: "openbsd_lookup_empty", c: &conf{ goos: "openbsd", }, resolv: &dnsConfig{lookup: nil}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupDNSFiles}}, }, { name: "linux_no_nsswitch.conf", c: &conf{ goos: "linux", }, resolv: defaultResolvConf, nss: &nssConf{err: fs.ErrNotExist}, hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFilesDNS}}, }, { name: "linux_empty_nsswitch.conf", c: &conf{ goos: "linux", }, resolv: defaultResolvConf, nss: nssStr(t, ""), hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupFilesDNS}}, }, { name: "files_mdns_dns", c: &conf{ mdnsTest: mdnsAssumeDoesNotExist, }, resolv: defaultResolvConf, nss: nssStr(t, "hosts: files mdns dns"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupFilesDNS}, {"x.local", "myhostname", hostLookupCgo}, }, }, { name: "dns_special_hostnames", c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: dns"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupDNS}, {"x\\.com", "myhostname", hostLookupCgo}, // punt on weird glibc escape {"foo.com%en0", "myhostname", hostLookupCgo}, // and IPv6 zones }, }, { name: "mdns_allow", c: &conf{ mdnsTest: mdnsAssumeExists, }, resolv: defaultResolvConf, nss: nssStr(t, "hosts: files mdns dns"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupCgo}, {"x.local", "myhostname", hostLookupCgo}, }, }, { name: "files_dns", c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: files dns"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupFilesDNS}, {"x", "myhostname", hostLookupFilesDNS}, {"x.local", "myhostname", hostLookupFilesDNS}, }, }, { name: "dns_files", c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: dns files"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupDNSFiles}, {"x", "myhostname", hostLookupDNSFiles}, {"x.local", "myhostname", hostLookupDNSFiles}, }, }, { name: "something_custom", c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: dns files something_custom"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupCgo}, }, }, { name: "myhostname", c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: files dns myhostname"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupFilesDNS}, {"myhostname", "myhostname", hostLookupCgo}, {"myHostname", "myhostname", hostLookupCgo}, {"myhostname.dot", "myhostname.dot", hostLookupCgo}, {"myHostname.dot", "myhostname.dot", hostLookupCgo}, {"_gateway", "myhostname", hostLookupCgo}, {"_Gateway", "myhostname", hostLookupCgo}, {"_outbound", "myhostname", hostLookupCgo}, {"_Outbound", "myhostname", hostLookupCgo}, {"localhost", "myhostname", hostLookupCgo}, {"Localhost", "myhostname", hostLookupCgo}, {"anything.localhost", "myhostname", hostLookupCgo}, {"Anything.localhost", "myhostname", hostLookupCgo}, {"localhost.localdomain", "myhostname", hostLookupCgo}, {"Localhost.Localdomain", "myhostname", hostLookupCgo}, {"anything.localhost.localdomain", "myhostname", hostLookupCgo}, {"Anything.Localhost.Localdomain", "myhostname", hostLookupCgo}, {"somehostname", "myhostname", hostLookupFilesDNS}, }, }, { name: "ubuntu14.04.02", c: &conf{ mdnsTest: mdnsAssumeDoesNotExist, }, resolv: defaultResolvConf, nss: nssStr(t, "hosts: files myhostname mdns4_minimal [NOTFOUND=return] dns mdns4"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupFilesDNS}, {"somehostname", "myhostname", hostLookupFilesDNS}, {"myhostname", "myhostname", hostLookupCgo}, }, }, // Debian Squeeze is just "dns,files", but lists all // the default criteria for dns, but then has a // non-standard but redundant notfound=return for the // files. { name: "debian_squeeze", c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: dns [success=return notfound=continue unavail=continue tryagain=continue] files [notfound=return]"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupDNSFiles}, {"somehostname", "myhostname", hostLookupDNSFiles}, }, }, { name: "resolv.conf-unknown", c: &conf{}, resolv: &dnsConfig{servers: defaultNS, ndots: 1, timeout: 5, attempts: 2, unknownOpt: true}, nss: nssStr(t, "foo: bar"), hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupCgo}}, }, // Issue 24393: make sure "Resolver.PreferGo = true" acts like netgo. { name: "resolver-prefergo", resolver: &Resolver{PreferGo: true}, c: &conf{ preferCgo: true, netCgo: true, }, resolv: defaultResolvConf, nss: nssStr(t, ""), hostTests: []nssHostTest{ {"localhost", "myhostname", hostLookupFilesDNS}, }, }, { name: "unknown-source", resolver: &Resolver{PreferGo: true}, c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: resolve files"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupDNSFiles}, }, }, { name: "dns-among-unknown-sources", resolver: &Resolver{PreferGo: true}, c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: mymachines files dns"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupFilesDNS}, }, }, { name: "dns-among-unknown-sources-2", resolver: &Resolver{PreferGo: true}, c: &conf{}, resolv: defaultResolvConf, nss: nssStr(t, "hosts: dns mymachines files"), hostTests: []nssHostTest{ {"x.com", "myhostname", hostLookupDNSFiles}, }, }, } origGetHostname := getHostname defer func() { getHostname = origGetHostname }() defer setSystemNSS(getSystemNSS(), 0) conf, err := newResolvConfTest() if err != nil { t.Fatal(err) } defer conf.teardown() for _, tt := range tests { if !conf.forceUpdateConf(tt.resolv, time.Now().Add(time.Hour)) { t.Errorf("%s: failed to change resolv config", tt.name) } for _, ht := range tt.hostTests { getHostname = func() (string, error) { return ht.localhost, nil } setSystemNSS(tt.nss, time.Hour) gotOrder, _ := tt.c.hostLookupOrder(tt.resolver, ht.host) if gotOrder != ht.want { t.Errorf("%s: hostLookupOrder(%q) = %v; want %v", tt.name, ht.host, gotOrder, ht.want) } } } } func TestAddrLookupOrder(t *testing.T) { // This test is written for a system with cgo available, // without using the netgo tag. if netGoBuildTag { t.Skip("skipping test because net package built with netgo tag") } if !cgoAvailable { t.Skip("skipping test because cgo resolver not available") } defer setSystemNSS(getSystemNSS(), 0) c, err := newResolvConfTest() if err != nil { t.Fatal(err) } defer c.teardown() if !c.forceUpdateConf(defaultResolvConf, time.Now().Add(time.Hour)) { t.Fatal("failed to change resolv config") } setSystemNSS(nssStr(t, "hosts: files myhostname dns"), time.Hour) cnf := &conf{} order, _ := cnf.addrLookupOrder(nil, "192.0.2.1") if order != hostLookupCgo { t.Errorf("addrLookupOrder returned: %v, want cgo", order) } setSystemNSS(nssStr(t, "hosts: files mdns4 dns"), time.Hour) order, _ = cnf.addrLookupOrder(nil, "192.0.2.1") if order != hostLookupCgo { t.Errorf("addrLookupOrder returned: %v, want cgo", order) } } func setSystemNSS(nss *nssConf, addDur time.Duration) { nssConfig.mu.Lock() nssConfig.nssConf = nss nssConfig.mu.Unlock() nssConfig.acquireSema() nssConfig.lastChecked = time.Now().Add(addDur) nssConfig.releaseSema() } func TestSystemConf(t *testing.T) { systemConf() }
Close