1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// Copyright 2022 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.
package unix
import (
"internal/abi"
"syscall"
"unsafe"
)
const (
AI_CANONNAME = 0x2
AI_ALL = 0x100
AI_V4MAPPED = 0x800
AI_MASK = 0x1407
EAI_AGAIN = 2
EAI_NONAME = 8
EAI_SYSTEM = 11
EAI_OVERFLOW = 14
NI_NAMEREQD = 4
)
type Addrinfo struct {
Flags int32
Family int32
Socktype int32
Protocol int32
Addrlen uint32
Canonname *byte
Addr *syscall.RawSockaddr
Next *Addrinfo
}
//go:cgo_ldflag "-lresolv"
//go:cgo_import_dynamic libc_getaddrinfo getaddrinfo "/usr/lib/libSystem.B.dylib"
func libc_getaddrinfo_trampoline()
func Getaddrinfo(hostname, servname *byte, hints *Addrinfo, res **Addrinfo) (int, error) {
gerrno, _, errno := syscall_syscall6(abi.FuncPCABI0(libc_getaddrinfo_trampoline),
uintptr(unsafe.Pointer(hostname)),
uintptr(unsafe.Pointer(servname)),
uintptr(unsafe.Pointer(hints)),
uintptr(unsafe.Pointer(res)),
0,
0)
var err error
if errno != 0 {
err = errno
}
return int(gerrno), err
}
//go:cgo_import_dynamic libc_freeaddrinfo freeaddrinfo "/usr/lib/libSystem.B.dylib"
func libc_freeaddrinfo_trampoline()
func Freeaddrinfo(ai *Addrinfo) {
syscall_syscall6(abi.FuncPCABI0(libc_freeaddrinfo_trampoline),
uintptr(unsafe.Pointer(ai)),
0, 0, 0, 0, 0)
}
//go:cgo_import_dynamic libc_getnameinfo getnameinfo "/usr/lib/libSystem.B.dylib"
func libc_getnameinfo_trampoline()
func Getnameinfo(sa *syscall.RawSockaddr, salen int, host *byte, hostlen int, serv *byte, servlen int, flags int) (int, error) {
gerrno, _, errno := syscall_syscall9(abi.FuncPCABI0(libc_getnameinfo_trampoline),
uintptr(unsafe.Pointer(sa)),
uintptr(salen),
uintptr(unsafe.Pointer(host)),
uintptr(hostlen),
uintptr(unsafe.Pointer(serv)),
uintptr(servlen),
uintptr(flags),
0,
0)
var err error
if errno != 0 {
err = errno
}
return int(gerrno), err
}
//go:cgo_import_dynamic libc_gai_strerror gai_strerror "/usr/lib/libSystem.B.dylib"
func libc_gai_strerror_trampoline()
func GaiStrerror(ecode int) string {
r1, _, _ := syscall_syscall(abi.FuncPCABI0(libc_gai_strerror_trampoline),
uintptr(ecode),
0, 0)
return GoString((*byte)(unsafe.Pointer(r1)))
}
// Implemented in the runtime package.
func gostring(*byte) string
func GoString(p *byte) string {
return gostring(p)
}
//go:linkname syscall_syscall syscall.syscall
func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
//go:linkname syscall_syscallPtr syscall.syscallPtr
func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
//go:linkname syscall_syscall6 syscall.syscall6
func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
//go:linkname syscall_syscall6X syscall.syscall6X
func syscall_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
//go:linkname syscall_syscall9 syscall.syscall9
func syscall_syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno)
type ResState struct {
unexported [70]uintptr
}
//go:cgo_import_dynamic libresolv_res_9_ninit res_9_ninit "/usr/lib/libresolv.9.dylib"
func libresolv_res_9_ninit_trampoline()
func ResNinit(state *ResState) error {
_, _, errno := syscall_syscall(abi.FuncPCABI0(libresolv_res_9_ninit_trampoline),
uintptr(unsafe.Pointer(state)),
0, 0)
if errno != 0 {
return errno
}
return nil
}
//go:cgo_import_dynamic libresolv_res_9_nclose res_9_nclose "/usr/lib/libresolv.9.dylib"
func libresolv_res_9_nclose_trampoline()
func ResNclose(state *ResState) {
syscall_syscall(abi.FuncPCABI0(libresolv_res_9_nclose_trampoline),
uintptr(unsafe.Pointer(state)),
0, 0)
}
//go:cgo_import_dynamic libresolv_res_9_nsearch res_9_nsearch "/usr/lib/libresolv.9.dylib"
func libresolv_res_9_nsearch_trampoline()
func ResNsearch(state *ResState, dname *byte, class, typ int, ans *byte, anslen int) (int, error) {
r1, _, errno := syscall_syscall6(abi.FuncPCABI0(libresolv_res_9_nsearch_trampoline),
uintptr(unsafe.Pointer(state)),
uintptr(unsafe.Pointer(dname)),
uintptr(class),
uintptr(typ),
uintptr(unsafe.Pointer(ans)),
uintptr(anslen))
if errno != 0 {
return 0, errno
}
return int(int32(r1)), nil
}
|