pub fn lookup(&self, name: &str) -> Result<Vec<IpAddr>, crate::Error> {
        let mut results = HashSet::new();

        // TODO Change this to make both DNS requests in parallel
        // If we returned a iterator, perhaps we could start to return entries
        // before they have all complete?

        // Send two queries, a A and a AAAA.
        for r#type in &[Type::A, Type::AAAA] {
            let mut query = Message::default();
            query.add_question(name, *r#type, Class::Internet);
            query.add_extension(Extension {
                payload_size: 4096, // Allow for bigger responses.

                ..Default::default()
            });

            let response = self.client.exchange(&query)?; // TODO Better error message

            println!(
                "{}: Trying {} and got {}",
                name,
                r#type,
                response.answers.len()
            );

            match response.rcode {
                Rcode::NoError => (), // Nothing
                _ => bail!(InvalidInput, "query failed with rcode: {}", response.rcode),
            };

            for answer in response.answers {
                // TODO Check the answer is for this question.
                match answer.resource {
                    Resource::A(ip4) => results.insert(IpAddr::V4(ip4)),
                    Resource::AAAA(ip6) => results.insert(IpAddr::V6(ip6)),
                    //Resource::A(ip4) => results.push(ip4),
                    _ => false, // Ignore other types
                };
            }
        }

        Ok(results.into_iter().collect())
    }
/// Resolves a name into one or more IP address.
//
/// See [rfc1035#section-7] and [rfc1034#section-5].
///
/// [rfc1035#section-7]: https://datatracker.ietf.org/doc/html/rfc1035#section-7
/// [rfc1034#section-5]: https://datatracker.ietf.org/doc/html/
// TODO Should this return a Iterator, or a Vector? Check other APIs.
// https://docs.rs/tokio/1.6.1/tokio/net/fn.lookup_host.html yield a iterator
Resolves a name into one or more IP address.


Resolves a name into one or more IP address .
pub fn lookup(&self, name: &str) -> Result<Vec<IpAddr>, crate::Error> {
        let mut results = HashSet::new();
        // TODO Change this to make both DNS requests in parallel
        // If we returned a iterator, perhaps we could start to return entries
        // before they have all complete?
        // Send two queries, a A and a AAAA.
        for r#type in &[Type::A, Type::AAAA] {
            let mut query = Message::default();
            query.add_question(name, *r#type, Class::Internet);
            query.add_extension(Extension {
                payload_size: 4096, // Allow for bigger responses.
                ..Default::default()
            });
            let response = self.client.exchange(&query)?; // TODO Better error message
            println!(
                "{}: Trying {} and got {}",
                name,
                r#type,
                response.answers.len()
            );
            match response.rcode {
                Rcode::NoError => (), // Nothing
                _ => bail!(InvalidInput, "query failed with rcode: {}", response.rcode),
            };
            for answer in response.answers {
                // TODO Check the answer is for this question.
                match answer.resource {
                    Resource::A(ip4) => results.insert(IpAddr::V4(ip4)),
                    Resource::AAAA(ip6) => results.insert(IpAddr::V6(ip6)),
                    //Resource::A(ip4) => results.push(ip4),
                    _ => false, // Ignore other types
                };
            }
        }
        Ok(results.into_iter().collect())
    }
pub fn lookup ( & self , name : & str ) -> Result < Vec < IpAddr > , crate :: Error > { let mut results = HashSet :: new ( ) ; // TODO Change this to make both DNS requests in parallel // If we returned a iterator, perhaps we could start to return entries // before they have all complete? // Send two queries, a A and a AAAA. for r#type in & [ Type :: A , Type :: AAAA ] { let mut query = Message :: default ( ) ; query . add_question ( name , * r#type , Class :: Internet ) ; query . add_extension ( Extension { payload_size : 4096 , // Allow for bigger responses. .. Default :: default ( ) } ) ; let response = self . client . exchange ( & query ) ? ; // TODO Better error message println ! ( " " name r#type response answers len ( ) ) ; match response . rcode { Rcode :: NoError => ( ) , // Nothing _ => bail ! ( InvalidInput " " response rcode ) , } ; for answer in response . answers { // TODO Check the answer is for this question. match answer . resource { Resource :: A ( ip4 ) => results . insert ( IpAddr :: V4 ( ip4 ) ) , Resource :: AAAA ( ip6 ) => results . insert ( IpAddr :: V6 ( ip6 ) ) , //Resource::A(ip4) => results.push(ip4), _ => false , // Ignore other types } ; } } Ok ( results . into_iter ( ) . collect ( ) ) }
Resolves a name into one or more IP address.
Resolves a name into one or more IP address .
&self
name
&str