mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-17 20:43: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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using SMBLibrary.NetBios;
|
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary.Server
|
namespace SMBLibrary.NetBios
|
||||||
{
|
{
|
||||||
public class SMBConnectionReceiveBuffer
|
public class NBTConnectionReceiveBuffer
|
||||||
{
|
{
|
||||||
private byte[] m_buffer;
|
private byte[] m_buffer;
|
||||||
private int m_readOffset = 0;
|
private int m_readOffset = 0;
|
||||||
private int m_bytesInBuffer = 0;
|
private int m_bytesInBuffer = 0;
|
||||||
private int? m_packetLength;
|
private int? m_packetLength;
|
||||||
|
|
||||||
/// <param name="bufferLength">Must be large enough to hold the largest possible packet</param>
|
public NBTConnectionReceiveBuffer() : this(SessionPacket.MaxSessionPacketLength)
|
||||||
public SMBConnectionReceiveBuffer(int bufferLength)
|
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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];
|
m_buffer = new byte[bufferLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +42,6 @@ namespace SMBLibrary.Server
|
||||||
{
|
{
|
||||||
if (!m_packetLength.HasValue)
|
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);
|
byte flags = ByteReader.ReadByte(m_buffer, m_readOffset + 1);
|
||||||
int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(m_buffer, m_readOffset + 2);
|
int trailerLength = (flags & 0x01) << 16 | BigEndianConverter.ToUInt16(m_buffer, m_readOffset + 2);
|
||||||
m_packetLength = 4 + trailerLength;
|
m_packetLength = 4 + trailerLength;
|
|
@ -16,6 +16,8 @@ namespace SMBLibrary.NetBios
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class SessionPacket
|
public abstract class SessionPacket
|
||||||
{
|
{
|
||||||
|
public const int MaxSessionPacketLength = 131075;
|
||||||
|
|
||||||
public SessionPacketTypeName Type;
|
public SessionPacketTypeName Type;
|
||||||
public byte Flags;
|
public byte Flags;
|
||||||
public int Length; // 2 bytes + length extension bit
|
public int Length; // 2 bytes + length extension bit
|
||||||
|
|
|
@ -69,6 +69,7 @@
|
||||||
<Compile Include="NetBios\NameServicePackets\Structures\NodeStatistics.cs" />
|
<Compile Include="NetBios\NameServicePackets\Structures\NodeStatistics.cs" />
|
||||||
<Compile Include="NetBios\NameServicePackets\Structures\QuestionSection.cs" />
|
<Compile Include="NetBios\NameServicePackets\Structures\QuestionSection.cs" />
|
||||||
<Compile Include="NetBios\NameServicePackets\Structures\ResourceRecord.cs" />
|
<Compile Include="NetBios\NameServicePackets\Structures\ResourceRecord.cs" />
|
||||||
|
<Compile Include="NetBios\NBTConnectionReceiveBuffer.cs" />
|
||||||
<Compile Include="NetBios\NetBiosUtils.cs" />
|
<Compile Include="NetBios\NetBiosUtils.cs" />
|
||||||
<Compile Include="NetBios\SessionPackets\Enums\SessionPacketTypeName.cs" />
|
<Compile Include="NetBios\SessionPackets\Enums\SessionPacketTypeName.cs" />
|
||||||
<Compile Include="NetBios\SessionPackets\NegativeSessionResponsePacket.cs" />
|
<Compile Include="NetBios\SessionPackets\NegativeSessionResponsePacket.cs" />
|
||||||
|
@ -129,7 +130,6 @@
|
||||||
<Compile Include="Server\Shares\ISMBShare.cs" />
|
<Compile Include="Server\Shares\ISMBShare.cs" />
|
||||||
<Compile Include="Server\Shares\NamedPipeShare.cs" />
|
<Compile Include="Server\Shares\NamedPipeShare.cs" />
|
||||||
<Compile Include="Server\Shares\ShareCollection.cs" />
|
<Compile Include="Server\Shares\ShareCollection.cs" />
|
||||||
<Compile Include="Server\SMBConnectionReceiveBuffer.cs" />
|
|
||||||
<Compile Include="Server\SMBServer.cs" />
|
<Compile Include="Server\SMBServer.cs" />
|
||||||
<Compile Include="Server\User.cs" />
|
<Compile Include="Server\User.cs" />
|
||||||
<Compile Include="Server\UserCollection.cs" />
|
<Compile Include="Server\UserCollection.cs" />
|
||||||
|
|
|
@ -8,6 +8,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using SMBLibrary.NetBios;
|
||||||
using Utilities;
|
using Utilities;
|
||||||
|
|
||||||
namespace SMBLibrary.Server
|
namespace SMBLibrary.Server
|
||||||
|
@ -15,8 +16,7 @@ namespace SMBLibrary.Server
|
||||||
public class SMB1ConnectionState
|
public class SMB1ConnectionState
|
||||||
{
|
{
|
||||||
public Socket ClientSocket = null;
|
public Socket ClientSocket = null;
|
||||||
public const int ReceiveBufferSize = 131075; // Largest NBT Session Packet
|
public NBTConnectionReceiveBuffer ReceiveBuffer = new NBTConnectionReceiveBuffer();
|
||||||
public SMBConnectionReceiveBuffer ReceiveBuffer = new SMBConnectionReceiveBuffer(ReceiveBufferSize);
|
|
||||||
|
|
||||||
public int MaxBufferSize;
|
public int MaxBufferSize;
|
||||||
public bool LargeRead;
|
public bool LargeRead;
|
||||||
|
|
|
@ -100,6 +100,8 @@ namespace SMBLibrary.Server
|
||||||
state.ClientSocket = clientSocket;
|
state.ClientSocket = clientSocket;
|
||||||
try
|
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);
|
clientSocket.BeginReceive(state.ReceiveBuffer.Buffer, state.ReceiveBuffer.WriteOffset, state.ReceiveBuffer.AvailableLength, 0, ReceiveCallback, state);
|
||||||
}
|
}
|
||||||
catch (ObjectDisposedException)
|
catch (ObjectDisposedException)
|
||||||
|
@ -144,7 +146,7 @@ namespace SMBLibrary.Server
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMBConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
NBTConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
||||||
receiveBuffer.SetNumberOfBytesReceived(numberOfBytesReceived);
|
receiveBuffer.SetNumberOfBytesReceived(numberOfBytesReceived);
|
||||||
ProcessConnectionBuffer(state);
|
ProcessConnectionBuffer(state);
|
||||||
|
|
||||||
|
@ -167,7 +169,7 @@ namespace SMBLibrary.Server
|
||||||
{
|
{
|
||||||
Socket clientSocket = state.ClientSocket;
|
Socket clientSocket = state.ClientSocket;
|
||||||
|
|
||||||
SMBConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
NBTConnectionReceiveBuffer receiveBuffer = state.ReceiveBuffer;
|
||||||
while (receiveBuffer.HasCompletePacket())
|
while (receiveBuffer.HasCompletePacket())
|
||||||
{
|
{
|
||||||
SessionPacket packet = null;
|
SessionPacket packet = null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue