| Crates.io | tokio-dstip |
| lib.rs | tokio-dstip |
| version | 0.1.1 |
| created_at | 2025-04-27 21:06:31.523566+00 |
| updated_at | 2025-04-30 22:08:01.073964+00 |
| description | Get a packet's destination IP address whilst using Tokio on Linux and macOS |
| homepage | |
| repository | https://github.com/SentryPeer/tokio-dstip |
| max_upload_size | |
| id | 1651462 |
| size | 34,689 |
Get a packet's destination IP address whilst using Tokio on Linux and macOS
tokio::net compatibilitytokio_rustls and other wrappers[dependencies]
tokio-dstip = "0.1"
use tokio_dstip::TcpListenerWithDst;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let listener = TcpListenerWithDst::bind("127.0.0.1:8080".parse().unwrap()).await?;
let (stream, peer, dst_ip) = listener.accept_with_dst().await?;
println!("Received from {peer}, destined to {dst_ip}");
Ok(())
}
use tokio_dstip::UdpSocketWithDst;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let sock = UdpSocketWithDst::bind("0.0.0.0:8080".parse().unwrap())?;
let (data, source, dst_ip) = sock.recv_from().await?;
println!("UDP from {source}, destined to {dst_ip}: {:?}", data);
Ok(())
}
cargo run --example udp
cargo run --example tcp
MIT