xref: /openbsd/include/asr.h (revision af4d66b3)
1 /*	$OpenBSD: asr.h,v 1.2 2019/10/24 05:57:41 otto 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  * Expected fd conditions
20  */
21 #define ASR_WANT_READ	1
22 #define ASR_WANT_WRITE	2
23 
24 /*
25  * Structure through which asynchronous query results are returned when
26  * calling asr_run().
27  */
28 struct asr_result {
29 	/* Fields set if the query is not done yet (asr_run returns 0) */
30 	int	 ar_cond;	/* ASR_WANT_READ or ASR_WANT_WRITE */
31 	int	 ar_fd;		/* the fd waiting for io condition */
32 	int	 ar_timeout;	/* time to wait for in milliseconds */
33 
34 	/* Error fields.  Depends on the query type. */
35 	int	 ar_errno;
36 	int	 ar_h_errno;
37 	int	 ar_gai_errno;
38 	int	 ar_rrset_errno;
39 
40 	/* Result for res_*_async() calls */
41 	int	 ar_count;	/* number of answers in the dns reply */
42 	int	 ar_rcode;	/* response code in the dns reply */
43 	void	*ar_data;	/* raw reply packet (must be freed) */
44 	int	 ar_datalen;	/* reply packet length */
45 	struct sockaddr_storage ar_ns; /* nameserver that responded */
46 
47 	/* Result for other calls. Must be freed properly. */
48 	struct addrinfo	 *ar_addrinfo;
49 	struct rrsetinfo *ar_rrsetinfo;
50 	struct hostent	 *ar_hostent;
51 	struct netent	 *ar_netent;
52 };
53 
54 /*
55  * Asynchronous query management.
56  */
57 
58 /* Forward declaration. The API uses opaque pointers as query handles. */
59 struct asr_query;
60 
61 void *asr_resolver_from_string(const char *);
62 void asr_resolver_free(void *);
63 int asr_run(struct asr_query *, struct asr_result *);
64 int asr_run_sync(struct asr_query *, struct asr_result *);
65 void asr_abort(struct asr_query *);
66 
67 /*
68  * Asynchronous version of the resolver functions. Similar prototypes, with
69  * an extra context parameter at the end which must currently be set to NULL.
70  * All functions return a handle suitable for use with the management functions
71  * above.
72  */
73 struct asr_query *res_send_async(const unsigned char *, int, void *);
74 struct asr_query *res_query_async(const char *, int, int, void *);
75 struct asr_query *res_search_async(const char *, int, int, void *);
76 
77 struct asr_query *getrrsetbyname_async(const char *, unsigned int, unsigned int,
78     unsigned int, void *);
79 
80 struct asr_query *gethostbyname_async(const char *, void *);
81 struct asr_query *gethostbyname2_async(const char *, int, void *);
82 struct asr_query *gethostbyaddr_async(const void *, socklen_t, int, void *);
83 
84 struct asr_query *getnetbyname_async(const char *, void *);
85 struct asr_query *getnetbyaddr_async(in_addr_t, int, void *);
86 
87 struct asr_query *getaddrinfo_async(const char *, const char *,
88     const struct addrinfo *, void *);
89 struct asr_query *getnameinfo_async(const struct sockaddr *, socklen_t, char *,
90     size_t, char *, size_t, int, void *);
91