From a7a7ea89df78be2b33711772e36e62c126393af4 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 3 Jan 2021 05:40:27 +0500 Subject: [PATCH] Add function "recv_response1" --- src/main.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2bc6316..aa6a0d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,20 +63,7 @@ fn iterate_ttl( set_timeout(socket, 2, 0); - let mut response: Option = 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 let Some(response) = recv_response1(socket, &request) { if response.type_ != 11 || response.code != 0 { continue } @@ -138,7 +125,21 @@ fn set_timeout(socket: libc::c_int, sec: i64, usec: i64) { ) }); } -fn recv_response(socket: libc::c_int) -> Option { +fn recv_response1(socket: libc::c_int, request: &Request) -> Option { + let time_limit = SystemTime::now() + Duration::new(2, 0); + + while SystemTime::now() < time_limit { + if let Some(tmp_response) = recv_response2(socket) { + if tmp_response.does_match_request(request) { + return Some(tmp_response) + } + } + } + + return None +} + +fn recv_response2(socket: libc::c_int) -> Option { let response_body_data: [u8; 1024] = [0; 1024]; let mut response_sockaddr_data = libc::sockaddr {