diff --git a/p2p/src/serv.rs b/p2p/src/serv.rs index 9cbfaa313..8590f8a10 100644 --- a/p2p/src/serv.rs +++ b/p2p/src/serv.rs @@ -14,7 +14,7 @@ use std::fs::File; use std::io::{self, Read}; -use std::net::{Shutdown, SocketAddr, TcpListener, TcpStream}; +use std::net::{IpAddr, Shutdown, SocketAddr, SocketAddrV4, TcpListener, TcpStream}; use std::path::PathBuf; use std::sync::Arc; use std::thread; @@ -92,7 +92,20 @@ impl Server { // we do not want. stream.set_nonblocking(false)?; - let peer_addr = PeerAddr(peer_addr); + let mut peer_addr = PeerAddr(peer_addr); + + // attempt to see if it an ipv4-mapped ipv6 + // if yes convert to ipv4 + if peer_addr.0.is_ipv6() { + if let IpAddr::V6(ipv6) = peer_addr.0.ip() { + if let Some(ipv4) = ipv6.to_ipv4() { + peer_addr = PeerAddr(SocketAddr::V4(SocketAddrV4::new( + ipv4, + peer_addr.0.port(), + ))) + } + } + } if self.check_undesirable(&stream) { // Shutdown the incoming TCP connection if it is not desired