Browse Source

Apply 13061 patch

olegkap_cp 13 years ago
parent
commit
702af15a59

+ 2 - 1
Renci.SshClient/Renci.SshNet/ForwardedPortDynamic.NET.cs

@@ -24,7 +24,8 @@ namespace Renci.SshNet
             var ip = IPAddress.Any;
             if (!string.IsNullOrEmpty(this.BoundHost))
             {
-                ip = Dns.GetHostAddresses(this.BoundHost)[0];
+                if (IPAddress.TryParse(this.BoundHost, out ip) == false)
+                    ip = Dns.GetHostAddresses(this.BoundHost)[0];
             }
 
             var ep = new IPEndPoint(ip, (int)this.BoundPort);

+ 6 - 1
Renci.SshClient/Renci.SshNet/ForwardedPortLocal.NET.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Linq;
 using System.Net.Sockets;
 using System.Net;
 using System.Threading;
@@ -20,7 +21,11 @@ namespace Renci.SshNet
             if (this.IsStarted)
                 return;
 
-            var ep = new IPEndPoint(Dns.GetHostAddresses(this.BoundHost)[0], (int)this.BoundPort);
+            IPAddress addr;
+            if (!IPAddress.TryParse(this.BoundHost, out addr))
+                addr = Dns.GetHostAddresses(this.BoundHost).First();
+
+            var ep = new IPEndPoint(addr, (int)this.BoundPort); 
 
             this._listener = new TcpListener(ep);
             this._listener.Start();

+ 5 - 1
Renci.SshClient/Renci.SshNet/Session.NET.cs

@@ -24,7 +24,11 @@ namespace Renci.SshNet
 
         partial void SocketConnect(string host, int port)
         {
-            var ep = new IPEndPoint(Dns.GetHostAddresses(host)[0], port);
+            IPAddress addr;
+            if (!IPAddress.TryParse(this.ConnectionInfo.Host, out addr))
+                addr = Dns.GetHostAddresses(host).First();
+
+            var ep = new IPEndPoint(addr, port); 
             this._socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
 
             var socketBufferSize = 2 * MAXIMUM_PACKET_SIZE;

+ 4 - 2
Renci.SshClient/Renci.SshNet/Session.cs

@@ -1627,7 +1627,8 @@ namespace Renci.SshNet
                 throw new ProxyException("SOCKS4: Silverlight supports only IP addresses.");
             }
 #else
-            ipAddress = Dns.GetHostAddresses(this.ConnectionInfo.Host).First();
+            if (!IPAddress.TryParse(this.ConnectionInfo.Host, out ipAddress))
+                ipAddress = Dns.GetHostAddresses(this.ConnectionInfo.Host).First();
 #endif
             this.SocketWrite(ipAddress.GetAddressBytes());
 
@@ -1750,7 +1751,8 @@ namespace Renci.SshNet
                 throw new ProxyException("SOCKS4: Silverlight supports only IP addresses.");
             }
 #else
-            ip = Dns.GetHostAddresses(this.ConnectionInfo.Host).First();
+            if (!IPAddress.TryParse(this.ConnectionInfo.Host, out ip))
+                ip = Dns.GetHostAddresses(this.ConnectionInfo.Host).First();
 #endif
 
             //  Send address type and address