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