Skip to content

Commit

Permalink
ensure test port cannot be selected as ephemeral port
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Aug 3, 2023
1 parent a43c05a commit 7d63674
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tokio/tests/io_async_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,15 @@ async fn await_error_readiness_invalid_address() {
// Spawn a separate thread for sending messages
tokio::spawn(async move {
// Set the destination address. This address is invalid in this context. the OS will notice
// that nobody is listening on port 1234. Normally this is ignored (UDP is "fire and forget"),
// that nobody is listening on port this port. Normally this is ignored (UDP is "fire and forget"),
// but because IP_RECVERR is enabled, the error will actually be reported to the sending socket
let mut dest_addr =
unsafe { std::mem::MaybeUninit::<libc::sockaddr_in>::zeroed().assume_init() };
dest_addr.sin_family = libc::AF_INET as _;
dest_addr.sin_port = 1234u16.to_be(); // Destination port
// based on https://en.wikipedia.org/wiki/Ephemeral_port, we should pick a port number
// below 1024 to guarantee that other tests don't select this port by accident when they
// use port 0 to select an ephemeral port.
dest_addr.sin_port = 512u16.to_be(); // Destination port

// Prepare the message data
let message = "Hello, Socket!";
Expand Down

0 comments on commit 7d63674

Please sign in to comment.