krata/crates/network/examples/ping.rs

22 lines
546 B
Rust
Raw Normal View History

2024-02-10 21:13:47 +00:00
use std::{net::Ipv6Addr, str::FromStr, time::Duration};
use anyhow::Result;
2024-02-21 20:57:46 +00:00
use kratanet::icmp::{IcmpClient, IcmpProtocol};
2024-02-10 21:13:47 +00:00
#[tokio::main]
async fn main() -> Result<()> {
let client = IcmpClient::new(IcmpProtocol::Icmpv6)?;
2024-02-10 21:13:47 +00:00
let payload: [u8; 4] = [12u8, 14u8, 16u8, 32u8];
let result = client
.ping6(
Ipv6Addr::from_str("2606:4700:4700::1111")?,
0,
1,
&payload,
Duration::from_secs(10),
)
.await?;
println!("reply: {:?}", result);
Ok(())
}