summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorTom Lee <github@tomlee.co>2014-05-10 21:30:36 -0700
committerTom Lee <github@tomlee.co>2014-05-12 21:41:48 -0700
commit611c2ae4f1411a36e3010a3a4f9145115a3a0e88 (patch)
tree305cc9a91a14ea77a4f6e91bf98187046ed9c317 /src/libstd
parenta57889a58012a53146de7ba54e234a025a9b30c4 (diff)
downloadrust-611c2ae4f1411a36e3010a3a4f9145115a3a0e88.tar.gz
rust-611c2ae4f1411a36e3010a3a4f9145115a3a0e88.zip
Try to parse TcpStream::connect 'host' parameter as an IP.
Fall back to get_host_addresses to try a DNS lookup if we can't
parse it as an IP address.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/net/tcp.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs
index 454d9af5eeb..42db3939e7d 100644
--- a/src/libstd/io/net/tcp.rs
+++ b/src/libstd/io/net/tcp.rs
@@ -63,7 +63,10 @@ impl TcpStream {
     /// `host` can be a hostname or IP address string. If no error is
     /// encountered, then `Ok(stream)` is returned.
     pub fn connect(host: &str, port: u16) -> IoResult<TcpStream> {
-        let addresses = try!(get_host_addresses(host));
+        let addresses = match FromStr::from_str(host) {
+            Some(addr) => vec!(addr),
+            None => try!(get_host_addresses(host))
+        };
         let mut err = IoError{
             kind: ConnectionFailed,
             desc: "no addresses found for hostname",