diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2016-06-03 23:10:36 +0200 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2016-06-29 11:39:56 +0200 |
| commit | d6237cefcb9fae0286a920b182e9bbc928a57c8a (patch) | |
| tree | 829a95e9e6b3bddb2eb36fd6c5876566379a1d4e /src/libstd | |
| parent | 366de839ae9794411419c5b579c829e18adde613 (diff) | |
| download | rust-d6237cefcb9fae0286a920b182e9bbc928a57c8a.tar.gz rust-d6237cefcb9fae0286a920b182e9bbc928a57c8a.zip | |
Ignore unknown address types when looking up hosts
Previously, any function using a `ToSocketAddrs` input would fail if passed a hostname that resolves to an address type different from the ones recognized by Rust. This also changes the `LookupHost` iterator to only include the known address types, as a result, it doesn't have to return `Result`s any more, which are likely misinterpreted as failed name lookups.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/net/addr.rs | 7 | ||||
| -rw-r--r-- | src/libstd/net/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/common/net.rs | 14 |
3 files changed, 12 insertions, 13 deletions
diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index d510339f1c5..44a7823f82a 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -448,12 +448,7 @@ impl ToSocketAddrs for (Ipv6Addr, u16) { fn resolve_socket_addr(s: &str, p: u16) -> io::Result<vec::IntoIter<SocketAddr>> { let ips = lookup_host(s)?; - let v: Vec<_> = ips.map(|a| { - a.map(|mut a| { - a.set_port(p); - a - }) - }).collect()?; + let v: Vec<_> = ips.map(|mut a| { a.set_port(p); a }).collect(); Ok(v.into_iter()) } diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index 45070460282..95df7f7eaeb 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -98,8 +98,8 @@ pub struct LookupHost(net_imp::LookupHost); addresses", issue = "27705")] impl Iterator for LookupHost { - type Item = io::Result<SocketAddr>; - fn next(&mut self) -> Option<io::Result<SocketAddr>> { self.0.next() } + type Item = SocketAddr; + fn next(&mut self) -> Option<SocketAddr> { self.0.next() } } /// Resolve the host specified by `host` as a number of `SocketAddr` instances. diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 54b9b466c42..3e2a0a8f39a 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -119,14 +119,18 @@ pub struct LookupHost { } impl Iterator for LookupHost { - type Item = io::Result<SocketAddr>; - fn next(&mut self) -> Option<io::Result<SocketAddr>> { + type Item = SocketAddr; + fn next(&mut self) -> Option<SocketAddr> { + let result; unsafe { if self.cur.is_null() { return None } - let ret = sockaddr_to_addr(mem::transmute((*self.cur).ai_addr), - (*self.cur).ai_addrlen as usize); + result = sockaddr_to_addr(mem::transmute((*self.cur).ai_addr), + (*self.cur).ai_addrlen as usize).ok(); self.cur = (*self.cur).ai_next as *mut c::addrinfo; - Some(ret) + } + match result { + Some(r) => Some(r), + None => self.next(), } } } |
