rust/src/libstd
Manish Goregaokar 5389ccc0c1 Rollup merge of #34700 - inejge:ai-hints, r=alexcrichton
Use hints with getaddrinfo() in std::net::lookup_host()

As noted in #24250, `std::net::lookup_host()` repeats each IPv[46] address in the result set. The number of repetitions is OS-dependent; e.g., Linux and FreeBSD give three copies, OpenBSD gives two. Filtering the duplicates can be done by the user if `lookup_host()` is used explicitly, but not with functions like `TcpStream::connect()`. What happens with the latter is that any unsuccessful connection attempt will be repeated as many times as there are duplicates of the address.

The program:

```rust
use std::net::TcpStream;

fn main() {
    let _stream = TcpStream::connect("localhost:4444").unwrap();
}
```

results in the following capture:

[capture-before.txt](https://github.com/rust-lang/rust/files/352004/capture-before.txt)

assuming that "localhost" resolves both to ::1 and 127.0.0.1, and that the listening program opens just an IPv4 socket (e.g., `nc -l 127.0.0.1 4444`.) The reason for this behavior is explained in [this comment](https://github.com/rust-lang/rust/issues/24250#issuecomment-92240152): `getaddrinfo()` is not constrained.

Various OSS projects (I checked out Postfix, OpenLDAP, Apache HTTPD and BIND) which use `getaddrinfo()` generally constrain the result set by using a non-NULL `hints` parameter and setting at least `ai_socktype` to `SOCK_STREAM`. `SOCK_DGRAM` would also work. Other parameters are unnecessary for pure name resolution.

The patch in this PR initializes a `hints` struct and passes it to `getaddrinfo()`, which eliminates the duplicates. The same test program as above with this change produces:

[capture-after.txt](https://github.com/rust-lang/rust/files/352042/capture-after.txt)

All `libstd` tests pass with this patch.
2016-07-08 14:47:00 +05:30
..
collections std: use siphash-1-3 for HashMap 2016-06-29 16:08:32 -07:00
ffi Document CStr::as_ptr dangers. 2016-06-19 15:14:51 +03:00
io Add doc examples for io::Error::from_raw_os_error. 2016-07-06 19:39:21 -04:00
net Update documentation to reflect ignoring of unknown addresses 2016-06-29 11:44:33 +02:00
num std: Stabilize APIs for the 1.11.0 release 2016-07-03 10:49:01 -07:00
os std: Fix up stabilization discrepancies 2016-06-23 14:08:11 -07:00
prelude
rand
sync std: sync: Implement recv_timeout() 2016-06-22 20:48:55 +02:00
sys Use hints with getaddrinfo() in std::net::lokup_host() 2016-07-07 12:03:31 +02:00
thread Rollup merge of #34406 - frewsxcv:sleep-ex, r=alexcrichton 2016-06-28 16:05:14 +02:00
time std: Clean out old unstable + deprecated APIs 2016-05-30 20:46:32 -07:00
ascii.rs std: Stabilize APIs for the 1.9 release 2016-04-11 08:57:53 -07:00
build.rs Fix issue where rustbuild expected msvc to have ar 2016-06-16 08:38:06 -04:00
Cargo.toml rustbuild: Add support for crate tests + doctests 2016-05-12 08:52:20 -07:00
env.rs Cleanup formatting and wording for std::env::temp_dir docs. 2016-05-12 00:05:25 -04:00
error.rs Implement Error trait for fmt::Error type 2016-05-25 10:52:10 +02:00
fs.rs Fix a docs typo 2016-06-15 13:06:48 +03:00
lib.rs std: use siphash-1-3 for HashMap 2016-06-29 16:08:32 -07:00
macros.rs Mark concat_idents! unstable 2016-06-21 23:30:15 +01:00
memchr.rs Fix a few typos in the code 2016-07-03 10:02:24 +02:00
panic.rs std: Clean out old unstable + deprecated APIs 2016-05-30 20:46:32 -07:00
panicking.rs Auto merge of #33699 - alexcrichton:stabilize-1.10, r=aturon 2016-05-25 20:36:09 -07:00
path.rs Fix std::path::Path::file_name() doc 2016-07-06 01:26:24 +02:00
primitive_docs.rs Use the correct types in float examples 2016-06-22 23:33:07 +01:00
process.rs doc: fix mis-named binding & remove not needed mut 2016-06-16 23:20:58 +02:00
rt.rs Auto merge of #33803 - WiSaGaN:feature/rename-main-thread, r=alexcrichton 2016-06-03 19:36:32 -07:00
rtdeps.rs