Add function "iterate_ttl"
This commit is contained in:
parent
e6fa791fd0
commit
311d556a25
1 changed files with 44 additions and 30 deletions
36
src/main.rs
36
src/main.rs
|
@ -32,8 +32,30 @@ fn main() {
|
|||
let mut current_ttl = options.first_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 {
|
||||
let request = Request::new(0, sequence);
|
||||
|
||||
|
@ -59,19 +81,11 @@ fn main() {
|
|||
continue
|
||||
}
|
||||
|
||||
current_address = Some(response.source);
|
||||
return Some(response.source)
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ip_addr) = current_address {
|
||||
println!("{} {}", current_ttl, ip_addr);
|
||||
}
|
||||
else {
|
||||
println!("{} ***", current_ttl);
|
||||
}
|
||||
|
||||
current_ttl += 1;
|
||||
}
|
||||
return None
|
||||
}
|
||||
|
||||
fn send_request(
|
||||
|
|
Reference in a new issue