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/sys | |
| 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/sys')
| -rw-r--r-- | src/libstd/sys/common/net.rs | 14 |
1 files changed, 9 insertions, 5 deletions
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(), } } } |
