Skip to content

Commit bd01d97

Browse files
committed
Use pack consistently.
Formatting.
1 parent 07e142c commit bd01d97

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

src/Renci.SshNet/Abstractions/SocketAbstraction.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static int ReadPartial(Socket socket, byte[] buffer, int offset, int size
180180
receiveCompleted.Dispose();
181181
}
182182
#else
183-
#error Receiving data from a Socket is not implemented.
183+
#error Receiving data from a Socket is not implemented.
184184
#endif
185185
}
186186

@@ -242,7 +242,7 @@ public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int
242242
if (readToken.Exception != null)
243243
throw readToken.Exception;
244244
#else
245-
#error Receiving data from a Socket is not implemented.
245+
#error Receiving data from a Socket is not implemented.
246246
#endif
247247
}
248248

@@ -407,11 +407,10 @@ public static void Send(Socket socket, byte[] data, int offset, int size)
407407
{
408408
try
409409
{
410-
var bytesSent = socket.Send(data, offset + totalBytesSent, totalBytesToSend - totalBytesSent,
411-
SocketFlags.None);
410+
var bytesSent = socket.Send(data, offset + totalBytesSent, totalBytesToSend - totalBytesSent, SocketFlags.None);
412411
if (bytesSent == 0)
413412
throw new SshConnectionException("An established connection was aborted by the server.",
414-
DisconnectReason.ConnectionLost);
413+
DisconnectReason.ConnectionLost);
415414

416415
totalBytesSent += bytesSent;
417416
}
@@ -430,10 +429,10 @@ public static void Send(Socket socket, byte[] data, int offset, int size)
430429
var sendCompleted = new ManualResetEvent(false);
431430
var sendReceiveToken = new BlockingSendReceiveToken(socket, data, offset, size, sendCompleted);
432431
var socketAsyncSendArgs = new SocketAsyncEventArgs
433-
{
434-
RemoteEndPoint = socket.RemoteEndPoint,
435-
UserToken = sendReceiveToken
436-
};
432+
{
433+
RemoteEndPoint = socket.RemoteEndPoint,
434+
UserToken = sendReceiveToken
435+
};
437436
socketAsyncSendArgs.SetBuffer(data, offset, size);
438437
socketAsyncSendArgs.Completed += SendCompleted;
439438

@@ -450,7 +449,7 @@ public static void Send(Socket socket, byte[] data, int offset, int size)
450449

451450
if (sendReceiveToken.TotalBytesTransferred == 0)
452451
throw new SshConnectionException("An established connection was aborted by the server.",
453-
DisconnectReason.ConnectionLost);
452+
DisconnectReason.ConnectionLost);
454453
}
455454
finally
456455
{
@@ -460,7 +459,7 @@ public static void Send(Socket socket, byte[] data, int offset, int size)
460459
sendCompleted.Dispose();
461460
}
462461
#else
463-
#error Sending data to a Socket is not implemented.
462+
#error Sending data to a Socket is not implemented.
464463
#endif
465464
}
466465

src/Renci.SshNet/ForwardedPortDynamic.NET.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private bool HandleSocks4(Socket socket, IChannelDirectTcpip channel, TimeSpan t
328328
return false;
329329
}
330330

331-
var port = (uint)(portBuffer[0] * 256 + portBuffer[1]);
331+
var port = Pack.BigEndianToUInt16(portBuffer);
332332

333333
var ipBuffer = new byte[4];
334334
if (SocketAbstraction.Read(socket, ipBuffer, 0, ipBuffer.Length, timeout) == 0)
@@ -387,12 +387,12 @@ private bool HandleSocks5(Socket socket, IChannelDirectTcpip channel, TimeSpan t
387387
{
388388
// no user authentication is one of the authentication methods supported
389389
// by the SOCKS client
390-
SocketAbstraction.Send(socket, new byte[] { 0x05, 0x00 }, 0, 2);
390+
SocketAbstraction.Send(socket, new byte[] {0x05, 0x00}, 0, 2);
391391
}
392392
else
393393
{
394394
// the SOCKS client requires authentication, which we currently do not support
395-
SocketAbstraction.Send(socket, new byte[] { 0x05, 0xFF }, 0, 2);
395+
SocketAbstraction.Send(socket, new byte[] {0x05, 0xFF}, 0, 2);
396396

397397
// we continue business as usual but expect the client to close the connection
398398
// 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
515515

516516
private static byte[] CreateSocks5Reply(bool channelOpen)
517517
{
518-
var socksReply = new byte[
519-
// SOCKS version
520-
1 +
521-
// Reply field
522-
1 +
523-
// Reserved; fixed: 0x00
524-
1 +
525-
// Address type; fixed: 0x01
526-
1 +
527-
// IPv4 server bound address; fixed: {0x00, 0x00, 0x00, 0x00}
528-
4 +
529-
// server bound port; fixed: {0x00, 0x00}
530-
2];
518+
var socksReply = new byte
519+
[
520+
// SOCKS version
521+
1 +
522+
// Reply field
523+
1 +
524+
// Reserved; fixed: 0x00
525+
1 +
526+
// Address type; fixed: 0x01
527+
1 +
528+
// IPv4 server bound address; fixed: {0x00, 0x00, 0x00, 0x00}
529+
4 +
530+
// server bound port; fixed: {0x00, 0x00}
531+
2
532+
];
531533

532534
socksReply[0] = 0x05;
533535

0 commit comments

Comments
 (0)