diff --git a/src/rust/src/args.rs b/src/rust/src/args.rs index bdc6bcca5..7c73f2379 100644 --- a/src/rust/src/args.rs +++ b/src/rust/src/args.rs @@ -174,10 +174,9 @@ pub struct Args { pub segmentonkeyonly: bool, /// Read the input via UDP (listening in the specified port) /// instead of reading a file. - /// Host can be a - /// hostname or IPv4 address. If host is not specified - /// then listens on the local host. - #[arg(long, value_name="[host:]port", verbatim_doc_comment, help_heading=NETWORK_SUPPORT)] + /// Host and src can be a hostname or IPv4 address. + /// If host is not specified then listens on the local host. + #[arg(long, value_name="[[src@]host:]port", verbatim_doc_comment, help_heading=NETWORK_SUPPORT)] pub udp: Option, /// Can be a hostname or IPv4 address. #[arg(long, value_name="port", verbatim_doc_comment, help_heading=NETWORK_SUPPORT)] diff --git a/src/rust/src/parser.rs b/src/rust/src/parser.rs index 818ab6227..613183360 100644 --- a/src/rust/src/parser.rs +++ b/src/rust/src/parser.rs @@ -1321,23 +1321,33 @@ impl OptionsExt for Options { // Network stuff if let Some(ref udp) = args.udp { - if let Some(at) = udp.find('@') { - let addr = &udp[0..at]; - let port = &udp[at + 1..]; + let mut remaining_udp = udp.as_str(); - self.udpsrc = Some(udp.clone()); - self.udpaddr = Some(addr.to_owned()); - self.udpport = port.parse().unwrap(); - } else if let Some(colon) = udp.find(':') { - let addr = &udp[0..colon]; - let port = get_atoi_hex(&udp[colon + 1..]); + if let Some(at) = remaining_udp.find('@') { + let src = &remaining_udp[0..at]; + self.udpsrc = Some(src.to_owned()); + + remaining_udp = &remaining_udp[at + 1..]; + } + + if let Some(colon) = remaining_udp.find(':') { + let addr = &remaining_udp[0..colon]; + let port = get_atoi_hex(&remaining_udp[colon + 1..]); - self.udpsrc = Some(udp.clone()); self.udpaddr = Some(addr.to_owned()); self.udpport = port; } else { - self.udpaddr = None; - self.udpport = udp.parse().unwrap(); + match remaining_udp.parse() { + Ok(port) => { + self.udpport = port; + } + Err(_) => { + fatal!( + cause = ExitCause::MalformedParameter; + "Invalid UDP parameter\n" + ); + } + } } self.input_source = DataSource::Network;