Convert ipv4-mapped ipv6 when accepting peer (#3225)

This commit is contained in:
Quentin Le Sceller 2020-02-14 09:38:02 -05:00 committed by GitHub
parent b400a4b1cf
commit 053415ddf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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