1
0
Fork 0

Add function "iterate_ttl"

This commit is contained in:
Alex Kotov 2021-01-03 05:36:06 +05:00
parent e6fa791fd0
commit 311d556a25
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -32,8 +32,30 @@ fn main() {
let mut current_ttl = options.first_ttl; let mut current_ttl = options.first_ttl;
while !reached_host && current_ttl <= options.max_ttl { while !reached_host && current_ttl <= options.max_ttl {
let mut current_address: Option<IpAddr> = None; let current_address = iterate_ttl(
&options,
&host,
socket,
current_ttl,
);
if let Some(ip_addr) = current_address {
println!("{} {}", current_ttl, ip_addr);
}
else {
println!("{} ***", current_ttl);
}
current_ttl += 1;
}
}
fn iterate_ttl(
options: &Options,
host: &IpAddr,
socket: libc::c_int,
current_ttl: u8,
) -> Option<IpAddr> {
for sequence in 0..options.nqueries { for sequence in 0..options.nqueries {
let request = Request::new(0, sequence); let request = Request::new(0, sequence);
@ -59,19 +81,11 @@ fn main() {
continue continue
} }
current_address = Some(response.source); return Some(response.source)
} }
} }
if let Some(ip_addr) = current_address { return None
println!("{} {}", current_ttl, ip_addr);
}
else {
println!("{} ***", current_ttl);
}
current_ttl += 1;
}
} }
fn send_request( fn send_request(