diff --git a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs index 13191d5a6..ef4bd956c 100644 --- a/src/Renci.SshNet/Abstractions/SocketAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/SocketAbstraction.cs @@ -180,7 +180,7 @@ public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size receiveCompleted.Dispose(); } #else -#error Receiving data from a Socket is not implemented. + #error Receiving data from a Socket is not implemented. #endif } @@ -242,7 +242,7 @@ public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int if (readToken.Exception != null) throw readToken.Exception; #else -#error Receiving data from a Socket is not implemented. + #error Receiving data from a Socket is not implemented. #endif } @@ -407,11 +407,10 @@ public static void Send(Socket socket, byte[] data, int offset, int size) { try { - var bytesSent = socket.Send(data, offset + totalBytesSent, totalBytesToSend - totalBytesSent, - SocketFlags.None); + var bytesSent = socket.Send(data, offset + totalBytesSent, totalBytesToSend - totalBytesSent, SocketFlags.None); if (bytesSent == 0) throw new SshConnectionException("An established connection was aborted by the server.", - DisconnectReason.ConnectionLost); + DisconnectReason.ConnectionLost); totalBytesSent += bytesSent; } @@ -430,10 +429,10 @@ public static void Send(Socket socket, byte[] data, int offset, int size) var sendCompleted = new ManualResetEvent(false); var sendReceiveToken = new BlockingSendReceiveToken(socket, data, offset, size, sendCompleted); var socketAsyncSendArgs = new SocketAsyncEventArgs - { - RemoteEndPoint = socket.RemoteEndPoint, - UserToken = sendReceiveToken - }; + { + RemoteEndPoint = socket.RemoteEndPoint, + UserToken = sendReceiveToken + }; socketAsyncSendArgs.SetBuffer(data, offset, size); socketAsyncSendArgs.Completed += SendCompleted; @@ -450,7 +449,7 @@ public static void Send(Socket socket, byte[] data, int offset, int size) if (sendReceiveToken.TotalBytesTransferred == 0) throw new SshConnectionException("An established connection was aborted by the server.", - DisconnectReason.ConnectionLost); + DisconnectReason.ConnectionLost); } finally { @@ -460,7 +459,7 @@ public static void Send(Socket socket, byte[] data, int offset, int size) sendCompleted.Dispose(); } #else -#error Sending data to a Socket is not implemented. + #error Sending data to a Socket is not implemented. #endif } diff --git a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs index 5790ecb44..b2c16cd23 100644 --- a/src/Renci.SshNet/ForwardedPortDynamic.NET.cs +++ b/src/Renci.SshNet/ForwardedPortDynamic.NET.cs @@ -328,7 +328,7 @@ private bool HandleSocks4(Socket socket, IChannelDirectTcpip channel, TimeSpan t return false; } - var port = (uint)(portBuffer[0] * 256 + portBuffer[1]); + var port = Pack.BigEndianToUInt16(portBuffer); var ipBuffer = new byte[4]; if (SocketAbstraction.Read(socket, ipBuffer, 0, ipBuffer.Length, timeout) == 0) @@ -387,12 +387,12 @@ private bool HandleSocks5(Socket socket, IChannelDirectTcpip channel, TimeSpan t { // no user authentication is one of the authentication methods supported // by the SOCKS client - SocketAbstraction.Send(socket, new byte[] { 0x05, 0x00 }, 0, 2); + SocketAbstraction.Send(socket, new byte[] {0x05, 0x00}, 0, 2); } else { // the SOCKS client requires authentication, which we currently do not support - SocketAbstraction.Send(socket, new byte[] { 0x05, 0xFF }, 0, 2); + SocketAbstraction.Send(socket, new byte[] {0x05, 0xFF}, 0, 2); // we continue business as usual but expect the client to close the connection // so one of the subsequent reads should return -1 signaling that the client @@ -515,19 +515,21 @@ private static string GetSocks5Host(int addressType, Socket socket, TimeSpan tim private static byte[] CreateSocks5Reply(bool channelOpen) { - var socksReply = new byte[ - // SOCKS version - 1 + - // Reply field - 1 + - // Reserved; fixed: 0x00 - 1 + - // Address type; fixed: 0x01 - 1 + - // IPv4 server bound address; fixed: {0x00, 0x00, 0x00, 0x00} - 4 + - // server bound port; fixed: {0x00, 0x00} - 2]; + var socksReply = new byte + [ + // SOCKS version + 1 + + // Reply field + 1 + + // Reserved; fixed: 0x00 + 1 + + // Address type; fixed: 0x01 + 1 + + // IPv4 server bound address; fixed: {0x00, 0x00, 0x00, 0x00} + 4 + + // server bound port; fixed: {0x00, 0x00} + 2 + ]; socksReply[0] = 0x05;