hickory_client/
lib.rs

1/*
2 * Copyright (C) 2015 Benjamin Fry <benjaminfry@me.com>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// LIBRARY WARNINGS
18#![warn(
19    clippy::default_trait_access,
20    clippy::dbg_macro,
21    clippy::print_stdout,
22    clippy::unimplemented,
23    clippy::use_self,
24    missing_copy_implementations,
25    missing_docs,
26    non_snake_case,
27    non_upper_case_globals,
28    rust_2018_idioms,
29    unreachable_pub
30)]
31#![allow(
32    clippy::needless_doctest_main,
33    clippy::single_component_path_imports,
34    clippy::upper_case_acronyms, // can be removed on a major release boundary
35    clippy::bool_to_int_with_if,
36)]
37#![recursion_limit = "1024"]
38#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
39
40//! Hickory DNS is intended to be a fully compliant domain name server and client library.
41//!
42//! The Client library is responsible for the basic protocols responsible for communicating with DNS servers (authorities) and resolvers. It can be used for managing DNS records through the use of update operations. It is possible to send raw DNS Messages with the Client, but for ease of use the `query` and various other update operations are recommended for general use.
43//!
44//! For a system-like resolver, see [hickory-resolver](https://docs.rs/hickory-resolver). This is most likely what you want if all you want to do is lookup IP addresses.
45//!
46//! For serving DNS serving, see [hickory-server](https://docs.rs/hickory-server).
47//!
48//! # Goals
49//!
50//! * Only safe Rust
51//! * All errors handled
52//! * Simple to manage servers
53//! * High level abstraction for clients
54//! * Secure dynamic update
55//! * New features for securing public information
56//!
57//! # Usage
58//!
59//! This shows basic usage of the Client. More examples will be associated directly with other types.
60//!
61//! ## Dependency
62//!
63//! ```toml
64//! [dependencies]
65//! hickory-client = "*"
66//! ```
67//!
68//! By default DNSSEC validation is built in with OpenSSL, this can be disabled with:
69//!
70//! ```toml
71//! [dependencies]
72//! hickory-client = { version = "*", default-features = false }
73//! ```
74//!
75//! ## Objects
76//!
77//! There are two variations of implementations of the client: the [`client::Client`], an
78//! async client usually used with the Tokio runtime and the [`client::DnssecClient`], which
79//! validates DNSSEC records. For these basic examples we'll only look at the `Client`.
80//!
81//! First we must decide on the type of connection. For the purpose of this example, we'll
82//! show how to set up a TCP-based connection.
83//!
84//! This example is meant to show basic usage, using the `#[tokio::main]` macro to setup a simple
85//! runtime. The Tokio documentation should be reviewed for more advanced usage.
86//!
87//! ```rust
88//! use std::net::Ipv4Addr;
89//! use std::str::FromStr;
90//! use tokio::net::TcpStream as TokioTcpStream;
91//! use hickory_client::client::{Client, ClientHandle};
92//! use hickory_client::proto::runtime::TokioRuntimeProvider;
93//! use hickory_client::proto::rr::{DNSClass, Name, RData, RecordType};
94//! use hickory_client::proto::rr::rdata::A;
95//! use hickory_client::proto::tcp::TcpClientStream;
96//!
97//! #[tokio::main]
98//! async fn main() {
99//!     // Since we used UDP in the previous examples, let's change things up a bit and use TCP here
100//!     let (stream, sender) =
101//!         TcpClientStream::new(([8, 8, 8, 8], 53).into(), None, None, TokioRuntimeProvider::new());
102//!
103//!     // Create a new client, the bg is a background future which handles
104//!     //   the multiplexing of the DNS requests to the server.
105//!     //   the client is a handle to an unbounded queue for sending requests via the
106//!     //   background. The background must be scheduled to run before the client can
107//!     //   send any dns requests
108//!     let client = Client::new(stream, sender, None);
109//!
110//!     // await the connection to be established
111//!     let (mut client, bg) = client.await.expect("connection failed");
112//!
113//!     // make sure to run the background task
114//!     tokio::spawn(bg);
115//!
116//!     // Create a query future
117//!     let query = client.query(
118//!         Name::from_str("www.example.com.").unwrap(),
119//!         DNSClass::IN,
120//!         RecordType::A,
121//!    );
122//!
123//!     // wait for its response
124//!     let response = query.await.unwrap();
125//!
126//!     // validate it's what we expected
127//!     if let RData::A(addr) = response.answers()[0].data() {
128//!         assert_eq!(*addr, A::new(93, 184, 215, 14));
129//!     }
130//! }
131//! ```
132//!
133//! In the above example we successfully queried for a A record. There are many other types, each
134//! can be independently queried and the associated [`crate::proto::rr::record_data::RData`]
135//! has a variant with the deserialized data for the record stored.
136//!
137//! ## Dynamic update
138//!
139//! Currently `hickory-client` supports SIG(0) signed records for authentication and authorization
140//! of dynamic DNS updates. Consult the [`client::DnssecClient`] API for more information.
141
142pub mod client;
143mod error;
144pub use error::{Error as ClientError, ErrorKind as ClientErrorKind};
145#[cfg(test)]
146mod tests;
147
148pub use hickory_proto as proto;
149
150/// Returns a version as specified in Cargo.toml
151pub fn version() -> &'static str {
152    env!("CARGO_PKG_VERSION")
153}