Skip to main content

random_unallocated_port

Function random_unallocated_port 

Source
pub fn random_unallocated_port() -> u16
Expand description

Returns the “magic” port number that tells the operating system to choose a random unallocated port.

The OS chooses a different port each time it opens a connection or listener with this magic port number.

Bind the real listener using this port, then query its local address while keeping it open. Do not probe and release a temporary listener: another process can take the released port.