From e42024f9b399c211a105ff53cf10ecad0efd1ce4 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 29 Jul 2023 11:52:36 +0800 Subject: update dynamic `sendto` parameter adaptively --- src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d45fe8a..b5c4e69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,11 @@ use std::io; use std::net::{SocketAddr, ToSocketAddrs}; - use std::time::{Duration, SystemTime, SystemTimeError}; use clap::{arg, Parser}; use tokio::net::UdpSocket; use tracing::{debug, error}; - use crate::Destination::{Address, SockAddr}; const TTL: Duration = Duration::from_secs(300); @@ -52,8 +50,8 @@ async fn main() { let local = args.local.parse().expect("failed to parse local address"); let mut sendto = Destination::None; let args_sendto: String; - if let Some(s) = args.sendto { - args_sendto = s; + if let Some(s) = &args.sendto { + args_sendto = s.clone(); sendto = Address(&args_sendto); } let mut addr_sendto: Option = None; @@ -71,8 +69,9 @@ async fn main() { i = 0; } } - if sendto == Destination::None && addr != local { - // assume the packet is coming from target + if args.sendto == None && addr != local { + // sendto is not defined by user and is determined dynamically + // we simply assume the last packet's sender is the target // update missing sendto parameter sendto = SockAddr(addr); } -- cgit v1.2.3