Skip to content

Commit

Permalink
add: ip verification in udp connection
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscaOrtegaG committed Oct 16, 2024
1 parent a05c68e commit a5459ff
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/client/udp_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ impl ClientConnection for ClientUDPConnection {
Err(_) => return Err(ClientError::Io(IoError::new(ErrorKind::TimedOut, format!("Error: timeout"))).into()),
};

match result {
let (_, src_addr) = match result {
Err(e) => return Err(IoError::new(ErrorKind::Other, format!("Error: could not read {}", e))).map_err(Into::into),
Ok(_) => (),
Ok((n, addr)) => (n, addr),
};

// Verify that the response comes from the expected IP
let expected_ip = self.get_server_addr();
let actual_ip = src_addr.ip();
if actual_ip != expected_ip {
return Err(ClientError::Io(IoError::new(
ErrorKind::PermissionDenied,
format!("IP mismatch: expected {}, got {}", expected_ip, actual_ip),
)).into());
}
let ip = self.get_server_addr();
let mut additionals = dns_query.get_additional();
let mut ar = ARdata::new();
Expand Down

0 comments on commit a5459ff

Please sign in to comment.