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,36 +32,12 @@ fn main() {
let mut current_ttl = options.first_ttl;
while !reached_host && current_ttl <= options.max_ttl {
let mut current_address: Option<IpAddr> = None;
for sequence in 0..options.nqueries {
let request = Request::new(0, sequence);
send_request(socket, current_ttl, &host, &request);
set_timeout(socket, 2, 0);
let mut response: Option<Response> = None;
let time_limit = SystemTime::now() + Duration::new(2, 0);
while SystemTime::now() < time_limit {
if let Some(tmp_response) = recv_response(socket) {
if tmp_response.does_match_request(&request) {
response = Some(tmp_response);
break
}
}
}
if let Some(response) = response {
if response.type_ != 11 || response.code != 0 {
continue
}
current_address = Some(response.source);
}
}
let current_address = iterate_ttl(
&options,
&host,
socket,
current_ttl,
);
if let Some(ip_addr) = current_address {
println!("{} {}", current_ttl, ip_addr);
@ -74,6 +50,44 @@ fn main() {
}
}
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);
send_request(socket, current_ttl, &host, &request);
set_timeout(socket, 2, 0);
let mut response: Option<Response> = None;
let time_limit = SystemTime::now() + Duration::new(2, 0);
while SystemTime::now() < time_limit {
if let Some(tmp_response) = recv_response(socket) {
if tmp_response.does_match_request(&request) {
response = Some(tmp_response);
break
}
}
}
if let Some(response) = response {
if response.type_ != 11 || response.code != 0 {
continue
}
return Some(response.source)
}
}
return None
}
fn send_request(
socket: libc::c_int,
current_ttl: u8,