pub fn ping(
        &self,
        hostname: IpAddr,
        ident: u16,
        seq_cnt: u16,
        timeout: Duration,
    ) -> PingFuture {
        let (sender, receiver) = oneshot::channel();

        let deadline = Instant::now() + timeout;

        let token = random();
        self.inner.state.insert(token, sender);

        let dest = SocketAddr::new(hostname, 0);
        let mut buffer = [0; ECHO_REQUEST_BUFFER_SIZE];

        let request = EchoRequest {
            ident,
            seq_cnt,
            payload: &token,
        };

        let (encode_result, mb_socket) = {
            if dest.is_ipv4() {
                (
                    request.encode::<IcmpV4>(&mut buffer[..]),
                    self.inner.sockets.v4().cloned(),
                )
            } else {
                (
                    request.encode::<IcmpV6>(&mut buffer[..]),
                    self.inner.sockets.v6().cloned(),
                )
            }
        };

        let socket = match mb_socket {
            Some(socket) => socket,
            None => {
                return PingFuture {
                    inner: PingFutureKind::InvalidProtocol,
                }
            }
        };

        if let Err(_) = encode_result {
            return PingFuture {
                inner: PingFutureKind::PacketEncodeError,
            };
        }

        let send_future = socket.send_to(buffer, &dest);

        PingFuture {
            inner: PingFutureKind::Normal(NormalPingFutureKind {
                start_time: Instant::now(),
                state: self.inner.state.clone(),
                token,
                sleep: Box::pin(sleep_until(deadline.into())),
                send: Some(send_future),
                receiver,
            }),
        }
    }
/// Send ICMP request and wait for response.
Send ICMP request and wait for response.
Send ICMP request and wait for response .
pub fn ping(
        &self,
        hostname: IpAddr,
        ident: u16,
        seq_cnt: u16,
        timeout: Duration,
    ) -> PingFuture {
        let (sender, receiver) = oneshot::channel();
        let deadline = Instant::now() + timeout;
        let token = random();
        self.inner.state.insert(token, sender);
        let dest = SocketAddr::new(hostname, 0);
        let mut buffer = [0; ECHO_REQUEST_BUFFER_SIZE];
        let request = EchoRequest {
            ident,
            seq_cnt,
            payload: &token,
        };
        let (encode_result, mb_socket) = {
            if dest.is_ipv4() {
                (
                    request.encode::<IcmpV4>(&mut buffer[..]),
                    self.inner.sockets.v4().cloned(),
                )
            } else {
                (
                    request.encode::<IcmpV6>(&mut buffer[..]),
                    self.inner.sockets.v6().cloned(),
                )
            }
        };
        let socket = match mb_socket {
            Some(socket) => socket,
            None => {
                return PingFuture {
                    inner: PingFutureKind::InvalidProtocol,
                }
            }
        };
        if let Err(_) = encode_result {
            return PingFuture {
                inner: PingFutureKind::PacketEncodeError,
            };
        }
        let send_future = socket.send_to(buffer, &dest);
        PingFuture {
            inner: PingFutureKind::Normal(NormalPingFutureKind {
                start_time: Instant::now(),
                state: self.inner.state.clone(),
                token,
                sleep: Box::pin(sleep_until(deadline.into())),
                send: Some(send_future),
                receiver,
            }),
        }
    }
pub fn ping ( & self , hostname : IpAddr , ident : u16 , seq_cnt : u16 , timeout : Duration , ) -> PingFuture { let ( sender , receiver ) = oneshot :: channel ( ) ; let deadline = Instant :: now ( ) + timeout ; let token = random ( ) ; self . inner . state . insert ( token , sender ) ; let dest = SocketAddr :: new ( hostname , 0 ) ; let mut buffer = [ 0 ; ECHO_REQUEST_BUFFER_SIZE ] ; let request = EchoRequest { ident , seq_cnt , payload : & token , } ; let ( encode_result , mb_socket ) = { if dest . is_ipv4 ( ) { ( request . encode :: < IcmpV4 > ( & mut buffer [ .. ] ) , self . inner . sockets . v4 ( ) . cloned ( ) , ) } else { ( request . encode :: < IcmpV6 > ( & mut buffer [ .. ] ) , self . inner . sockets . v6 ( ) . cloned ( ) , ) } } ; let socket = match mb_socket { Some ( socket ) => socket , None => { return PingFuture { inner : PingFutureKind :: InvalidProtocol , } } } ; if let Err ( _ ) = encode_result { return PingFuture { inner : PingFutureKind :: PacketEncodeError , } ; } let send_future = socket . send_to ( buffer , & dest ) ; PingFuture { inner : PingFutureKind :: Normal ( NormalPingFutureKind { start_time : Instant :: now ( ) , state : self . inner . state . clone ( ) , token , sleep : Box :: pin ( sleep_until ( deadline . into ( ) ) ) , send : Some ( send_future ) , receiver , } ) , } }
Send ICMP request and wait for response.
Send ICMP request and wait for response .
&self
hostname
IpAddr
ident
u16
seq_cnt
u16
timeout
Duration
&self
hostname
IpAddr
ident
u16
seq_cnt
u16
timeout
Duration