Struct QueryQuestion

Source
pub struct QueryQuestion { /* private fields */ }

Implementations§

Source§

impl QueryQuestion

Source

pub fn new(name: &str, ty: RecordType) -> QueryQuestion

Source

pub fn as_bytes(&self) -> Result<Vec<u8>, DNSParseError>

Source

pub fn from_bytes(bytes: &mut &[u8]) -> Result<QueryQuestion, DNSParseError>

Source

pub fn name(&self) -> &str

Examples found in repository?
examples/resolve.rs (line 25)
5fn main() {
6	let query = Query::for_name("google.de", RecordType::A);
7	let bytes = query.as_bytes().unwrap();
8
9	let socket = UdpSocket::bind(format!("0.0.0.0:{}", rand::thread_rng().gen_range(1001..64000))).unwrap();
10	socket.connect("1.1.1.1:53").unwrap();
11	socket.send(&bytes).unwrap();
12
13	println!("Sent request");
14
15	let mut buf = vec![0u8; 1024];
16	let recvd = socket.recv(buf.as_mut_slice()).unwrap();
17	buf.truncate(recvd);
18
19	println!("Received response of length ({})", recvd);
20
21	let query = Query::from_bytes(&buf).unwrap();
22
23	for (i, question) in query.resource_queries.iter().enumerate() {
24		println!("Question #{} of Type '{}':", i, question.ty_str().unwrap_or("NOT IMPLEMENTED"));
25		println!("  - For Name: {}", question.name());
26	}
27
28	for (i, answer) in query.resource_answers.iter().enumerate() {
29		println!("Answer #{}:", i);
30		let entry_ty = answer.entry_type();
31
32		match entry_ty {
33			Some(RecordType::A | RecordType::NS) => {
34				println!("  - IPv4: {}", answer.data_as_ipv4().unwrap());
35			}
36			Some(RecordType::AAAA) => {
37				println!("  - IPv6: {}", answer.data_as_ipv6().unwrap());
38			}
39			_ => {
40				println!("  - Data: {}", answer.data_as_text().unwrap());
41			}
42		}
43	}
44
45	for (i, authoritative) in query.resource_authorities.iter().enumerate() {
46		println!("Authority #{}: ", i);
47		println!("  - For Name: {}", authoritative.name());
48		println!("  - Primary Name Server: {}", authoritative.primary_ns());
49		println!("  - Responsible Authority Mailbox: {}", authoritative.responsible_mail());
50	}
51}
Source

pub fn ty_str(&self) -> Option<&'static str>

Examples found in repository?
examples/resolve.rs (line 24)
5fn main() {
6	let query = Query::for_name("google.de", RecordType::A);
7	let bytes = query.as_bytes().unwrap();
8
9	let socket = UdpSocket::bind(format!("0.0.0.0:{}", rand::thread_rng().gen_range(1001..64000))).unwrap();
10	socket.connect("1.1.1.1:53").unwrap();
11	socket.send(&bytes).unwrap();
12
13	println!("Sent request");
14
15	let mut buf = vec![0u8; 1024];
16	let recvd = socket.recv(buf.as_mut_slice()).unwrap();
17	buf.truncate(recvd);
18
19	println!("Received response of length ({})", recvd);
20
21	let query = Query::from_bytes(&buf).unwrap();
22
23	for (i, question) in query.resource_queries.iter().enumerate() {
24		println!("Question #{} of Type '{}':", i, question.ty_str().unwrap_or("NOT IMPLEMENTED"));
25		println!("  - For Name: {}", question.name());
26	}
27
28	for (i, answer) in query.resource_answers.iter().enumerate() {
29		println!("Answer #{}:", i);
30		let entry_ty = answer.entry_type();
31
32		match entry_ty {
33			Some(RecordType::A | RecordType::NS) => {
34				println!("  - IPv4: {}", answer.data_as_ipv4().unwrap());
35			}
36			Some(RecordType::AAAA) => {
37				println!("  - IPv6: {}", answer.data_as_ipv6().unwrap());
38			}
39			_ => {
40				println!("  - Data: {}", answer.data_as_text().unwrap());
41			}
42		}
43	}
44
45	for (i, authoritative) in query.resource_authorities.iter().enumerate() {
46		println!("Authority #{}: ", i);
47		println!("  - For Name: {}", authoritative.name());
48		println!("  - Primary Name Server: {}", authoritative.primary_ns());
49		println!("  - Responsible Authority Mailbox: {}", authoritative.responsible_mail());
50	}
51}

Trait Implementations§

Source§

impl Debug for QueryQuestion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V