diff options
| author | bors <bors@rust-lang.org> | 2016-07-01 18:43:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-01 18:43:28 -0700 |
| commit | 32a6373322d381c5778daea39a4f3b7ff94d9ee0 (patch) | |
| tree | c9dc0b5377eef02cc968d9f68be600ec68275322 /src/libstd/sys | |
| parent | 01411937ff6b2a2dfad03d060d636941b0034591 (diff) | |
| parent | 6aa01825204e8c3c29d104935de78df74a8e51d3 (diff) | |
| download | rust-32a6373322d381c5778daea39a4f3b7ff94d9ee0.tar.gz rust-32a6373322d381c5778daea39a4f3b7ff94d9ee0.zip | |
Auto merge of #34067 - tbu-:pr_lookup_host_ignore_other_addresses, r=alexcrichton
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/sys')
| -rw-r--r-- | src/libstd/sys/common/net.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 54b9b466c42..274e495d70e 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -119,14 +119,22 @@ pub struct LookupHost { } impl Iterator for LookupHost { - type Item = io::Result<SocketAddr>; - fn next(&mut self) -> Option<io::Result<SocketAddr>> { - 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); - self.cur = (*self.cur).ai_next as *mut c::addrinfo; - Some(ret) + type Item = SocketAddr; + fn next(&mut self) -> Option<SocketAddr> { + loop { + unsafe { + let cur = match self.cur.as_ref() { + None => return None, + Some(c) => c, + }; + self.cur = cur.ai_next; + match sockaddr_to_addr(mem::transmute(cur.ai_addr), + cur.ai_addrlen as usize) + { + Ok(addr) => return Some(addr), + Err(_) => continue, + } + } } } } |
