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