Attempt to read ipv4-mapped ipv6 to ipv4 if possible (#3221)

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

View file

@ -143,16 +143,18 @@ impl Readable for PeerAddr {
))))
} else {
let ip = try_iter_map_vec!(0..8, |_| reader.read_u16());
let ipv6 = Ipv6Addr::new(ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7]);
let port = reader.read_u16()?;
if let Some(ipv4) = ipv6.to_ipv4() {
Ok(PeerAddr(SocketAddr::V4(SocketAddrV4::new(ipv4, port))))
} else {
Ok(PeerAddr(SocketAddr::V6(SocketAddrV6::new(
Ipv6Addr::new(ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7]),
port,
0,
0,
ipv6, port, 0, 0,
))))
}
}
}
}
impl std::hash::Hash for PeerAddr {
/// If loopback address then we care about ip and port.