From e6c8b8f480712d346c9b92f06217b4c56c15610c Mon Sep 17 00:00:00 2001 From: Murarth Date: Sun, 28 Dec 2014 15:44:25 -0700 Subject: Added `get_address_name`, an interface to `getnameinfo` --- src/libstd/io/net/addrinfo.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/libstd/io') diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 69ba64d856e..e8fbb121181 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -10,8 +10,8 @@ //! Synchronous DNS Resolution //! -//! Contains the functionality to perform DNS resolution in a style related to -//! `getaddrinfo()` +//! Contains the functionality to perform DNS resolution or reverse lookup, +//! in a style related to `getaddrinfo()` and `getnameinfo()`, respectively. #![allow(missing_docs)] @@ -24,6 +24,7 @@ use io::{IoResult}; use io::net::ip::{SocketAddr, IpAddr}; use option::Option; use option::Option::{Some, None}; +use string::String; use sys; use vec::Vec; @@ -83,6 +84,12 @@ pub fn get_host_addresses(host: &str) -> IoResult> { lookup(Some(host), None, None).map(|a| a.into_iter().map(|i| i.address.ip).collect()) } +/// Reverse name resolution. Given an address, returns the corresponding +/// hostname. +pub fn get_address_name(addr: IpAddr) -> IoResult { + sys::addrinfo::get_address_name(addr) +} + /// Full-fledged resolution. This function will perform a synchronous call to /// getaddrinfo, controlled by the parameters /// -- cgit 1.4.1-3-g733a5