1 /*	$OpenBSD: asr.h,v 1.1 2014/03/26 18:13:15 eric Exp $	*/
2 /*
3  * Copyright (c) 2012-2014 Eric Faurot <eric@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 
19 #include "includes.h"
20 
21 /*
22  * Expected fd conditions
23  */
24 #define ASR_WANT_READ	1
25 #define ASR_WANT_WRITE	2
26 
27 /*
28  * Structure through which asynchronous query results are returned when
29  * calling asr_run().
30  */
31 struct asr_result {
32 	/* Fields set if the query is not done yet (asr_run returns 0) */
33 	int	 ar_cond;	/* ASR_WANT_READ or ASR_WANT_WRITE */
34 	int	 ar_fd;		/* the fd waiting for io condition */
35 	int	 ar_timeout;	/* time to wait for in milliseconds */
36 
37 	/* Error fields.  Depends on the query type. */
38 	int	 ar_errno;
39 	int	 ar_h_errno;
40 	int	 ar_gai_errno;
41 	int	 ar_rrset_errno;
42 
43 	/* Result for res_*_async() calls */
44 	int	 ar_count;	/* number of answers in the dns reply */
45 	int	 ar_rcode;	/* response code in the dns reply */
46 	void	*ar_data;	/* raw reply packet (must be freed) */
47 	int	 ar_datalen;	/* reply packet length */
48 	struct sockaddr_storage ar_ns; /* nameserver that responded */
49 
50 	/* Result for other calls. Must be freed properly. */
51 	struct addrinfo	 *ar_addrinfo;
52 	struct rrsetinfo *ar_rrsetinfo;
53 	struct hostent	 *ar_hostent;
54 	struct netent	 *ar_netent;
55 };
56 
57 /*
58  * Asynchronous query management.
59  */
60 
61 /* Forward declaration. The API uses opaque pointers as query handles. */
62 struct asr_query;
63 
64 int asr_run(struct asr_query *, struct asr_result *);
65 int asr_run_sync(struct asr_query *, struct asr_result *);
66 void asr_abort(struct asr_query *);
67 
68 /*
69  * Asynchronous version of the resolver functions. Similar prototypes, with
70  * an extra context parameter at the end which must currently be set to NULL.
71  * All functions return a handle suitable for use with the management functions
72  * above.
73  */
74 struct asr_query *res_send_async(const unsigned char *, int, void *);
75 struct asr_query *res_query_async(const char *, int, int, void *);
76 struct asr_query *res_search_async(const char *, int, int, void *);
77 
78 struct asr_query *getrrsetbyname_async(const char *, unsigned int, unsigned int,
79     unsigned int, void *);
80 
81 struct asr_query *gethostbyname_async(const char *, void *);
82 struct asr_query *gethostbyname2_async(const char *, int, void *);
83 struct asr_query *gethostbyaddr_async(const void *, socklen_t, int, void *);
84 
85 struct asr_query *getnetbyname_async(const char *, void *);
86 struct asr_query *getnetbyaddr_async(in_addr_t, int, void *);
87 
88 struct asr_query *getaddrinfo_async(const char *, const char *,
89     const struct addrinfo *, void *);
90 struct asr_query *getnameinfo_async(const struct sockaddr *, socklen_t, char *,
91     size_t, char *, size_t, int, void *);
92 
93 /* only there for -portable */
94 void asr_freeaddrinfo(struct addrinfo *);
95 
96 /* from in event.h */
97 struct event_asr * event_asr_run(struct asr_query *,
98     void (*)(struct asr_result *, void *), void *);
99