Add OPT record handling.

This commit is contained in:
Martin Hoffmann
2016-06-29 17:28:45 +02:00
parent bd53e0d7f7
commit cfe7bc2469
8 changed files with 1598 additions and 14 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ Eventually, this crate will provide the following functions:
* [X] querying for host names,
* [ ] reverse host name queries,
* [X] reverse host name queries,
* [ ] querying for mail servers (MX records),
+4
View File
@@ -98,6 +98,9 @@ pub enum ParseError {
/// A compressed label was encountered in a `DNameRef` or `OwnedDName`.
CompressedLabel,
/// A format error was encountered.
FormErr,
}
impl Error for ParseError {
@@ -108,6 +111,7 @@ impl Error for ParseError {
UnexpectedEnd => "unexpected end of data",
UnknownLabel => "unknown label type in domain name",
CompressedLabel => "a compressed label was encountered",
FormErr => "format error",
}
}
}
+3 -3
View File
@@ -14,9 +14,9 @@ use super::parse::ParseBytes;
/// Arbitrary bytes data.
///
/// This type can be used to refer an arbitrary sequence of bytes in DNS data.
/// Such a sequence is often used by record data definitions and cover the
/// remainder of the record data. Under the hood, this type is actually a
/// This type can be used to refer to an arbitrary sequence of bytes in DNS
/// data. Such a sequence is often used by record data definitions and cover
/// the remainder of the record data. Under the hood, this type is actually a
/// `Cow<[u8]>` and derefs into one, giving you all of `Cow`’s methods and,
/// transitively, all of bytes slice’s methods.
///
+6
View File
@@ -67,6 +67,12 @@ pub trait ParseBytes<'a>: Sized + Clone {
})
}
/// Parses the rest of the parser.
fn parse_left(&mut self) -> ParseResult<&'a [u8]> {
let len = self.left();
self.parse_bytes(len)
}
/// Creates a sup-parser starting a the current position.
///
/// XXX This is identical to `clone()`, so maybe we should ditch it?
+1 -1
View File
@@ -20,7 +20,7 @@ use super::nest::Nest;
use super::parse::ParseBytes;
///----------- RecordData ------------------------------------------------
//----------- RecordData ------------------------------------------------
/// A trait for parsing and composing record data.
pub trait RecordData<'a>: fmt::Display + Sized {
+6 -1
View File
@@ -30,7 +30,7 @@ use super::rdata::RecordData;
/// the type is generic over a `RecordData` trait that represents the
/// concrete record data of the type.
///
/// Thus, most often when using records, you use specify it in terms of the
/// Thus, most often when using records, you specify it in terms of the
/// record data it contains. For instance, a resource record of type
/// `RRType::A`, generally called an A record, can be given as `Record<A>`
/// (with the type `A` actually being `domain::rdata::A`).
@@ -114,6 +114,11 @@ impl<'a, D: RecordData<'a>> Record<'a, D> {
pub fn rdata_mut(&mut self) -> &mut D {
&mut self.rdata
}
/// Converts the record into its record data.
pub fn into_rdata(self) -> D {
self.rdata
}
}
/// Parsing and Composing
+2 -2
View File
@@ -4,8 +4,8 @@
//! System. Currently, these are:
//!
//! * fundamental types, traits, and implementations for dealing with DNS
//! data through the modules [bits](bits/index.html) and
//! [rdata](rdata/index.html),
//! data through the modules [bits](bits/index.html),
//! [rdata](rdata/index.html), and [iana](iana/index.html),
//! * an asynchronous stub resolver implementation for querying the DNS
//! in [resolv](resolv/index.html).
+1575 -6
View File
File diff suppressed because it is too large Load Diff