mirror of https://github.com/dswd/vpncloud.git
Prefer IPv4 over IPv6 when possible
This commit is contained in:
parent
6c61ca61a8
commit
7a4efa9257
|
@ -127,6 +127,11 @@ pub fn resolve<Addr: ToSocketAddrs+fmt::Display>(addr: Addr) -> Result<Vec<Socke
|
|||
let addrs = try!(addr.to_socket_addrs().map_err(|_| Error::Name(format!("{}", addr))));
|
||||
// Remove duplicates in addrs (why are there duplicates???)
|
||||
let mut addrs = addrs.collect::<Vec<_>>();
|
||||
// Try IPv4 first as it usually is faster
|
||||
addrs.sort_by_key(|addr| match *addr {
|
||||
SocketAddr::V4(_) => 4,
|
||||
SocketAddr::V6(_) => 6
|
||||
});
|
||||
addrs.dedup();
|
||||
Ok(addrs)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue