evdns.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Niels Provos <provos@citi.umich.edu>
00003  * All rights reserved.
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 
00160 #ifndef EVENTDNS_H
00161 #define EVENTDNS_H
00162 
00163 #ifdef __cplusplus
00164 extern "C" {
00165 #endif
00166 
00167 /* For integer types. */
00168 #include <evutil.h>
00169 
00171 #define DNS_ERR_NONE 0
00172 
00173 #define DNS_ERR_FORMAT 1
00174 
00176 #define DNS_ERR_SERVERFAILED 2
00177 
00178 #define DNS_ERR_NOTEXIST 3
00179 
00180 #define DNS_ERR_NOTIMPL 4
00181 
00183 #define DNS_ERR_REFUSED 5
00184 
00185 #define DNS_ERR_TRUNCATED 65
00186 
00187 #define DNS_ERR_UNKNOWN 66
00188 
00189 #define DNS_ERR_TIMEOUT 67
00190 
00191 #define DNS_ERR_SHUTDOWN 68
00192 
00193 #define DNS_IPv4_A 1
00194 #define DNS_PTR 2
00195 #define DNS_IPv6_AAAA 3
00196 
00197 #define DNS_QUERY_NO_SEARCH 1
00198 
00199 #define DNS_OPTION_SEARCH 1
00200 #define DNS_OPTION_NAMESERVERS 2
00201 #define DNS_OPTION_MISC 4
00202 #define DNS_OPTIONS_ALL 7
00203 
00211 typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
00212 
00223 int evdns_init(void);
00224 
00225 
00237 void evdns_shutdown(int fail_requests);
00238 
00239 
00246 const char *evdns_err_to_string(int err);
00247 
00248 
00259 int evdns_nameserver_add(unsigned long int address);
00260 
00261 
00273 int evdns_count_nameservers(void);
00274 
00275 
00284 int evdns_clear_nameservers_and_suspend(void);
00285 
00286 
00296 int evdns_resume(void);
00297 
00298 
00308 int evdns_nameserver_ip_add(const char *ip_as_string);
00309 
00310 
00321 int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr);
00322 
00323 
00334 int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr);
00335 
00336 struct in_addr;
00337 struct in6_addr;
00338 
00349 int evdns_resolve_reverse(struct in_addr *in, int flags, evdns_callback_type callback, void *ptr);
00350 
00351 
00362 int evdns_resolve_reverse_ipv6(struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr);
00363 
00364 
00377 int evdns_set_option(const char *option, const char *val, int flags);
00378 
00379 
00401 int evdns_resolv_conf_parse(int flags, const char *const filename);
00402 
00403 
00414 #ifdef MS_WINDOWS
00415 int evdns_config_windows_nameservers(void);
00416 #endif
00417 
00418 
00422 void evdns_search_clear(void);
00423 
00424 
00430 void evdns_search_add(const char *domain);
00431 
00432 
00441 void evdns_search_ndots_set(const int ndots);
00442 
00449 typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg);
00450 
00451 
00457 void evdns_set_log_fn(evdns_debug_log_fn_type fn);
00458 
00465 void evdns_set_transaction_id_fn(ev_uint16_t (*fn)(void));
00466 
00467 #define DNS_NO_SEARCH 1
00468 
00469 /*
00470  * Structures and functions used to implement a DNS server.
00471  */
00472 
00473 struct evdns_server_request {
00474         int flags;
00475         int nquestions;
00476         struct evdns_server_question **questions;
00477 };
00478 struct evdns_server_question {
00479         int type;
00480 #ifdef __cplusplus
00481         int dns_question_class;
00482 #else
00483         /* You should refer to this field as "dns_question_class".  The
00484          * name "class" works in C for backward compatibility, and will be
00485          * removed in a future version. (1.5 or later). */
00486         int class;
00487 #define dns_question_class class
00488 #endif
00489         char name[1];
00490 };
00491 typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, void *);
00492 #define EVDNS_ANSWER_SECTION 0
00493 #define EVDNS_AUTHORITY_SECTION 1
00494 #define EVDNS_ADDITIONAL_SECTION 2
00495 
00496 #define EVDNS_TYPE_A       1
00497 #define EVDNS_TYPE_NS      2
00498 #define EVDNS_TYPE_CNAME   5
00499 #define EVDNS_TYPE_SOA     6
00500 #define EVDNS_TYPE_PTR    12
00501 #define EVDNS_TYPE_MX     15
00502 #define EVDNS_TYPE_TXT    16
00503 #define EVDNS_TYPE_AAAA   28
00504 
00505 #define EVDNS_QTYPE_AXFR 252
00506 #define EVDNS_QTYPE_ALL  255
00507 
00508 #define EVDNS_CLASS_INET   1
00509 
00510 struct evdns_server_port *evdns_add_server_port(int socket, int is_tcp, evdns_request_callback_fn_type callback, void *user_data);
00511 void evdns_close_server_port(struct evdns_server_port *port);
00512 
00513 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);
00514 int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl);
00515 int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, void *addrs, int ttl);
00516 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);
00517 int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl);
00518 
00519 int evdns_server_request_respond(struct evdns_server_request *req, int err);
00520 int evdns_server_request_drop(struct evdns_server_request *req);
00521 struct sockaddr;
00522 int evdns_server_request_get_requesting_addr(struct evdns_server_request *_req, struct sockaddr *sa, int addr_len);
00523 
00524 #ifdef __cplusplus
00525 }
00526 #endif
00527 
00528 #endif  /* !EVENTDNS_H */

Generated on Fri Apr 11 08:26:23 2008 for libevent by  doxygen 1.5.3