mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-18 04:53:46 +02:00
Renamed SMBConnectionReceiveBuffer to NBTConnectionReceiveBuffer
This commit is contained in:
parent
bc167316a2
commit
3aa7825d1c
5 changed files with 21 additions and 13 deletions
|
@ -6,22 +6,28 @@
|
|||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SMBLibrary.NetBios;
|
||||
using Utilities;
|
||||
|
||||
namespace SMBLibrary.Server
|
||||
namespace SMBLibrary.NetBios
|
||||
{
|
||||
public class SMBConnectionReceiveBuffer
|
||||
public class NBTConnectionReceiveBuffer
|
||||
{
|
||||
private byte[] m_buffer;
|
||||
private int m_readOffset = 0;
|
||||
private int m_bytesInBuffer = 0;
|
||||
private int? m_packetLength;
|
||||
|
||||
/// <param name="bufferLength">Must be large enough to hold the largest possible packet</param>
|
||||
public SMBConnectionReceiveBuffer(int bufferLength)
|
||||
public NBTConnectionReceiveBuffer() : this(SessionPacket.MaxSessionPacketLength)
|
||||
{
|
||||
}
|
||||
|
||||
/// <param name="bufferLength">Must be large enough to hold the largest possible NBT packet</param>
|
||||
public NBTConnectionReceiveBuffer(int bufferLength)
|
||||
{
|
||||
if (bufferLength < SessionPacket.MaxSessionPacketLength)
|
||||
{
|
||||
throw new ArgumentException("bufferLength must be large enough to hold the largest possible NBT packet");
|
||||
}
|
||||
m_buffer = new byte[bufferLength];
|
||||
}
|
||||
|
||||
|
@ -36,8 +42,6 @@ namespace SMBLibrary.Server
|
|||
{
|
||||
if (!m_packetLength.HasValue)
|
||||
{
|
||||
// The packet is either Direct TCP transport packet (which is an NBT Session Message
|
||||
// Packet) or an NBT packet.
|
||||
byte flags = ByteReader.ReadByte(m_buffer, m_readOffset + 1);
|
||||
int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(m_buffer, m_readOffset + 2);
|
||||
m_packetLength = 4 + trailerLength;
|
|
@ -16,6 +16,8 @@ namespace SMBLibrary.NetBios
|
|||
/// </summary>
|
||||
public abstract class SessionPacket
|
||||
{
|
||||
public const int MaxSessionPacketLength = 131075;
|
||||
|
||||
public SessionPacketTypeName Type;
|
||||
public byte Flags;
|
||||
public int Length; // 2 bytes + length extension bit
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
<Compile Include="NetBios\NameServicePackets\Structures\NodeStatistics.cs" />
|
||||
<Compile Include="NetBios\NameServicePackets\Structures\QuestionSection.cs" />
|
||||
<Compile Include="NetBios\NameServicePackets\Structures\ResourceRecord.cs" />
|
||||
<Compile Include="NetBios\NBTConnectionReceiveBuffer.cs" />
|
||||
<Compile Include="NetBios\NetBiosUtils.cs" />
|
||||
<Compile Include="NetBios\SessionPackets\Enums\SessionPacketTypeName.cs" />
|
||||
<Compile Include="NetBios\SessionPackets\NegativeSessionResponsePacket.cs" />
|
||||
|
@ -129,7 +130,6 @@
|
|||
<Compile Include="Server\Shares\ISMBShare.cs" />
|
||||
<Compile Include="Server\Shares\NamedPipeShare.cs" />
|
||||
<Compile Include="Server\Shares\ShareCollection.cs" />
|
||||
<Compile Include="Server\SMBConnectionReceiveBuffer.cs" />
|
||||
<Compile Include="Server\SMBServer.cs" />
|
||||
<Compile Include="Server\User.cs" />
|
||||
<Compile Include="Server\UserCollection.cs" />
|
||||
|
|
|
@ -8,6 +8,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using SMBLibrary.NetBios;
|
||||
using Utilities;
|
||||
|
||||
namespace SMBLibrary.Server
|
||||
|
@ -15,8 +16,7 @@ namespace SMBLibrary.Server
|
|||
public class SMB1ConnectionState
|
||||
{
|
||||
public Socket ClientSocket = null;
|
||||
public const int ReceiveBufferSize = 131075; // Largest NBT Session Packet
|
||||
public SMBConnectionReceiveBuffer ReceiveBuffer = new SMBConnectionReceiveBuffer(ReceiveBufferSize);
|
||||
public NBTConnectionReceiveBuffer ReceiveBuffer = new NBTConnectionReceiveBuffer();
|
||||
|
||||
public int MaxBufferSize;
|
||||
public bool LargeRead;
|
||||
|
|
|
@ -100,6 +100,8 @@ namespace SMBLibrary.Server
|
|||
state.ClientSocket = clientSocket;
|
||||
try
|
||||
{
|
||||
// Direct TCP transport packet is actually an NBT Session Message Packet,
|
||||
// So in either case (NetBios over TCP or Direct TCP Transport) we will receive an NBT packet.
|
||||
clientSocket.BeginReceive(state.ReceiveBuffer.Buffer, state.ReceiveBuffer.WriteOffset, state.ReceiveBuffer.AvailableLength, 0, ReceiveCallback, state);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
|
@ -144,7 +146,7 @@ namespace SMBLibrary.Server
|
|||
return;
|
||||
}
|
||||
|
||||
SMBConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
||||
NBTConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
||||
receiveBuffer.SetNumberOfBytesReceived(numberOfBytesReceived);
|
||||
ProcessConnectionBuffer(state);
|
||||
|
||||
|
@ -167,7 +169,7 @@ namespace SMBLibrary.Server
|
|||
{
|
||||
Socket clientSocket = state.ClientSocket;
|
||||
|
||||
SMBConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
||||
NBTConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
||||
while (receiveBuffer.HasCompletePacket())
|
||||
{
|
||||
SessionPacket packet = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue