udpproxi

Crates.ioudpproxi
lib.rsudpproxi
version0.1.1
sourcesrc
created_at2024-06-18 03:52:50.967811
updated_at2024-06-18 07:02:40.867794
descriptionudp forwarding library
homepage
repositoryhttps://github.com/xutianyi1999/udpproxi
max_upload_size
id1275109
size10,103
XTY (xutianyi1999)

documentation

README

udpproxi

udp forwarding library

A simple udp forwarding library that can easily manage udp sessions

Latest version Documentation License

Usage

link udpproxi crate

Cargo.toml

[dependencies]
udpproxi = "0.1"
tokio = { version = "1", features = ["full"] }

main.rs

use std::io::Result;
use std::net::{IpAddr, SocketAddr};
use std::sync::Arc;
use udpproxi::UdpProxi;

#[tokio::main]
async fn main() -> Result<()> {
    let bind = SocketAddr::from((IpAddr::from([127, 0, 0, 1]), 53));
    let forward_to = SocketAddr::from((IpAddr::from([8, 8, 8, 8]), 53));
    
    let socket = tokio::net::UdpSocket::bind(bind).await?;
    let socket = Arc::new(socket);

    let mut proxy = UdpProxi::new(socket.clone(), udpproxi::default_endpoint_creator);
    let mut buff = vec![0u8; 2048];
    
    loop {
        let (len, from) = socket.recv_from(&mut buff).await?;
        
        proxy.send_packet(
            &buff[..len],
            from,
            forward_to,
        ).await?;
    }
}
Commit count: 13

cargo fmt