OXIESEC PANEL
- Current Dir:
/
/
opt
/
golang
/
1.22.0
/
src
/
net
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
addrselect.go
9.69 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
addrselect_test.go
8.5 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_aix.go
582 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_android.go
272 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_bsd.go
343 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_darwin.go
298 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_linux.go
642 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_netbsd.go
276 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_openbsd.go
276 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_resnew.go
580 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_resold.go
579 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_socknew.go
753 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_sockold.go
842 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_solaris.go
343 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_stub.go
1.33 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_unix.go
11.35 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_unix_cgo.go
2.24 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_unix_cgo_darwin.go
461 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_unix_cgo_res.go
911 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_unix_cgo_resn.go
998 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_unix_syscall.go
2.99 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
cgo_unix_test.go
1.44 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
conf.go
15.63 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
conf_test.go
12.28 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
conn_test.go
1.82 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dial.go
25.68 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dial_test.go
30.14 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dial_unix_test.go
2.77 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsclient.go
5.65 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsclient_test.go
1.51 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsclient_unix.go
24.26 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsclient_unix_test.go
69.13 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsconfig.go
1.73 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsconfig_unix.go
4.16 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsconfig_unix_test.go
7.07 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsconfig_windows.go
1.6 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
dnsname_test.go
1.96 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_plan9.go
224 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_plan9_test.go
437 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_posix.go
543 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_posix_test.go
981 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_test.go
20.32 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_unix.go
382 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_unix_test.go
723 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_windows.go
355 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
error_windows_test.go
757 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
example_test.go
8.45 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
external_test.go
4.05 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
fd_fake.go
3.79 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
fd_js.go
627 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
fd_plan9.go
3.56 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
fd_posix.go
4.29 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
fd_unix.go
5.43 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
fd_wasip1.go
496 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
fd_windows.go
6.14 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file.go
1.69 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_plan9.go
2.72 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_stub.go
481 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_test.go
6.43 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_unix.go
2.5 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_unix_test.go
2.07 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_wasip1.go
2.2 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_wasip1_test.go
3.76 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
file_windows.go
521 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
hook.go
894 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
hook_plan9.go
211 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
hook_unix.go
658 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
hook_windows.go
720 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
hosts.go
3.48 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
hosts_test.go
5.6 KB
02/02/2024 06:09:55 PM
rw-r--r--
📁
http
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
interface.go
7.26 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_aix.go
4.46 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_bsd.go
2.82 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_bsd_test.go
1.44 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_bsdvar.go
718 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_darwin.go
1.29 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_freebsd.go
1.29 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_linux.go
6.96 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_linux_test.go
3.65 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_plan9.go
4.71 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_solaris.go
2.13 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_stub.go
814 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_test.go
9.76 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_unix_test.go
4.85 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
interface_windows.go
5.43 KB
02/02/2024 06:09:55 PM
rw-r--r--
📁
internal
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
ip.go
13.88 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
ip_test.go
25.6 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
iprawsock.go
7.11 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
iprawsock_plan9.go
874 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
iprawsock_posix.go
3.89 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
iprawsock_test.go
5.98 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
ipsock.go
9.05 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
ipsock_plan9.go
7.48 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
ipsock_plan9_test.go
645 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
ipsock_posix.go
7.86 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
ipsock_test.go
6.81 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
listen_test.go
20.5 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
lookup.go
29.04 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
lookup_plan9.go
9.94 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
lookup_test.go
40.62 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
lookup_unix.go
3.35 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
lookup_windows.go
13.8 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
lookup_windows_test.go
8.93 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
mac.go
1.88 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
mac_test.go
3.26 KB
02/02/2024 06:09:55 PM
rw-r--r--
📁
mail
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
main_cloexec_test.go
693 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_conf_test.go
1.39 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_noconf_test.go
467 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_plan9_test.go
392 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_posix_test.go
1.37 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_test.go
7.53 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_unix_test.go
1.19 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_wasm_test.go
284 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
main_windows_test.go
1 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
mockserver_test.go
10.77 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
mptcpsock_linux.go
3.96 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
mptcpsock_linux_test.go
4.06 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
mptcpsock_stub.go
542 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
net.go
24.56 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
net_fake.go
26.36 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
net_fake_test.go
2.79 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
net_test.go
14 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
net_windows_test.go
16.28 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
netcgo_off.go
222 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
netcgo_on.go
220 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
netgo_netcgo.go
453 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
netgo_off.go
220 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
netgo_on.go
218 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📁
netip
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
nss.go
5.48 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
nss_test.go
3.4 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
packetconn_test.go
3.02 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
parse.go
6.04 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
parse_test.go
1.55 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
pipe.go
5.43 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
pipe_test.go
1.2 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
platform_test.go
4.33 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
port.go
1.46 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
port_test.go
1.34 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
port_unix.go
1.24 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
protoconn_test.go
7.44 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
rawconn.go
2.7 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
rawconn_stub_test.go
631 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
rawconn_test.go
4.33 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
rawconn_unix_test.go
2.96 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
rawconn_windows_test.go
3.12 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
resolverdialfunc_test.go
8.25 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
rlimit_js.go
346 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
rlimit_unix.go
1.1 KB
02/02/2024 06:09:55 PM
rw-r--r--
📁
rpc
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
sendfile_linux.go
1.12 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sendfile_linux_test.go
1.93 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sendfile_stub.go
344 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sendfile_test.go
8.25 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sendfile_unix_alt.go
2.04 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sendfile_windows.go
1.02 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
server_test.go
11.67 KB
02/02/2024 06:09:55 PM
rw-r--r--
📁
smtp
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
sock_bsd.go
918 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sock_cloexec.go
1.38 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sock_linux.go
993 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sock_linux_test.go
575 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sock_plan9.go
262 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sock_posix.go
6.29 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sock_stub.go
390 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sock_windows.go
802 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockaddr_posix.go
1.45 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_aix.go
1.43 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_bsd.go
2.21 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_fake.go
955 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_linux.go
1.25 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_plan9.go
406 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_posix.go
2.13 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_solaris.go
1.25 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockopt_windows.go
1.51 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockoptip_bsdvar.go
867 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockoptip_linux.go
735 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockoptip_posix.go
1.38 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockoptip_stub.go
769 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
sockoptip_windows.go
786 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
splice_linux.go
1.69 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
splice_stub.go
376 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
splice_test.go
13.48 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
sys_cloexec.go
962 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsock.go
11.75 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsock_plan9.go
2.18 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsock_posix.go
6.16 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsock_test.go
17.68 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsock_unix_test.go
2.34 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_darwin.go
770 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_dragonfly.go
698 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_openbsd.go
365 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_plan9.go
525 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_posix.go
442 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_solaris.go
1.15 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_stub.go
399 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_unix.go
722 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
tcpsockopt_windows.go
741 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📁
testdata
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📁
textproto
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
timeout_test.go
29.11 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
udpsock.go
11.83 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
udpsock_plan9.go
4.64 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
udpsock_plan9_test.go
1.31 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
udpsock_posix.go
7.53 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
udpsock_test.go
17.24 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock.go
10.12 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_linux_test.go
2.29 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_plan9.go
1.24 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_posix.go
6.64 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_readmsg_cloexec.go
654 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_readmsg_cmsg_cloexec.go
332 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_readmsg_other.go
275 bytes
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_readmsg_test.go
2.51 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_test.go
10.64 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
unixsock_windows_test.go
2.03 KB
02/02/2024 06:09:55 PM
rw-r--r--
📁
url
-
02/02/2024 06:09:55 PM
rwxr-xr-x
📄
write_unix_test.go
1.61 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
writev_test.go
5.03 KB
02/02/2024 06:09:55 PM
rw-r--r--
📄
writev_unix.go
666 bytes
02/02/2024 06:09:55 PM
rw-r--r--
Editing: cgo_unix.go
Close
// Copyright 2011 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. // This file is called cgo_unix.go, but to allow syscalls-to-libc-based // implementations to share the code, it does not use cgo directly. // Instead of C.foo it uses _C_foo, which is defined in either // cgo_unix_cgo.go or cgo_unix_syscall.go //go:build !netgo && ((cgo && unix) || darwin) package net import ( "context" "errors" "net/netip" "syscall" "unsafe" "golang.org/x/net/dns/dnsmessage" ) // cgoAvailable set to true to indicate that the cgo resolver // is available on this system. const cgoAvailable = true // An addrinfoErrno represents a getaddrinfo, getnameinfo-specific // error number. It's a signed number and a zero value is a non-error // by convention. type addrinfoErrno int func (eai addrinfoErrno) Error() string { return _C_gai_strerror(_C_int(eai)) } func (eai addrinfoErrno) Temporary() bool { return eai == _C_EAI_AGAIN } func (eai addrinfoErrno) Timeout() bool { return false } // isAddrinfoErrno is just for testing purposes. func (eai addrinfoErrno) isAddrinfoErrno() {} // doBlockingWithCtx executes a blocking function in a separate goroutine when the provided // context is cancellable. It is intended for use with calls that don't support context // cancellation (cgo, syscalls). blocking func may still be running after this function finishes. func doBlockingWithCtx[T any](ctx context.Context, blocking func() (T, error)) (T, error) { if ctx.Done() == nil { return blocking() } type result struct { res T err error } res := make(chan result, 1) go func() { var r result r.res, r.err = blocking() res <- r }() select { case r := <-res: return r.res, r.err case <-ctx.Done(): var zero T return zero, mapErr(ctx.Err()) } } func cgoLookupHost(ctx context.Context, name string) (hosts []string, err error) { addrs, err := cgoLookupIP(ctx, "ip", name) if err != nil { return nil, err } for _, addr := range addrs { hosts = append(hosts, addr.String()) } return hosts, nil } func cgoLookupPort(ctx context.Context, network, service string) (port int, err error) { var hints _C_struct_addrinfo switch network { case "ip": // no hints case "tcp", "tcp4", "tcp6": *_C_ai_socktype(&hints) = _C_SOCK_STREAM *_C_ai_protocol(&hints) = _C_IPPROTO_TCP case "udp", "udp4", "udp6": *_C_ai_socktype(&hints) = _C_SOCK_DGRAM *_C_ai_protocol(&hints) = _C_IPPROTO_UDP default: return 0, &DNSError{Err: "unknown network", Name: network + "/" + service} } switch ipVersion(network) { case '4': *_C_ai_family(&hints) = _C_AF_INET case '6': *_C_ai_family(&hints) = _C_AF_INET6 } return doBlockingWithCtx(ctx, func() (int, error) { return cgoLookupServicePort(&hints, network, service) }) } func cgoLookupServicePort(hints *_C_struct_addrinfo, network, service string) (port int, err error) { cservice, err := syscall.ByteSliceFromString(service) if err != nil { return 0, &DNSError{Err: err.Error(), Name: network + "/" + service} } // Lowercase the C service name. for i, b := range cservice[:len(service)] { cservice[i] = lowerASCII(b) } var res *_C_struct_addrinfo gerrno, err := _C_getaddrinfo(nil, (*_C_char)(unsafe.Pointer(&cservice[0])), hints, &res) if gerrno != 0 { isTemporary := false switch gerrno { case _C_EAI_SYSTEM: if err == nil { // see golang.org/issue/6232 err = syscall.EMFILE } case _C_EAI_SERVICE, _C_EAI_NONAME: // Darwin returns EAI_NONAME. return 0, &DNSError{Err: "unknown port", Name: network + "/" + service, IsNotFound: true} default: err = addrinfoErrno(gerrno) isTemporary = addrinfoErrno(gerrno).Temporary() } return 0, &DNSError{Err: err.Error(), Name: network + "/" + service, IsTemporary: isTemporary} } defer _C_freeaddrinfo(res) for r := res; r != nil; r = *_C_ai_next(r) { switch *_C_ai_family(r) { case _C_AF_INET: sa := (*syscall.RawSockaddrInet4)(unsafe.Pointer(*_C_ai_addr(r))) p := (*[2]byte)(unsafe.Pointer(&sa.Port)) return int(p[0])<<8 | int(p[1]), nil case _C_AF_INET6: sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(*_C_ai_addr(r))) p := (*[2]byte)(unsafe.Pointer(&sa.Port)) return int(p[0])<<8 | int(p[1]), nil } } return 0, &DNSError{Err: "unknown port", Name: network + "/" + service, IsNotFound: true} } func cgoLookupHostIP(network, name string) (addrs []IPAddr, err error) { acquireThread() defer releaseThread() var hints _C_struct_addrinfo *_C_ai_flags(&hints) = cgoAddrInfoFlags *_C_ai_socktype(&hints) = _C_SOCK_STREAM *_C_ai_family(&hints) = _C_AF_UNSPEC switch ipVersion(network) { case '4': *_C_ai_family(&hints) = _C_AF_INET case '6': *_C_ai_family(&hints) = _C_AF_INET6 } h, err := syscall.BytePtrFromString(name) if err != nil { return nil, &DNSError{Err: err.Error(), Name: name} } var res *_C_struct_addrinfo gerrno, err := _C_getaddrinfo((*_C_char)(unsafe.Pointer(h)), nil, &hints, &res) if gerrno != 0 { isErrorNoSuchHost := false isTemporary := false switch gerrno { case _C_EAI_SYSTEM: if err == nil { // err should not be nil, but sometimes getaddrinfo returns // gerrno == _C_EAI_SYSTEM with err == nil on Linux. // The report claims that it happens when we have too many // open files, so use syscall.EMFILE (too many open files in system). // Most system calls would return ENFILE (too many open files), // so at the least EMFILE should be easy to recognize if this // comes up again. golang.org/issue/6232. err = syscall.EMFILE } case _C_EAI_NONAME, _C_EAI_NODATA: err = errNoSuchHost isErrorNoSuchHost = true default: err = addrinfoErrno(gerrno) isTemporary = addrinfoErrno(gerrno).Temporary() } return nil, &DNSError{Err: err.Error(), Name: name, IsNotFound: isErrorNoSuchHost, IsTemporary: isTemporary} } defer _C_freeaddrinfo(res) for r := res; r != nil; r = *_C_ai_next(r) { // We only asked for SOCK_STREAM, but check anyhow. if *_C_ai_socktype(r) != _C_SOCK_STREAM { continue } switch *_C_ai_family(r) { case _C_AF_INET: sa := (*syscall.RawSockaddrInet4)(unsafe.Pointer(*_C_ai_addr(r))) addr := IPAddr{IP: copyIP(sa.Addr[:])} addrs = append(addrs, addr) case _C_AF_INET6: sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(*_C_ai_addr(r))) addr := IPAddr{IP: copyIP(sa.Addr[:]), Zone: zoneCache.name(int(sa.Scope_id))} addrs = append(addrs, addr) } } return addrs, nil } func cgoLookupIP(ctx context.Context, network, name string) (addrs []IPAddr, err error) { return doBlockingWithCtx(ctx, func() ([]IPAddr, error) { return cgoLookupHostIP(network, name) }) } // These are roughly enough for the following: // // Source Encoding Maximum length of single name entry // Unicast DNS ASCII or <=253 + a NUL terminator // Unicode in RFC 5892 252 * total number of labels + delimiters + a NUL terminator // Multicast DNS UTF-8 in RFC 5198 or <=253 + a NUL terminator // the same as unicast DNS ASCII <=253 + a NUL terminator // Local database various depends on implementation const ( nameinfoLen = 64 maxNameinfoLen = 4096 ) func cgoLookupPTR(ctx context.Context, addr string) (names []string, err error) { ip, err := netip.ParseAddr(addr) if err != nil { return nil, &DNSError{Err: "invalid address", Name: addr} } sa, salen := cgoSockaddr(IP(ip.AsSlice()), ip.Zone()) if sa == nil { return nil, &DNSError{Err: "invalid address " + ip.String(), Name: addr} } return doBlockingWithCtx(ctx, func() ([]string, error) { return cgoLookupAddrPTR(addr, sa, salen) }) } func cgoLookupAddrPTR(addr string, sa *_C_struct_sockaddr, salen _C_socklen_t) (names []string, err error) { acquireThread() defer releaseThread() var gerrno int var b []byte for l := nameinfoLen; l <= maxNameinfoLen; l *= 2 { b = make([]byte, l) gerrno, err = cgoNameinfoPTR(b, sa, salen) if gerrno == 0 || gerrno != _C_EAI_OVERFLOW { break } } if gerrno != 0 { isErrorNoSuchHost := false isTemporary := false switch gerrno { case _C_EAI_SYSTEM: if err == nil { // see golang.org/issue/6232 err = syscall.EMFILE } case _C_EAI_NONAME: err = errNoSuchHost isErrorNoSuchHost = true default: err = addrinfoErrno(gerrno) isTemporary = addrinfoErrno(gerrno).Temporary() } return nil, &DNSError{Err: err.Error(), Name: addr, IsTemporary: isTemporary, IsNotFound: isErrorNoSuchHost} } for i := 0; i < len(b); i++ { if b[i] == 0 { b = b[:i] break } } return []string{absDomainName(string(b))}, nil } func cgoSockaddr(ip IP, zone string) (*_C_struct_sockaddr, _C_socklen_t) { if ip4 := ip.To4(); ip4 != nil { return cgoSockaddrInet4(ip4), _C_socklen_t(syscall.SizeofSockaddrInet4) } if ip6 := ip.To16(); ip6 != nil { return cgoSockaddrInet6(ip6, zoneCache.index(zone)), _C_socklen_t(syscall.SizeofSockaddrInet6) } return nil, 0 } func cgoLookupCNAME(ctx context.Context, name string) (cname string, err error, completed bool) { resources, err := resSearch(ctx, name, int(dnsmessage.TypeCNAME), int(dnsmessage.ClassINET)) if err != nil { return } cname, err = parseCNAMEFromResources(resources) if err != nil { return "", err, false } return cname, nil, true } // resSearch will make a call to the 'res_nsearch' routine in the C library // and parse the output as a slice of DNS resources. func resSearch(ctx context.Context, hostname string, rtype, class int) ([]dnsmessage.Resource, error) { return doBlockingWithCtx(ctx, func() ([]dnsmessage.Resource, error) { return cgoResSearch(hostname, rtype, class) }) } func cgoResSearch(hostname string, rtype, class int) ([]dnsmessage.Resource, error) { acquireThread() defer releaseThread() resStateSize := unsafe.Sizeof(_C_struct___res_state{}) var state *_C_struct___res_state if resStateSize > 0 { mem := _C_malloc(resStateSize) defer _C_free(mem) memSlice := unsafe.Slice((*byte)(mem), resStateSize) clear(memSlice) state = (*_C_struct___res_state)(unsafe.Pointer(&memSlice[0])) } if err := _C_res_ninit(state); err != nil { return nil, errors.New("res_ninit failure: " + err.Error()) } defer _C_res_nclose(state) // Some res_nsearch implementations (like macOS) do not set errno. // They set h_errno, which is not per-thread and useless to us. // res_nsearch returns the size of the DNS response packet. // But if the DNS response packet contains failure-like response codes, // res_search returns -1 even though it has copied the packet into buf, // giving us no way to find out how big the packet is. // For now, we are willing to take res_search's word that there's nothing // useful in the response, even though there *is* a response. bufSize := maxDNSPacketSize buf := (*_C_uchar)(_C_malloc(uintptr(bufSize))) defer _C_free(unsafe.Pointer(buf)) s, err := syscall.BytePtrFromString(hostname) if err != nil { return nil, err } var size int for { size, _ = _C_res_nsearch(state, (*_C_char)(unsafe.Pointer(s)), class, rtype, buf, bufSize) if size <= 0 || size > 0xffff { return nil, errors.New("res_nsearch failure") } if size <= bufSize { break } // Allocate a bigger buffer to fit the entire msg. _C_free(unsafe.Pointer(buf)) bufSize = size buf = (*_C_uchar)(_C_malloc(uintptr(bufSize))) } var p dnsmessage.Parser if _, err := p.Start(unsafe.Slice((*byte)(unsafe.Pointer(buf)), size)); err != nil { return nil, err } p.SkipAllQuestions() resources, err := p.AllAnswers() if err != nil { return nil, err } return resources, nil }