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 * 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 int asr_run(struct asr_query *, struct asr_result *); 62 int asr_run_sync(struct asr_query *, struct asr_result *); 63 void asr_abort(struct asr_query *); 64 65 /* 66 * Asynchronous version of the resolver functions. Similar prototypes, with 67 * an extra context parameter at the end which must currently be set to NULL. 68 * All functions return a handle suitable for use with the management functions 69 * above. 70 */ 71 struct asr_query *res_send_async(const unsigned char *, int, void *); 72 struct asr_query *res_query_async(const char *, int, int, void *); 73 struct asr_query *res_search_async(const char *, int, int, void *); 74 75 struct asr_query *getrrsetbyname_async(const char *, unsigned int, unsigned int, 76 unsigned int, void *); 77 78 struct asr_query *gethostbyname_async(const char *, void *); 79 struct asr_query *gethostbyname2_async(const char *, int, void *); 80 struct asr_query *gethostbyaddr_async(const void *, socklen_t, int, void *); 81 82 struct asr_query *getnetbyname_async(const char *, void *); 83 struct asr_query *getnetbyaddr_async(in_addr_t, int, void *); 84 85 struct asr_query *getaddrinfo_async(const char *, const char *, 86 const struct addrinfo *, void *); 87 struct asr_query *getnameinfo_async(const struct sockaddr *, socklen_t, char *, 88 size_t, char *, size_t, int, void *); 89