Libinfo-517.200.9.tar.gz
[apple/libinfo.git] / lookup.subproj / netdb_async.h
1 /*
2 * Copyright (c) 2002-2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _NETDB_ASYNC_H_
25 #define _NETDB_ASYNC_H_
26
27 #include <sys/cdefs.h>
28 #include <mach/mach.h>
29 #include <netdb.h>
30
31 #define gethostbyname_async_handle_reply gethostbyname_async_handleReply
32 #define gethostbyaddr_async_handle_reply gethostbyaddr_async_handleReply
33 #if (!defined(LIBINFO_INSTALL_API) || !LIBINFO_INSTALL_API)
34 #define getipnodebyaddr_async_handle_reply getipnodebyaddr_async_handleReply
35 #define getipnodebyname_async_handle_reply getipnodebyname_async_handleReply
36 #endif
37
38 /* SPI for parallel / fast getaddrinfo */
39 #define AI_PARALLEL 0x00000008
40 #define AI_SRV 0x01000000
41
42 __BEGIN_DECLS
43
44
45 /*
46 * getaddrinfo
47 */
48 typedef void (*getaddrinfo_async_callback)(int32_t status, struct addrinfo *res, void *context);
49 int32_t getaddrinfo_async_start(mach_port_t *p, const char *nodename, const char *servname, const struct addrinfo *hints, getaddrinfo_async_callback callback, void *context);
50 int32_t getaddrinfo_async_send(mach_port_t *p, const char *nodename, const char *servname, const struct addrinfo *hints);
51 int32_t getaddrinfo_async_receive(mach_port_t p, struct addrinfo **res);
52 int32_t getaddrinfo_async_handle_reply(void *msg);
53 void getaddrinfo_async_cancel(mach_port_t p);
54
55
56 /*
57 * getnameinfo
58 */
59 typedef void (*getnameinfo_async_callback)(int32_t status, char *host, char *serv, void *context);
60 int32_t getnameinfo_async_start(mach_port_t *p, const struct sockaddr *sa, size_t salen, int flags, getnameinfo_async_callback callback, void *context);
61 int32_t getnameinfo_async_send(mach_port_t *p, const struct sockaddr *sa, size_t salen, int flags);
62 #if (!defined(LIBINFO_INSTALL_API) || !LIBINFO_INSTALL_API)
63 int32_t getnameinfo_async_receive(mach_port_t p, char **host, char **serv);
64 #endif
65 int32_t getnameinfo_async_handle_reply(void *msg);
66 void getnameinfo_async_cancel(mach_port_t p);
67
68 #if (!defined(LIBINFO_INSTALL_API) || !LIBINFO_INSTALL_API)
69 /*
70 * DNS
71 */
72 typedef void (*dns_async_callback)(int32_t status, char *buf, uint32_t len, struct sockaddr *from, int fromlen, void *context);
73 int32_t dns_async_start(mach_port_t *p, const char *name, uint16_t dnsclass, uint16_t dnstype, uint32_t do_search, dns_async_callback callback, void *context);
74 int32_t dns_async_send(mach_port_t *p, const char *name, uint16_t dnsclass, uint16_t dnstype, uint32_t do_search);
75 int32_t dns_async_receive(mach_port_t p, char **buf, uint32_t *len, struct sockaddr **from, uint32_t *fromlen);
76 int32_t dns_async_handle_reply(void *msg);
77 void dns_async_cancel(mach_port_t p);
78 #endif
79
80 /*
81 * Host lookup
82 */
83
84 /*
85 @typedef gethostbyaddr_async_callback
86 @discussion Type of the callback function used when a
87 gethostbyaddr_async_start() request is delivered.
88 @param hent The resolved host entry.
89 @param context The context provided when the request
90 was initiated.
91 */
92 typedef void (*gethostbyaddr_async_callback)(struct hostent *hent, void *context);
93
94 /*!
95 @function gethostbyaddr_async_start
96 @description Asynchronously resolves an Internet address
97 @param addr The address to be resolved.
98 @param len The length, in bytes, of the address.
99 @param type
100 @param callout The function to be called when the specified
101 address has been resolved.
102 @param context A user specified context which will be passed
103 to the callout function.
104 @result A mach reply port which will be sent a message when
105 the addr resolution has completed. This message
106 should be passed to the gethostbyaddr_async_handleReply
107 function. A NULL value indicates that no address
108 was specified or some other error occurred which
109 prevented the resolution from being started.
110 */
111 mach_port_t
112 gethostbyaddr_async_start(const char *addr, int len, int type, gethostbyaddr_async_callback callout, void *context);
113
114 /*!
115 @function gethostbyaddr_async_cancel
116 @description Cancel an asynchronous request currently in progress.
117 @param port The mach reply port associated with the request to be cancelled.
118 */
119 void gethostbyaddr_async_cancel(mach_port_t port);
120
121 /*!
122 @function gethostbyaddr_async_handleReply
123 @description This function should be called with the Mach message sent
124 to the port returned by the call to gethostbyaddr_async_start.
125 The reply message will be interpreted and will result in a
126 call to the specified callout function.
127 @param replyMsg The Mach message.
128 */
129 void gethostbyaddr_async_handleReply(void *replyMsg);
130
131 /*
132 @typedef gethostbyname_async_callback
133 @discussion Type of the callback function used when a
134 gethostbyname_async_start() request is delivered.
135 @param hent The resolved host entry.
136 @param context The context provided when the request was initiated.
137 */
138 typedef void (*gethostbyname_async_callback)(struct hostent *hent, void *context);
139
140 /*!
141 @function gethostbyname_async_start
142 @description Asynchronously resolves a hostname
143 @param name The hostname to be resolved.
144 @param callout The function to be called when the specified
145 hostname has been resolved.
146 @param context A user specified context which will be passed
147 to the callout function.
148 @result A mach reply port which will be sent a message when
149 the name resolution has completed. This message
150 should be passed to the gethostbyname_async_handleReply
151 function. A NULL value indicates that no hostname
152 was specified or some other error occurred which
153 prevented the resolution from being started.
154 */
155 mach_port_t gethostbyname_async_start(const char *name, gethostbyname_async_callback callout, void *context);
156
157 /*!
158 @function gethostbyname_async_cancel
159 @description Cancel an asynchronous request currently in progress.
160 @param port The mach reply port associated with the request to be cancelled.
161 */
162 void gethostbyname_async_cancel(mach_port_t port);
163
164 /*!
165 @function gethostbyname_async_handleReply
166 @description This function should be called with the Mach message sent
167 to the port returned by the call to gethostbyname_async_start.
168 The reply message will be interpreted and will result in a
169 call to the specified callout function.
170 @param replyMsg The Mach message.
171 */
172 void gethostbyname_async_handleReply(void *replyMsg);
173
174 #if (!defined(LIBINFO_INSTALL_API) || !LIBINFO_INSTALL_API)
175 /*
176 @typedef getipnodebyaddr_async_callback
177 @discussion Type of the callback function used when a
178 getipnodebyaddr_async_start() request is delivered.
179 @param hent The resolved host entry. If not NULL, the caller
180 must call freehostent() on the host entry.
181 @param error If error code if the resolved host entry is NULL
182 @param context The context provided when the request was initiated.
183 */
184 typedef void (*getipnodebyaddr_async_callback)(struct hostent *hent, int error, void *context);
185
186 /*!
187 @function getipnodebyaddr_async_start
188 @description Asynchronously resolves an Internet address
189 @param addr The address to be resolved.
190 @param len The length, in bytes, of the address.
191 @param af The address family
192 @param error
193 @param callout The function to be called when the specified
194 address has been resolved.
195 @param context A user specified context which will be passed
196 to the callout function.
197 @result A mach reply port which will be sent a message when
198 the addr resolution has completed. This message
199 should be passed to the getipnodebyaddr_async_handleReply
200 function. A NULL value indicates that no address
201 was specified or some other error occurred which
202 prevented the resolution from being started.
203 */
204 mach_port_t getipnodebyaddr_async_start(const void *addr, size_t len, int af, int *error, getipnodebyaddr_async_callback callout, void *context);
205
206 /*!
207 @function getipnodebyaddr_async_cancel
208 @description Cancel an asynchronous request currently in progress.
209 @param port The mach reply port associated with the request to be cancelled.
210 */
211 void getipnodebyaddr_async_cancel(mach_port_t port);
212
213 /*!
214 @function getipnodebyaddr_async_handleReply
215 @description This function should be called with the Mach message sent
216 to the port returned by the call to getipnodebyaddr_async_start.
217 The reply message will be interpreted and will result in a
218 call to the specified callout function.
219 @param replyMsg The Mach message.
220 */
221 void getipnodebyaddr_async_handleReply(void *replyMsg);
222
223
224 /*
225 @typedef getipnodebyname_async_callback
226 @discussion Type of the callback function used when a
227 getipnodebyname_async_start() request is delivered.
228 @param hent The resolved host entry. If not NULL, the caller
229 must call freehostent() on the host entry.
230 @param error If error code if the resolved host entry is NULL
231 @param context The context provided when the request was initiated.
232 */
233 typedef void (*getipnodebyname_async_callback)(struct hostent *hent, int error, void *context);
234
235 /*!
236 @function getipnodebyname_async_start
237 @description Asynchronously resolves a hostname
238 @param name The hostname to be resolved.
239 @param af
240 @param flags
241 @param error
242 @param callout The function to be called when the specified
243 hostname has been resolved.
244 @param context A user specified context which will be passed
245 to the callout function.
246 @result A mach reply port which will be sent a message when
247 the name resolution has completed. This message
248 should be passed to the getipnodebyname_async_handleReply
249 function. A NULL value indicates that no hostname
250 was specified or some other error occurred which
251 prevented the resolution from being started.
252 */
253 mach_port_t getipnodebyname_async_start(const char *name, int af, int flags, int *error, getipnodebyname_async_callback callout, void *context);
254
255 /*!
256 @function getipnodebyname_async_cancel
257 @description Cancel an asynchronous request currently in progress.
258 @param port The mach reply port associated with the request to be cancelled.
259 */
260 void getipnodebyname_async_cancel(mach_port_t port);
261
262 /*!
263 @function getipnodebyname_async_handleReply
264 @description This function should be called with the Mach message sent
265 to the port returned by the call to getipnodebyname_async_start.
266 The reply message will be interpreted and will result in a
267 call to the specified callout function.
268 @param replyMsg The Mach message.
269 */
270 void getipnodebyname_async_handleReply(void *replyMsg);
271 #endif // !LIBINFO_INSTALL_API
272
273 __END_DECLS
274
275 #endif /* !_NETDB_ASYNC_H_ */