pub fn detect_address() -> Result<String, String>Expand description
This machine’s own IPv4 address on the route to the outside.
A connectionless UDP socket, not ifconfig parsing and not a call to
somebody’s what-is-my-ip service. connect on a UDP socket sends
nothing; it only makes the kernel pick the source address it would
use, which is exactly the question. The address it names is
192.0.2.1 — TEST-NET-1, reserved for documentation and routed
nowhere — so even a stray packet would reach no one.
Behind NAT this answers with the private address, which is the honest answer: this box genuinely does not know its public one, and guessing would produce a certificate request for a name that resolves somewhere else.
§Errors
Returns a description when no route to the outside can be found.