libevent
|
00001 /* 00002 * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 00003 * Copyright (c) 2007-2010 Niels Provos and Nick Mathewson 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00017 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00018 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00019 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00020 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00021 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00022 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00023 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00025 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 /* 00029 * The original DNS code is due to Adam Langley with heavy 00030 * modifications by Nick Mathewson. Adam put his DNS software in the 00031 * public domain. You can find his original copyright below. Please, 00032 * aware that the code as part of Libevent is governed by the 3-clause 00033 * BSD license above. 00034 * 00035 * This software is Public Domain. To view a copy of the public domain dedication, 00036 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to 00037 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 00038 * 00039 * I ask and expect, but do not require, that all derivative works contain an 00040 * attribution similar to: 00041 * Parts developed by Adam Langley <agl@imperialviolet.org> 00042 * 00043 * You may wish to replace the word "Parts" with something else depending on 00044 * the amount of original code. 00045 * 00046 * (Derivative works does not include programs which link against, run or include 00047 * the source verbatim in their source distributions) 00048 */ 00049 00135 #ifndef _EVENT2_DNS_H_ 00136 #define _EVENT2_DNS_H_ 00137 00138 #ifdef __cplusplus 00139 extern "C" { 00140 #endif 00141 00142 /* For integer types. */ 00143 #include <event2/util.h> 00144 00146 #define DNS_ERR_NONE 0 00147 00148 #define DNS_ERR_FORMAT 1 00149 00151 #define DNS_ERR_SERVERFAILED 2 00152 00153 #define DNS_ERR_NOTEXIST 3 00154 00155 #define DNS_ERR_NOTIMPL 4 00156 00158 #define DNS_ERR_REFUSED 5 00159 00160 #define DNS_ERR_TRUNCATED 65 00161 00162 #define DNS_ERR_UNKNOWN 66 00163 00164 #define DNS_ERR_TIMEOUT 67 00165 00166 #define DNS_ERR_SHUTDOWN 68 00167 00168 #define DNS_ERR_CANCEL 69 00169 00170 #define DNS_IPv4_A 1 00171 #define DNS_PTR 2 00172 #define DNS_IPv6_AAAA 3 00173 00174 #define DNS_QUERY_NO_SEARCH 1 00175 00176 #define DNS_OPTION_SEARCH 1 00177 #define DNS_OPTION_NAMESERVERS 2 00178 #define DNS_OPTION_MISC 4 00179 #define DNS_OPTION_HOSTSFILE 8 00180 #define DNS_OPTIONS_ALL 15 00181 00182 /* Obsolete name for DNS_QUERY_NO_SEARCH */ 00183 #define DNS_NO_SEARCH DNS_QUERY_NO_SEARCH 00184 00195 typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg); 00196 00197 struct evdns_base; 00198 struct event_base; 00199 00212 struct evdns_base * evdns_base_new(struct event_base *event_base, int initialize_nameservers); 00213 00214 00227 void evdns_base_free(struct evdns_base *base, int fail_requests); 00228 00235 const char *evdns_err_to_string(int err); 00236 00237 00249 int evdns_base_nameserver_add(struct evdns_base *base, 00250 unsigned long int address); 00251 00264 int evdns_base_count_nameservers(struct evdns_base *base); 00265 00275 int evdns_base_clear_nameservers_and_suspend(struct evdns_base *base); 00276 00277 00288 int evdns_base_resume(struct evdns_base *base); 00289 00307 int evdns_base_nameserver_ip_add(struct evdns_base *base, 00308 const char *ip_as_string); 00309 00313 int 00314 evdns_base_nameserver_sockaddr_add(struct evdns_base *base, 00315 const struct sockaddr *sa, ev_socklen_t len, unsigned flags); 00316 00317 struct evdns_request; 00318 00330 struct evdns_request *evdns_base_resolve_ipv4(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr); 00331 00343 struct evdns_request *evdns_base_resolve_ipv6(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr); 00344 00345 struct in_addr; 00346 struct in6_addr; 00347 00359 struct evdns_request *evdns_base_resolve_reverse(struct evdns_base *base, const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr); 00360 00361 00373 struct evdns_request *evdns_base_resolve_reverse_ipv6(struct evdns_base *base, const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr); 00374 00382 void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req); 00383 00400 int evdns_base_set_option(struct evdns_base *base, const char *option, const char *val); 00401 00402 00425 int evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char *const filename); 00426 00437 int evdns_base_load_hosts(struct evdns_base *base, const char *hosts_fname); 00438 00449 #ifdef WIN32 00450 int evdns_base_config_windows_nameservers(struct evdns_base *); 00451 #define EVDNS_BASE_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED 00452 #endif 00453 00454 00458 void evdns_base_search_clear(struct evdns_base *base); 00459 00460 00466 void evdns_base_search_add(struct evdns_base *base, const char *domain); 00467 00468 00477 void evdns_base_search_ndots_set(struct evdns_base *base, const int ndots); 00478 00485 typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg); 00486 00487 00495 void evdns_set_log_fn(evdns_debug_log_fn_type fn); 00496 00507 void evdns_set_transaction_id_fn(ev_uint16_t (*fn)(void)); 00508 00518 void evdns_set_random_bytes_fn(void (*fn)(char *, size_t)); 00519 00520 /* 00521 * Functions used to implement a DNS server. 00522 */ 00523 00524 struct evdns_server_request; 00525 struct evdns_server_question; 00526 00538 typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, void *); 00539 #define EVDNS_ANSWER_SECTION 0 00540 #define EVDNS_AUTHORITY_SECTION 1 00541 #define EVDNS_ADDITIONAL_SECTION 2 00542 00543 #define EVDNS_TYPE_A 1 00544 #define EVDNS_TYPE_NS 2 00545 #define EVDNS_TYPE_CNAME 5 00546 #define EVDNS_TYPE_SOA 6 00547 #define EVDNS_TYPE_PTR 12 00548 #define EVDNS_TYPE_MX 15 00549 #define EVDNS_TYPE_TXT 16 00550 #define EVDNS_TYPE_AAAA 28 00551 00552 #define EVDNS_QTYPE_AXFR 252 00553 #define EVDNS_QTYPE_ALL 255 00554 00555 #define EVDNS_CLASS_INET 1 00556 00557 /* flags that can be set in answers; as part of the err parameter */ 00558 #define EVDNS_FLAGS_AA 0x400 00559 #define EVDNS_FLAGS_RD 0x080 00560 00571 struct evdns_server_port *evdns_add_server_port_with_base(struct event_base *base, evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data); 00573 void evdns_close_server_port(struct evdns_server_port *port); 00574 00578 void evdns_server_request_set_flags(struct evdns_server_request *req, int flags); 00579 00580 /* Functions to add an answer to an in-progress DNS reply. 00581 */ 00582 int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int dns_class, int ttl, int datalen, int is_name, const char *data); 00583 int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl); 00584 int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl); 00585 int evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl); 00586 int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl); 00587 00591 int evdns_server_request_respond(struct evdns_server_request *req, int err); 00595 int evdns_server_request_drop(struct evdns_server_request *req); 00596 struct sockaddr; 00600 int evdns_server_request_get_requesting_addr(struct evdns_server_request *_req, struct sockaddr *sa, int addr_len); 00601 00603 typedef void (*evdns_getaddrinfo_cb)(int result, struct evutil_addrinfo *res, void *arg); 00604 00605 struct evdns_base; 00606 struct evdns_getaddrinfo_request; 00624 struct evdns_getaddrinfo_request *evdns_getaddrinfo( 00625 struct evdns_base *dns_base, 00626 const char *nodename, const char *servname, 00627 const struct evutil_addrinfo *hints_in, 00628 evdns_getaddrinfo_cb cb, void *arg); 00629 00630 /* Cancel an in-progress evdns_getaddrinfo. This MUST NOT be called after the 00631 * getaddrinfo's callback has been invoked. The resolves will be canceled, 00632 * and the callback will be invoked with the error EVUTIL_EAI_CANCEL. */ 00633 void evdns_getaddrinfo_cancel(struct evdns_getaddrinfo_request *req); 00634 00635 #ifdef __cplusplus 00636 } 00637 #endif 00638 00639 #endif /* !_EVENT2_DNS_H_ */