Skip to content

Commit 7508725

Browse files
ivonnyssenclaude
andcommitted
Use TEST-NET-1 address for default-route detection in tests
Switch from 10.254.254.254 to 192.0.2.1 (RFC 5737) in the UDP socket trick used to infer the default-route IP. VPNs commonly push routes for RFC1918 prefixes (10/8, 172.16/12, 192.168/16), so a 10.0.0.0/8 target can resolve to the VPN tun interface instead of the true default route. TEST-NET ranges are reserved for documentation and are very rarely matched by a more-specific route. No effect in CI (no VPN) but reduces flakiness for developers running tests on machines with a corporate VPN. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3f91e5c commit 7508725

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/discovery.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,13 @@ mod tests {
158158

159159
/// Determine the default IPv4 address using the UDP socket trick:
160160
/// "connect" to a non-routable address and read back the source IP the OS chose.
161+
///
162+
/// Uses a TEST-NET-1 address (RFC 5737). VPNs commonly push routes for
163+
/// RFC1918 prefixes, which would make a `10.0.0.0/8` target resolve to
164+
/// the VPN interface instead of the true default route.
161165
fn get_default_ipv4() -> Option<Ipv4Addr> {
162166
let socket = std::net::UdpSocket::bind("0.0.0.0:0").ok()?;
163-
socket.connect("10.254.254.254:1").ok()?;
167+
socket.connect("192.0.2.1:1").ok()?;
164168
match socket.local_addr().ok()?.ip() {
165169
IpAddr::V4(ip) => Some(ip),
166170
IpAddr::V6(_) => None,

0 commit comments

Comments
 (0)