rusdig

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)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() {
	let query = Query::for_name("にゃ.shop", RecordType::A);
	let bytes = query.as_bytes().unwrap();

	let socket = UdpSocket::bind(format!("0.0.0.0:{}", rand::thread_rng().gen_range(1001..64000))).unwrap();
	socket.connect("1.1.1.1:53").unwrap();
	socket.send(&bytes).unwrap();

	println!("Sent request");

	let mut buf = vec![0u8; 1024];
	let recvd = socket.recv(buf.as_mut_slice()).unwrap();
	buf.truncate(recvd);

	println!("Received response of length ({})", recvd);

	let query = Query::from_bytes(&buf).unwrap();

	for (i, question) in query.resource_queries.iter().enumerate() {
		println!("Question #{} of Type '{}':", i, question.ty_str());
		println!("  - For Name: {}", question.name());
	}

	for (i, answer) in query.resource_answers.iter().enumerate() {
		println!("Answer #{}:", i);
		match answer.entry_type() {
			RecordType::A | RecordType::NS => {
				println!("  - IPv4: {}", answer.data_as_ipv4().unwrap());
			}
			RecordType::AAAA => {
				println!("  - IPv6: {}", answer.data_as_ipv6().unwrap());
			}
			_ => {
				println!("  - Data: {}", answer.data_as_text().unwrap());
			}
		}
	}

	for (i, authoritative) in query.resource_authorities.iter().enumerate() {
		println!("Authority #{}: ", i);
		println!("  - For Name: {}", authoritative.name());
		println!("  - Primary Name Server: {}", authoritative.primary_ns());
		println!("  - Responsible Authority Mailbox: {}", authoritative.responsible_mail());
	}
}
source

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

Examples found in repository?
examples/resolve.rs (line 24)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() {
	let query = Query::for_name("にゃ.shop", RecordType::A);
	let bytes = query.as_bytes().unwrap();

	let socket = UdpSocket::bind(format!("0.0.0.0:{}", rand::thread_rng().gen_range(1001..64000))).unwrap();
	socket.connect("1.1.1.1:53").unwrap();
	socket.send(&bytes).unwrap();

	println!("Sent request");

	let mut buf = vec![0u8; 1024];
	let recvd = socket.recv(buf.as_mut_slice()).unwrap();
	buf.truncate(recvd);

	println!("Received response of length ({})", recvd);

	let query = Query::from_bytes(&buf).unwrap();

	for (i, question) in query.resource_queries.iter().enumerate() {
		println!("Question #{} of Type '{}':", i, question.ty_str());
		println!("  - For Name: {}", question.name());
	}

	for (i, answer) in query.resource_answers.iter().enumerate() {
		println!("Answer #{}:", i);
		match answer.entry_type() {
			RecordType::A | RecordType::NS => {
				println!("  - IPv4: {}", answer.data_as_ipv4().unwrap());
			}
			RecordType::AAAA => {
				println!("  - IPv6: {}", answer.data_as_ipv6().unwrap());
			}
			_ => {
				println!("  - Data: {}", answer.data_as_text().unwrap());
			}
		}
	}

	for (i, authoritative) in query.resource_authorities.iter().enumerate() {
		println!("Authority #{}: ", i);
		println!("  - For Name: {}", authoritative.name());
		println!("  - Primary Name Server: {}", authoritative.primary_ns());
		println!("  - Responsible Authority Mailbox: {}", authoritative.responsible_mail());
	}
}

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