tokio-dstip

Crates.iotokio-dstip
lib.rstokio-dstip
version0.1.1
created_at2025-04-27 21:06:31.523566+00
updated_at2025-04-30 22:08:01.073964+00
descriptionGet a packet's destination IP address whilst using Tokio on Linux and macOS
homepage
repositoryhttps://github.com/SentryPeer/tokio-dstip
max_upload_size
id1651462
size34,689
Gavin Henry (ghenry)

documentation

README

tokio-dstip

Get a packet's destination IP address whilst using Tokio on Linux and macOS

Features

  • UDP destination IP address from incoming packets (Linux + macOS)
  • TCP destination IP address for accepted connections (Linux + macOS)
  • Native tokio::net compatibility
  • TLS-friendly: works with tokio_rustls and other wrappers

Crates.io MIT licensed CI

Install

[dependencies]
tokio-dstip = "0.1"

Usage

TCP

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(())
}

UDP

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(())
}

Examples

cargo run --example udp
cargo run --example tcp

License

MIT

Commit count: 13

cargo fmt