Libinfo-330.tar.gz
[apple/libinfo.git] / lookup.subproj / netdb_async.h
1 /*
2 * Copyright (c) 2002-2009 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 #define getipnodebyaddr_async_handle_reply getipnodebyaddr_async_handleReply
34 #define getipnodebyname_async_handle_reply getipnodebyname_async_handleReply
35
36 /* SPI for parallel / fast getaddrinfo */
37 #define AI_PARALLEL 0x00000008
38 #define AI_SRV 0x01000000
39
40 __BEGIN_DECLS
41
42
43 /*
44 * getaddrinfo
45 */
46 typedef void (*getaddrinfo_async_callback)(int32_t status, struct addrinfo *res, void *context);
47 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);
48 int32_t getaddrinfo_async_send(mach_port_t *p, const char *nodename, const char *servname, const struct addrinfo *hints);
49 int32_t getaddrinfo_async_receive(mach_port_t p, struct addrinfo **res);
50 int32_t getaddrinfo_async_handle_reply(void *msg);
51 void getaddrinfo_async_cancel(mach_port_t p);
52
53
54 /*
55 * getnameinfo
56 */
57 typedef void (*getnameinfo_async_callback)(int32_t status, char *host, char *serv, void *context);
58 int32_t getnameinfo_async_start(mach_port_t *p, const struct sockaddr *sa, size_t salen, int flags, getnameinfo_async_callback callback, void *context);
59 int32_t getnameinfo_async_send(mach_port_t *p, const struct sockaddr *sa, size_t salen, int flags);
60 int32_t getnameinfo_async_receive(mach_port_t p, char **host, char **serv);
61 int32_t getnameinfo_async_handle_reply(void *msg);
62 void getnameinfo_async_cancel(mach_port_t p);
63
64 /*
65 * DNS
66 */
67 typedef void (*dns_async_callback)(int32_t status, char *buf, uint32_t len, struct sockaddr *from, int fromlen, void *context);
68 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);
69 int32_t dns_async_send(mach_port_t *p, const char *name, uint16_t dnsclass, uint16_t dnstype, uint32_t do_search);
70 int32_t dns_async_receive(mach_port_t p, char **buf, uint32_t *len, struct sockaddr **from, uint32_t *fromlen);
71 int32_t dns_async_handle_reply(void *msg);
72 void dns_async_cancel(mach_port_t p);
73
74 /*
75 * Host lookup
76 */
77
78 /*
79 @typedef gethostbyaddr_async_callback
80 @discussion Type of the callback function used when a
81 gethostbyaddr_async_start() request is delivered.
82 @param hent The resolved host entry.
83 @param context The context provided when the request
84 was initiated.
85 */
86 typedef void (*gethostbyaddr_async_callback)(struct hostent *hent, void *context);
87
88 /*!
89 @function gethostbyaddr_async_start
90 @description Asynchronously resolves an Internet address
91 @param addr The address to be resolved.
92 @param len The length, in bytes, of the address.
93 @param type
94 @param callout The function to be called when the specified
95 address has been resolved.
96 @param context A user specified context which will be passed
97 to the callout function.
98 @result A mach reply port which will be sent a message when
99 the addr resolution has completed. This message
100 should be passed to the gethostbyaddr_async_handleReply
101 function. A NULL value indicates that no address
102 was specified or some other error occurred which
103 prevented the resolution from being started.
104 */
105 mach_port_t
106 gethostbyaddr_async_start(const char *addr, int len, int type, gethostbyaddr_async_callback callout, void *context);
107
108 /*!
109 @function gethostbyaddr_async_cancel
110 @description Cancel an asynchronous request currently in progress.
111 @param port The mach reply port associated with the request to be cancelled.
112 */
113 void gethostbyaddr_async_cancel(mach_port_t port);
114
115 /*!
116 @function gethostbyaddr_async_handleReply
117 @description This function should be called with the Mach message sent
118 to the port returned by the call to gethostbyaddr_async_start.
119 The reply message will be interpreted and will result in a
120 call to the specified callout function.
121 @param replyMsg The Mach message.
122 */
123 void gethostbyaddr_async_handleReply(void *replyMsg);
124
125 /*
126 @typedef gethostbyname_async_callback
127 @discussion Type of the callback function used when a
128 gethostbyname_async_start() request is delivered.
129 @param hent The resolved host entry.
130 @param context The context provided when the request was initiated.
131 */
132 typedef void (*gethostbyname_async_callback)(struct hostent *hent, void *context);
133
134 /*!
135 @function gethostbyname_async_start
136 @description Asynchronously resolves a hostname
137 @param name The hostname to be resolved.
138 @param callout The function to be called when the specified
139 hostname has been resolved.
140 @param context A user specified context which will be passed
141 to the callout function.
142 @result A mach reply port which will be sent a message when
143 the name resolution has completed. This message
144 should be passed to the gethostbyname_async_handleReply
145 function. A NULL value indicates that no hostname
146 was specified or some other error occurred which
147 prevented the resolution from being started.
148 */
149 mach_port_t gethostbyname_async_start(const char *name, gethostbyname_async_callback callout, void *context);
150
151 /*!
152 @function gethostbyname_async_cancel
153 @description Cancel an asynchronous request currently in progress.
154 @param port The mach reply port associated with the request to be cancelled.
155 */
156 void gethostbyname_async_cancel(mach_port_t port);
157
158 /*!
159 @function gethostbyname_async_handleReply
160 @description This function should be called with the Mach message sent
161 to the port returned by the call to gethostbyname_async_start.
162 The reply message will be interpreted and will result in a
163 call to the specified callout function.
164 @param replyMsg The Mach message.
165 */
166 void gethostbyname_async_handleReply(void *replyMsg);
167
168 /*
169 @typedef getipnodebyaddr_async_callback
170 @discussion Type of the callback function used when a
171 getipnodebyaddr_async_start() request is delivered.
172 @param hent The resolved host entry. If not NULL, the caller
173 must call freehostent() on the host entry.
174 @param error If error code if the resolved host entry is NULL
175 @param context The context provided when the request was initiated.
176 */
177 typedef void (*getipnodebyaddr_async_callback)(struct hostent *hent, int error, void *context);
178
179 /*!
180 @function getipnodebyaddr_async_start
181 @description Asynchronously resolves an Internet address
182 @param addr The address to be resolved.
183 @param len The length, in bytes, of the address.
184 @param af The address family
185 @param error
186 @param callout The function to be called when the specified
187 address has been resolved.
188 @param context A user specified context which will be passed
189 to the callout function.
190 @result A mach reply port which will be sent a message when
191 the addr resolution has completed. This message
192 should be passed to the getipnodebyaddr_async_handleReply
193 function. A NULL value indicates that no address
194 was specified or some other error occurred which
195 prevented the resolution from being started.
196 */
197 mach_port_t getipnodebyaddr_async_start(const void *addr, size_t len, int af, int *error, getipnodebyaddr_async_callback callout, void *context);
198
199 /*!
200 @function getipnodebyaddr_async_cancel
201 @description Cancel an asynchronous request currently in progress.
202 @param port The mach reply port associated with the request to be cancelled.
203 */
204 void getipnodebyaddr_async_cancel(mach_port_t port);
205
206 /*!
207 @function getipnodebyaddr_async_handleReply
208 @description This function should be called with the Mach message sent
209 to the port returned by the call to getipnodebyaddr_async_start.
210 The reply message will be interpreted and will result in a
211 call to the specified callout function.
212 @param replyMsg The Mach message.
213 */
214 void getipnodebyaddr_async_handleReply(void *replyMsg);
215
216
217 /*
218 @typedef getipnodebyname_async_callback
219 @discussion Type of the callback function used when a
220 getipnodebyname_async_start() request is delivered.
221 @param hent The resolved host entry. If not NULL, the caller
222 must call freehostent() on the host entry.
223 @param error If error code if the resolved host entry is NULL
224 @param context The context provided when the request was initiated.
225 */
226 typedef void (*getipnodebyname_async_callback)(struct hostent *hent, int error, void *context);
227
228 /*!
229 @function getipnodebyname_async_start
230 @description Asynchronously resolves a hostname
231 @param name The hostname to be resolved.
232 @param af
233 @param flags
234 @param error
235 @param callout The function to be called when the specified
236 hostname has been resolved.
237 @param context A user specified context which will be passed
238 to the callout function.
239 @result A mach reply port which will be sent a message when
240 the name resolution has completed. This message
241 should be passed to the getipnodebyname_async_handleReply
242 function. A NULL value indicates that no hostname
243 was specified or some other error occurred which
244 prevented the resolution from being started.
245 */
246 mach_port_t getipnodebyname_async_start(const char *name, int af, int flags, int *error, getipnodebyname_async_callback callout, void *context);
247
248 /*!
249 @function getipnodebyname_async_cancel
250 @description Cancel an asynchronous request currently in progress.
251 @param port The mach reply port associated with the request to be cancelled.
252 */
253 void getipnodebyname_async_cancel(mach_port_t port);
254
255 /*!
256 @function getipnodebyname_async_handleReply
257 @description This function should be called with the Mach message sent
258 to the port returned by the call to getipnodebyname_async_start.
259 The reply message will be interpreted and will result in a
260 call to the specified callout function.
261 @param replyMsg The Mach message.
262 */
263 void getipnodebyname_async_handleReply(void *replyMsg);
264
265 __END_DECLS
266
267 #endif /* !_NETDB_ASYNC_H_ */