Skip to content

Commit e64a977

Browse files
committed
intercept: add IPv6 loopback address to fall back to
1 parent 329da8c commit e64a977

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

bear/src/intercept/tcp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ impl CollectorOnTcp {
5656
/// The address of the collector can be obtained by the `address` method.
5757
pub fn new() -> Result<(Self, SocketAddr), std::io::Error> {
5858
let shutdown = Arc::new(AtomicBool::new(false));
59-
let listener = TcpListener::bind("127.0.0.1:0")?;
59+
// Try IPv4 loopback first, fall back to IPv6 loopback if IPv4 is unavailable.
60+
let listener = TcpListener::bind("127.0.0.1:0")
61+
.or_else(|_| TcpListener::bind("[::1]:0"))?;
6062
let address = listener.local_addr()?;
6163

6264
Ok((Self { shutdown, listener }, address))

0 commit comments

Comments
 (0)