Detect unspecified IP and use TCP conn IP instead

This commit is contained in:
Ignotus Peverell 2017-11-03 16:47:35 -04:00
parent ad07866275
commit 15705b3fa1
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211

View file

@ -172,14 +172,16 @@ impl Handshake {
fn extract_ip(advertised: &SocketAddr, conn: &TcpStream) -> SocketAddr {
match advertised {
&SocketAddr::V4(v4sock) => {
if v4sock.ip().is_loopback() {
let ip = v4sock.ip();
if ip.is_loopback() || ip.is_unspecified() {
if let Ok(addr) = conn.peer_addr() {
return SocketAddr::new(addr.ip(), advertised.port());
}
}
}
&SocketAddr::V6(v6sock) => {
if v6sock.ip().is_loopback() {
let ip = v6sock.ip();
if ip.is_loopback() || ip.is_unspecified() {
if let Ok(addr) = conn.peer_addr() {
return SocketAddr::new(addr.ip(), advertised.port());
}