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