diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-03-27 22:37:20 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-03-27 22:37:20 +0530 |
| commit | d77a9510f617dd68b0cb76beb31c43e98f25c300 (patch) | |
| tree | 92c69fa05dbcf4ec97a1a9a99d05addd0cc48c5d /src/libstd/net | |
| parent | 82b375b44d408e7ddd1e3b2c1e64b0bf0c4376d1 (diff) | |
| parent | c0dd239753ab22d059531472b3895669ce44a875 (diff) | |
| download | rust-d77a9510f617dd68b0cb76beb31c43e98f25c300.tar.gz rust-d77a9510f617dd68b0cb76beb31c43e98f25c300.zip | |
Rollup merge of #23419 - murarth:lookup-addr, r=alexcrichton
Closes #22608
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/addr.rs | 9 | ||||
| -rw-r--r-- | src/libstd/net/mod.rs | 10 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index dafca974bec..a08b33b342b 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -47,6 +47,15 @@ pub struct SocketAddrV4 { inner: libc::sockaddr_in } pub struct SocketAddrV6 { inner: libc::sockaddr_in6 } impl SocketAddr { + /// Creates a new socket address from the (ip, port) pair. + #[unstable(feature = "ip_addr", reason = "recent addition")] + pub fn new(ip: IpAddr, port: u16) -> SocketAddr { + match ip { + IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)), + IpAddr::V6(a) => SocketAddr::V6(SocketAddrV6::new(a, port, 0, 0)), + } + } + /// Gets the IP address associated with this socket address. #[unstable(feature = "ip_addr", reason = "recent addition")] pub fn ip(&self) -> IpAddr { diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index 7f51b1cba3f..68f3098d993 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -111,3 +111,13 @@ impl Iterator for LookupHost { pub fn lookup_host(host: &str) -> io::Result<LookupHost> { net_imp::lookup_host(host).map(LookupHost) } + +/// Resolve the given address to a hostname. +/// +/// This function may perform a DNS query to resolve `addr` and may also inspect +/// system configuration to resolve the specified address. If the address +/// cannot be resolved, it is returned in string format. +#[unstable(feature = "lookup_addr", reason = "recent addition")] +pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> { + net_imp::lookup_addr(addr) +} |
