about summary refs log tree commit diff
path: root/src/libstd/net
diff options
context:
space:
mode:
authorMurarth <murarth@gmail.com>2015-03-16 13:04:31 -0700
committerMurarth <murarth@gmail.com>2015-03-26 17:13:14 -0700
commitc0dd239753ab22d059531472b3895669ce44a875 (patch)
treea2f712b9431f2f3091b141ea2a48f24d3bcfaeee /src/libstd/net
parent1501f33e76f6f9621aa08fb0cbbc5f85a5ac7f0f (diff)
downloadrust-c0dd239753ab22d059531472b3895669ce44a875.tar.gz
rust-c0dd239753ab22d059531472b3895669ce44a875.zip
Add `std::net::lookup_addr` for reverse DNS lookup
Closes #22608
Diffstat (limited to 'src/libstd/net')
-rw-r--r--src/libstd/net/addr.rs9
-rw-r--r--src/libstd/net/mod.rs10
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)
+}