Crates.io | udpproxi |
lib.rs | udpproxi |
version | 0.1.1 |
source | src |
created_at | 2024-06-18 03:52:50.967811 |
updated_at | 2024-06-18 07:02:40.867794 |
description | udp forwarding library |
homepage | |
repository | https://github.com/xutianyi1999/udpproxi |
max_upload_size | |
id | 1275109 |
size | 10,103 |
udp forwarding library
A simple udp forwarding library that can easily manage udp sessions
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?;
}
}