1 /* 2 * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu> 3 * Copyright (c) 2007-2011 Niels Provos and Nick Mathewson 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * The original DNS code is due to Adam Langley with heavy 30 * modifications by Nick Mathewson. Adam put his DNS software in the 31 * public domain. You can find his original copyright below. Please, 32 * aware that the code as part of Libevent is governed by the 3-clause 33 * BSD license above. 34 * 35 * This software is Public Domain. To view a copy of the public domain dedication, 36 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to 37 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 38 * 39 * I ask and expect, but do not require, that all derivative works contain an 40 * attribution similar to: 41 * Parts developed by Adam Langley <agl@imperialviolet.org> 42 * 43 * You may wish to replace the word "Parts" with something else depending on 44 * the amount of original code. 45 * 46 * (Derivative works does not include programs which link against, run or include 47 * the source verbatim in their source distributions) 48 */ 49 50 /** @file event2/dns.h 51 * 52 * Welcome, gentle reader 53 * 54 * Async DNS lookups are really a whole lot harder than they should be, 55 * mostly stemming from the fact that the libc resolver has never been 56 * very good at them. Before you use this library you should see if libc 57 * can do the job for you with the modern async call getaddrinfo_a 58 * (see http://www.imperialviolet.org/page25.html#e498). Otherwise, 59 * please continue. 60 * 61 * The library keeps track of the state of nameservers and will avoid 62 * them when they go down. Otherwise it will round robin between them. 63 * 64 * Quick start guide: 65 * #include "evdns.h" 66 * void callback(int result, char type, int count, int ttl, 67 * void* addresses, void* arg); 68 * evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf"); 69 * evdns_resolve("www.hostname.com", 0, callback, NULL); 70 * 71 * When the lookup is complete the callback function is called. The 72 * first argument will be one of the DNS_ERR_* defines in evdns.h. 73 * Hopefully it will be DNS_ERR_NONE, in which case type will be 74 * DNS_IPv4_A, count will be the number of IP addresses, ttl is the time 75 * which the data can be cached for (in seconds), addresses will point 76 * to an array of uint32_t's and arg will be whatever you passed to 77 * evdns_resolve. 78 * 79 * Searching: 80 * 81 * In order for this library to be a good replacement for glibc's resolver it 82 * supports searching. This involves setting a list of default domains, in 83 * which names will be queried for. The number of dots in the query name 84 * determines the order in which this list is used. 85 * 86 * Searching appears to be a single lookup from the point of view of the API, 87 * although many DNS queries may be generated from a single call to 88 * evdns_resolve. Searching can also drastically slow down the resolution 89 * of names. 90 * 91 * To disable searching: 92 * 1. Never set it up. If you never call evdns_resolv_conf_parse or 93 * evdns_search_add then no searching will occur. 94 * 95 * 2. If you do call evdns_resolv_conf_parse then don't pass 96 * DNS_OPTION_SEARCH (or DNS_OPTIONS_ALL, which implies it). 97 * 98 * 3. When calling evdns_resolve, pass the DNS_QUERY_NO_SEARCH flag. 99 * 100 * The order of searches depends on the number of dots in the name. If the 101 * number is greater than the ndots setting then the names is first tried 102 * globally. Otherwise each search domain is appended in turn. 103 * 104 * The ndots setting can either be set from a resolv.conf, or by calling 105 * evdns_search_ndots_set. 106 * 107 * For example, with ndots set to 1 (the default) and a search domain list of 108 * ["myhome.net"]: 109 * Query: www 110 * Order: www.myhome.net, www. 111 * 112 * Query: www.abc 113 * Order: www.abc., www.abc.myhome.net 114 * 115 * Internals: 116 * 117 * Requests are kept in two queues. The first is the inflight queue. In 118 * this queue requests have an allocated transaction id and nameserver. 119 * They will soon be transmitted if they haven't already been. 120 * 121 * The second is the waiting queue. The size of the inflight ring is 122 * limited and all other requests wait in waiting queue for space. This 123 * bounds the number of concurrent requests so that we don't flood the 124 * nameserver. Several algorithms require a full walk of the inflight 125 * queue and so bounding its size keeps thing going nicely under huge 126 * (many thousands of requests) loads. 127 * 128 * If a nameserver loses too many requests it is considered down and we 129 * try not to use it. After a while we send a probe to that nameserver 130 * (a lookup for google.com) and, if it replies, we consider it working 131 * again. If the nameserver fails a probe we wait longer to try again 132 * with the next probe. 133 */ 134 module deimos.event2.dns; 135 136 137 extern (C): 138 nothrow: 139 140 public import deimos.event2.event_struct; 141 /* For integer types. */ 142 public import deimos.event2.util; 143 import deimos.event2._d_util; 144 145 /** Error codes 0-5 are as described in RFC 1035. */ 146 enum DNS_ERR_NONE = 0; 147 /** The name server was unable to interpret the query */ 148 enum DNS_ERR_FORMAT = 1; 149 /** The name server was unable to process this query due to a problem with the 150 * name server */ 151 enum DNS_ERR_SERVERFAILED = 2; 152 /** The domain name does not exist */ 153 enum DNS_ERR_NOTEXIST = 3; 154 /** The name server does not support the requested kind of query */ 155 enum DNS_ERR_NOTIMPL = 4; 156 /** The name server refuses to reform the specified operation for policy 157 * reasons */ 158 enum DNS_ERR_REFUSED = 5; 159 /** The reply was truncated or ill-formatted */ 160 enum DNS_ERR_TRUNCATED = 65; 161 /** An unknown error occurred */ 162 enum DNS_ERR_UNKNOWN = 66; 163 /** Communication with the server timed out */ 164 enum DNS_ERR_TIMEOUT = 67; 165 /** The request was canceled because the DNS subsystem was shut down. */ 166 enum DNS_ERR_SHUTDOWN = 68; 167 /** The request was canceled via a call to evdns_cancel_request */ 168 enum DNS_ERR_CANCEL = 69; 169 /** There were no answers and no error condition in the DNS packet. 170 * This can happen when you ask for an address that exists, but a record 171 * type that doesn't. */ 172 enum DNS_ERR_NODATA = 70; 173 174 enum DNS_IPv4_A = 1; 175 enum DNS_PTR = 2; 176 enum DNS_IPv6_AAAA = 3; 177 178 enum DNS_QUERY_NO_SEARCH = 1; 179 180 enum DNS_OPTION_SEARCH = 1; 181 enum DNS_OPTION_NAMESERVERS = 2; 182 enum DNS_OPTION_MISC = 4; 183 enum DNS_OPTION_HOSTSFILE = 8; 184 enum DNS_OPTIONS_ALL = 15; 185 186 /* Obsolete name for DNS_QUERY_NO_SEARCH */ 187 enum DNS_NO_SEARCH = DNS_QUERY_NO_SEARCH; 188 189 /** 190 * The callback that contains the results from a lookup. 191 * - result is one of the DNS_ERR_* values (DNS_ERR_NONE for success) 192 * - type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA 193 * - count contains the number of addresses of form type 194 * - ttl is the number of seconds the resolution may be cached for. 195 * - addresses needs to be cast according to type. It will be an array of 196 * 4-byte sequences for ipv4, or an array of 16-byte sequences for ipv6, 197 * or a nul-terminated string for PTR. 198 */ 199 alias ExternC!(void function(int result, char type, int count, int ttl, void* addresses, void* arg)) evdns_callback_type; 200 201 struct evdns_base; 202 203 /** 204 Initialize the asynchronous DNS library. 205 206 This function initializes support for non-blocking name resolution by 207 calling evdns_resolv_conf_parse() on UNIX and 208 evdns_config_windows_nameservers() on Windows. 209 210 @param event_base the event base to associate the dns client with 211 @param initialize_nameservers 1 if resolve.conf processing should occur 212 @return evdns_base object if successful, or NULL if an error occurred. 213 @see evdns_base_free() 214 */ 215 evdns_base* evdns_base_new(event_base* event_base, int initialize_nameservers); 216 217 218 /** 219 Shut down the asynchronous DNS resolver and terminate all active requests. 220 221 If the 'fail_requests' option is enabled, all active requests will return 222 an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise, 223 the requests will be silently discarded. 224 225 @param evdns_base the evdns base to free 226 @param fail_requests if zero, active requests will be aborted; if non-zero, 227 active requests will return DNS_ERR_SHUTDOWN. 228 @see evdns_base_new() 229 */ 230 void evdns_base_free(evdns_base* base, int fail_requests); 231 232 /** 233 Convert a DNS error code to a string. 234 235 @param err the DNS error code 236 @return a string containing an explanation of the error code 237 */ 238 const(char)* evdns_err_to_string(int err); 239 240 241 /** 242 Add a nameserver. 243 244 The address should be an IPv4 address in network byte order. 245 The type of address is chosen so that it matches in_addr.s_addr. 246 247 @param base the evdns_base to which to add the name server 248 @param address an IP address in network byte order 249 @return 0 if successful, or -1 if an error occurred 250 @see evdns_base_nameserver_ip_add() 251 */ 252 int evdns_base_nameserver_add(evdns_base* base, 253 c_ulong address); 254 255 /** 256 Get the number of configured nameservers. 257 258 This returns the number of configured nameservers (not necessarily the 259 number of running nameservers). This is useful for double-checking 260 whether our calls to the various nameserver configuration functions 261 have been successful. 262 263 @param base the evdns_base to which to apply this operation 264 @return the number of configured nameservers 265 @see evdns_base_nameserver_add() 266 */ 267 int evdns_base_count_nameservers(evdns_base* base); 268 269 /** 270 Remove all configured nameservers, and suspend all pending resolves. 271 272 Resolves will not necessarily be re-attempted until evdns_base_resume() is called. 273 274 @param base the evdns_base to which to apply this operation 275 @return 0 if successful, or -1 if an error occurred 276 @see evdns_base_resume() 277 */ 278 int evdns_base_clear_nameservers_and_suspend(evdns_base* base); 279 280 281 /** 282 Resume normal operation and continue any suspended resolve requests. 283 284 Re-attempt resolves left in limbo after an earlier call to 285 evdns_base_clear_nameservers_and_suspend(). 286 287 @param base the evdns_base to which to apply this operation 288 @return 0 if successful, or -1 if an error occurred 289 @see evdns_base_clear_nameservers_and_suspend() 290 */ 291 int evdns_base_resume(evdns_base* base); 292 293 /** 294 Add a nameserver by string address. 295 296 This function parses a n IPv4 or IPv6 address from a string and adds it as a 297 nameserver. It supports the following formats: 298 - [IPv6Address]:port 299 - [IPv6Address] 300 - IPv6Address 301 - IPv4Address:port 302 - IPv4Address 303 304 If no port is specified, it defaults to 53. 305 306 @param base the evdns_base to which to apply this operation 307 @return 0 if successful, or -1 if an error occurred 308 @see evdns_base_nameserver_add() 309 */ 310 int evdns_base_nameserver_ip_add(evdns_base* base, 311 const(char)* ip_as_string); 312 313 /** 314 Add a nameserver by sockaddr. 315 **/ 316 int 317 evdns_base_nameserver_sockaddr_add(evdns_base* base, 318 const(sockaddr)* sa, ev_socklen_t len, uint flags); 319 320 struct evdns_request; 321 322 /** 323 Lookup an A record for a given name. 324 325 @param base the evdns_base to which to apply this operation 326 @param name a DNS hostname 327 @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 328 @param callback a callback function to invoke when the request is completed 329 @param ptr an argument to pass to the callback function 330 @return an evdns_request object if successful, or NULL if an error occurred. 331 @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request() 332 */ 333 evdns_request* evdns_base_resolve_ipv4(evdns_base* base, const(char)* name, int flags, evdns_callback_type callback, void* ptr); 334 335 /** 336 Lookup an AAAA record for a given name. 337 338 @param base the evdns_base to which to apply this operation 339 @param name a DNS hostname 340 @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 341 @param callback a callback function to invoke when the request is completed 342 @param ptr an argument to pass to the callback function 343 @return an evdns_request object if successful, or NULL if an error occurred. 344 @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request() 345 */ 346 evdns_request* evdns_base_resolve_ipv6(evdns_base* base, const(char)* name, int flags, evdns_callback_type callback, void* ptr); 347 348 struct in_addr; 349 struct in6_addr; 350 351 /** 352 Lookup a PTR record for a given IP address. 353 354 @param base the evdns_base to which to apply this operation 355 @param in an IPv4 address 356 @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 357 @param callback a callback function to invoke when the request is completed 358 @param ptr an argument to pass to the callback function 359 @return an evdns_request object if successful, or NULL if an error occurred. 360 @see evdns_resolve_reverse_ipv6(), evdns_cancel_request() 361 */ 362 evdns_request* evdns_base_resolve_reverse(evdns_base* base, const(in_addr)* in_, int flags, evdns_callback_type callback, void* ptr); 363 364 365 /** 366 Lookup a PTR record for a given IPv6 address. 367 368 @param base the evdns_base to which to apply this operation 369 @param in an IPv6 address 370 @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. 371 @param callback a callback function to invoke when the request is completed 372 @param ptr an argument to pass to the callback function 373 @return an evdns_request object if successful, or NULL if an error occurred. 374 @see evdns_resolve_reverse_ipv6(), evdns_cancel_request() 375 */ 376 evdns_request* evdns_base_resolve_reverse_ipv6(evdns_base* base, const in6_addr* in_, int flags, evdns_callback_type callback, void* ptr); 377 378 /** 379 Cancels a pending DNS resolution request. 380 381 @param base the evdns_base that was used to make the request 382 @param req the evdns_request that was returned by calling a resolve function 383 @see evdns_base_resolve_ipv4(), evdns_base_resolve_ipv6, evdns_base_resolve_reverse 384 */ 385 void evdns_cancel_request(evdns_base* base, evdns_request* req); 386 387 /** 388 Set the value of a configuration option. 389 390 The currently available configuration options are: 391 392 ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case, 393 bind-to, initial-probe-timeout, getaddrinfo-allow-skew. 394 395 In versions before Libevent 2.0.3-alpha, the option name needed to end with 396 a colon. 397 398 @param base the evdns_base to which to apply this operation 399 @param option the name of the configuration option to be modified 400 @param val the value to be set 401 @return 0 if successful, or -1 if an error occurred 402 */ 403 int evdns_base_set_option(evdns_base* base, const(char)* option, const(char)* val); 404 405 406 /** 407 Parse a resolv.conf file. 408 409 The 'flags' parameter determines what information is parsed from the 410 resolv.conf file. See the man page for resolv.conf for the format of this 411 file. 412 413 The following directives are not parsed from the file: sortlist, rotate, 414 no-check-names, inet6, debug. 415 416 If this function encounters an error, the possible return values are: 1 = 417 failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of 418 memory, 5 = short read from file, 6 = no nameservers listed in the file 419 420 @param base the evdns_base to which to apply this operation 421 @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC| 422 DNS_OPTIONS_HOSTSFILE|DNS_OPTIONS_ALL 423 @param filename the path to the resolv.conf file 424 @return 0 if successful, or various positive error codes if an error 425 occurred (see above) 426 @see resolv.conf(3), evdns_config_windows_nameservers() 427 */ 428 int evdns_base_resolv_conf_parse(evdns_base* base, int flags, const(char)* filename); 429 430 /** 431 Load an /etc/hosts-style file from 'hosts_fname' into 'base'. 432 433 If hosts_fname is NULL, add minimal entries for localhost, and nothing 434 else. 435 436 Note that only evdns_getaddrinfo uses the /etc/hosts entries. 437 438 Return 0 on success, negative on failure. 439 */ 440 int evdns_base_load_hosts(evdns_base* base, const(char)* hosts_fname); 441 442 /** 443 Obtain nameserver information using the Windows API. 444 445 Attempt to configure a set of nameservers based on platform settings on 446 a win32 host. Preferentially tries to use GetNetworkParams; if that fails, 447 looks in the registry. 448 449 @return 0 if successful, or -1 if an error occurred 450 @see evdns_resolv_conf_parse() 451 */ 452 version (Win32) { 453 int evdns_base_config_windows_nameservers(evdns_base*); 454 enum EVDNS_BASE_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED = 1; 455 } 456 457 458 /** 459 Clear the list of search domains. 460 */ 461 void evdns_base_search_clear(evdns_base* base); 462 463 464 /** 465 Add a domain to the list of search domains 466 467 @param domain the domain to be added to the search list 468 */ 469 void evdns_base_search_add(evdns_base* base, const(char)* domain_); 470 471 472 /** 473 Set the 'ndots' parameter for searches. 474 475 Sets the number of dots which, when found in a name, causes 476 the first query to be without any search domain. 477 478 @param ndots the new ndots parameter 479 */ 480 void evdns_base_search_ndots_set(evdns_base* base, const int ndots); 481 482 /** 483 A callback that is invoked when a log message is generated 484 485 @param is_warning indicates if the log message is a 'warning' 486 @param msg the content of the log message 487 */ 488 alias ExternC!(void function(int is_warning, const(char)* msg)) evdns_debug_log_fn_type; 489 490 491 /** 492 Set the callback function to handle DNS log messages. If this 493 callback is not set, evdns log messages are handled with the regular 494 Libevent logging system. 495 496 @param fn the callback to be invoked when a log message is generated 497 */ 498 void evdns_set_log_fn(evdns_debug_log_fn_type fn); 499 500 /** 501 Set a callback that will be invoked to generate transaction IDs. By 502 default, we pick transaction IDs based on the current clock time, which 503 is bad for security. 504 505 @param fn the new callback, or NULL to use the default. 506 507 NOTE: This function has no effect in Libevent 2.0.4-alpha and later, 508 since Libevent now provides its own secure RNG. 509 */ 510 void evdns_set_transaction_id_fn(ExternC!(ev_uint16_t function()) fn); 511 512 /** 513 Set a callback used to generate random bytes. By default, we use 514 the same function as passed to evdns_set_transaction_id_fn to generate 515 bytes two at a time. If a function is provided here, it's also used 516 to generate transaction IDs. 517 518 NOTE: This function has no effect in Libevent 2.0.4-alpha and later, 519 since Libevent now provides its own secure RNG. 520 */ 521 void evdns_set_random_bytes_fn(ExternC!(void function(char*, size_t)) fn); 522 523 /* 524 * Functions used to implement a DNS server. 525 */ 526 527 struct evdns_server_request; 528 struct evdns_server_question; 529 530 /** 531 A callback to implement a DNS server. The callback function receives a DNS 532 request. It should then optionally add a number of answers to the reply 533 using the evdns_server_request_add_*_reply functions, before calling either 534 evdns_server_request_respond to send the reply back, or 535 evdns_server_request_drop to decline to answer the request. 536 537 @param req A newly received request 538 @param user_data A pointer that was passed to 539 evdns_add_server_port_with_base(). 540 */ 541 alias ExternC!(void function(evdns_server_request*, void*)) evdns_request_callback_fn_type; 542 enum EVDNS_ANSWER_SECTION = 0; 543 enum EVDNS_AUTHORITY_SECTION = 1; 544 enum EVDNS_ADDITIONAL_SECTION = 2; 545 546 enum EVDNS_TYPE_A = 1; 547 enum EVDNS_TYPE_NS = 2; 548 enum EVDNS_TYPE_CNAME = 5; 549 enum EVDNS_TYPE_SOA = 6; 550 enum EVDNS_TYPE_PTR = 12; 551 enum EVDNS_TYPE_MX = 15; 552 enum EVDNS_TYPE_TXT = 16; 553 enum EVDNS_TYPE_AAAA = 28; 554 555 enum EVDNS_QTYPE_AXFR = 252; 556 enum EVDNS_QTYPE_ALL = 255; 557 558 enum EVDNS_CLASS_INET = 1; 559 560 /* flags that can be set in answers; as part of the err parameter */ 561 enum EVDNS_FLAGS_AA = 0x400; 562 enum EVDNS_FLAGS_RD = 0x080; 563 564 struct evdns_server_port; 565 /** Create a new DNS server port. 566 567 @param base The event base to handle events for the server port. 568 @param socket A UDP socket to accept DNS requests. 569 @param flags Always 0 for now. 570 @param callback A function to invoke whenever we get a DNS request 571 on the socket. 572 @param user_data Data to pass to the callback. 573 @return an evdns_server_port structure for this server port. 574 */ 575 evdns_server_port* evdns_add_server_port_with_base(event_base* base, evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void* user_data); 576 /** Close down a DNS server port, and free associated structures. */ 577 void evdns_close_server_port(evdns_server_port* port); 578 579 /** Sets some flags in a reply we're building. 580 Allows setting of the AA or RD flags 581 */ 582 void evdns_server_request_set_flags(evdns_server_request* req, int flags); 583 584 /* Functions to add an answer to an in-progress DNS reply. 585 */ 586 int evdns_server_request_add_reply(evdns_server_request* req, int section, const(char)* name, int type, int dns_class, int ttl, int datalen, int is_name, const(char)* data); 587 int evdns_server_request_add_a_reply(evdns_server_request* req, const(char)* name, int n, const(void)* addrs, int ttl); 588 int evdns_server_request_add_aaaa_reply(evdns_server_request* req, const(char)* name, int n, const(void)* addrs, int ttl); 589 int evdns_server_request_add_ptr_reply(evdns_server_request* req, in_addr* in_, const(char)* inaddr_name, const(char)* hostname, int ttl); 590 int evdns_server_request_add_cname_reply(evdns_server_request* req, const(char)* name, const(char)* cname, int ttl); 591 592 /** 593 Send back a response to a DNS request, and free the request structure. 594 */ 595 int evdns_server_request_respond(evdns_server_request* req, int err); 596 /** 597 Free a DNS request without sending back a reply. 598 */ 599 int evdns_server_request_drop(evdns_server_request* req); 600 601 /** 602 Get the address that made a DNS request. 603 */ 604 int evdns_server_request_get_requesting_addr(evdns_server_request* _req, sockaddr* sa, int addr_len); 605 606 /** Callback for evdns_getaddrinfo. */ 607 alias ExternC!(void function(int result, evutil_addrinfo* res, void* arg)) evdns_getaddrinfo_cb; 608 609 struct evdns_getaddrinfo_request; 610 /** Make a non-blocking getaddrinfo request using the dns_base in 'dns_base'. 611 * 612 * If we can answer the request immediately (with an error or not!), then we 613 * invoke cb immediately and return NULL. Otherwise we return 614 * an evdns_getaddrinfo_request and invoke cb later. 615 * 616 * When the callback is invoked, we pass as its first argument the error code 617 * that getaddrinfo would return (or 0 for no error). As its second argument, 618 * we pass the evutil_addrinfo structures we found (or NULL on error). We 619 * pass 'arg' as the third argument. 620 * 621 * Limitations: 622 * 623 * - The AI_V4MAPPED and AI_ALL flags are not currently implemented. 624 * - For ai_socktype, we only handle SOCKTYPE_STREAM, SOCKTYPE_UDP, and 0. 625 * - For ai_protocol, we only handle IPPROTO_TCP, IPPROTO_UDP, and 0. 626 */ 627 evdns_getaddrinfo_request* evdns_getaddrinfo( 628 evdns_base* dns_base, 629 const(char)* nodename, const(char)* servname, 630 const(evutil_addrinfo)* hints_in_, 631 evdns_getaddrinfo_cb cb, void* arg); 632 633 /* Cancel an in-progress evdns_getaddrinfo. This MUST NOT be called after the 634 * getaddrinfo's callback has been invoked. The resolves will be canceled, 635 * and the callback will be invoked with the error EVUTIL_EAI_CANCEL. */ 636 void evdns_getaddrinfo_cancel(evdns_getaddrinfo_request* req);