Skip to content

Commit

Permalink
add: ip verification in tcp connection
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscaOrtegaG committed Oct 16, 2024
1 parent 180b18e commit a05c68e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/client/tcp_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ impl ClientConnection for ClientTCPConnection {
Ok(stream_result) => stream_result?,
Err(_) => return Err(ClientError::Io(IoError::new(ErrorKind::TimedOut, format!("Error: timeout"))).into()),
};


//Verify that the connected IP matches the expected IP
let actual_ip = stream.peer_addr()?.ip();
let expected_ip = self.get_server_addr();
if actual_ip != expected_ip {
return Err(ClientError::Io(IoError::new(
ErrorKind::PermissionDenied,
format!("IP mismatch: expected {}, got {}", expected_ip, actual_ip),
)).into());
}

// Add len of message len
let msg_length: u16 = bytes.len() as u16;
let tcp_bytes_length: [u8; 2] = [(msg_length >> 8) as u8, msg_length as u8];
Expand Down

0 comments on commit a05c68e

Please sign in to comment.