Skip to content

Commit 654d00a

Browse files
authored
[FIX] Rust: fix unsetting source udp address when not specified by the user (#1750)
* Rust: fix unsetting source udp address when not specified by the user * Rust: Fix `--udp [[src@]host:]port` parameter
1 parent d86ee72 commit 654d00a

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/rust/src/args.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ pub struct Args {
174174
pub segmentonkeyonly: bool,
175175
/// Read the input via UDP (listening in the specified port)
176176
/// instead of reading a file.
177-
/// Host can be a
178-
/// hostname or IPv4 address. If host is not specified
179-
/// then listens on the local host.
180-
#[arg(long, value_name="[host:]port", verbatim_doc_comment, help_heading=NETWORK_SUPPORT)]
177+
/// Host and src can be a hostname or IPv4 address.
178+
/// If host is not specified then listens on the local host.
179+
#[arg(long, value_name="[[src@]host:]port", verbatim_doc_comment, help_heading=NETWORK_SUPPORT)]
181180
pub udp: Option<String>,
182181
/// Can be a hostname or IPv4 address.
183182
#[arg(long, value_name="port", verbatim_doc_comment, help_heading=NETWORK_SUPPORT)]

src/rust/src/parser.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,23 +1321,33 @@ impl OptionsExt for Options {
13211321

13221322
// Network stuff
13231323
if let Some(ref udp) = args.udp {
1324-
if let Some(at) = udp.find('@') {
1325-
let addr = &udp[0..at];
1326-
let port = &udp[at + 1..];
1324+
let mut remaining_udp = udp.as_str();
13271325

1328-
self.udpsrc = Some(udp.clone());
1329-
self.udpaddr = Some(addr.to_owned());
1330-
self.udpport = port.parse().unwrap();
1331-
} else if let Some(colon) = udp.find(':') {
1332-
let addr = &udp[0..colon];
1333-
let port = get_atoi_hex(&udp[colon + 1..]);
1326+
if let Some(at) = remaining_udp.find('@') {
1327+
let src = &remaining_udp[0..at];
1328+
self.udpsrc = Some(src.to_owned());
1329+
1330+
remaining_udp = &remaining_udp[at + 1..];
1331+
}
1332+
1333+
if let Some(colon) = remaining_udp.find(':') {
1334+
let addr = &remaining_udp[0..colon];
1335+
let port = get_atoi_hex(&remaining_udp[colon + 1..]);
13341336

1335-
self.udpsrc = Some(udp.clone());
13361337
self.udpaddr = Some(addr.to_owned());
13371338
self.udpport = port;
13381339
} else {
1339-
self.udpaddr = None;
1340-
self.udpport = udp.parse().unwrap();
1340+
match remaining_udp.parse() {
1341+
Ok(port) => {
1342+
self.udpport = port;
1343+
}
1344+
Err(_) => {
1345+
fatal!(
1346+
cause = ExitCause::MalformedParameter;
1347+
"Invalid UDP parameter\n"
1348+
);
1349+
}
1350+
}
13411351
}
13421352

13431353
self.input_source = DataSource::Network;

0 commit comments

Comments
 (0)