Skip to content

Commit

Permalink
Use pack consistently.
Browse files Browse the repository at this point in the history
Formatting.
  • Loading branch information
drieseng committed Jul 30, 2018
1 parent 07e142c commit bd01d97
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
21 changes: 10 additions & 11 deletions src/Renci.SshNet/Abstractions/SocketAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

Expand All @@ -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
{
Expand All @@ -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
}

Expand Down
34 changes: 18 additions & 16 deletions src/Renci.SshNet/ForwardedPortDynamic.NET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit bd01d97

Please sign in to comment.