From 78adac1241ada61da97280282446cf1dd42fe835 Mon Sep 17 00:00:00 2001 From: drieseng Date: Sun, 22 May 2016 10:30:12 +0200 Subject: [PATCH] Restore HandleSocks5 as before bug triaging. --- src/Renci.SshNet/ForwardedPortDynamic.NET.cs | 59 +++++++------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs index 9666a2a4..2957c7c2 100644 --- a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs +++ b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs @@ -565,58 +565,37 @@ namespace Renci.SshNet Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | After channel open | " + DateTime.Now.ToString("hh:mm:ss.fff") + " => " + stopWatch.ElapsedMilliseconds); #endif // DEBUG_GERT - var replyBuffer = new byte[10]; - replyBuffer[0] = 0x05; - -// SocketAbstraction.SendByte(socket, 0x05); + SocketAbstraction.SendByte(socket, 0x05); if (channel.IsOpen) { - replyBuffer[1] = 0x00; -// SocketAbstraction.SendByte(socket, 0x00); + SocketAbstraction.SendByte(socket, 0x00); } else { - replyBuffer[1] = 0x01; - //SocketAbstraction.SendByte(socket, 0x01); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel not open"); -#endif // DEBUG_GERT + SocketAbstraction.SendByte(socket, 0x01); } // reserved - replyBuffer[2] = 0x00; + SocketAbstraction.SendByte(socket, 0x00); - // reserved - //SocketAbstraction.SendByte(socket, 0x00); + if (ipAddress.AddressFamily == AddressFamily.InterNetwork) + { + SocketAbstraction.SendByte(socket, 0x01); + } + else if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) + { + SocketAbstraction.SendByte(socket, 0x04); + } + else + { + throw new NotSupportedException("Not supported address family."); + } - //if (ipAddress.AddressFamily == AddressFamily.InterNetwork) - //{ - // SocketAbstraction.SendByte(socket, 0x01); - //} - //else if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) - //{ - // SocketAbstraction.SendByte(socket, 0x04); - //} - //else - //{ - // throw new NotSupportedException("Not supported address family."); - //} - - // IPv4 - replyBuffer[3] = 0x01; - - SocketAbstraction.Send(socket, replyBuffer, 0, replyBuffer.Length); - - //var addressBytes = IPAddress.Any.GetAddressBytes(); - //SocketAbstraction.Send(socket, addressBytes, 0, addressBytes.Length); - //SocketAbstraction.Send(socket, new byte[] {0x00, 0x00}, 0, 2); - - //var addressBytes = ipAddress.GetAddressBytes(); - //SocketAbstraction.Send(socket, addressBytes, 0, addressBytes.Length); - //SocketAbstraction.Send(socket, portBuffer, 0, portBuffer.Length); + var addressBytes = ipAddress.GetAddressBytes(); + SocketAbstraction.Send(socket, addressBytes, 0, addressBytes.Length); + SocketAbstraction.Send(socket, portBuffer, 0, portBuffer.Length); return true; }