ReactOS  0.4.14-dev-55-g2da92ac
buffer.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _NETWORK_HEADER
 
struct  _NDIS_BUFFER_POOL
 
struct  _NDISI_PACKET_POOL
 

Typedefs

typedef struct _NETWORK_HEADER NETWORK_HEADER
 
typedef struct _NETWORK_HEADERPNETWORK_HEADER
 
typedef struct _NDIS_BUFFER_POOL NDIS_BUFFER_POOL
 
typedef struct _NDIS_BUFFER_POOLPNDIS_BUFFER_POOL
 
typedef struct _NDISI_PACKET_POOL NDISI_PACKET_POOL
 
typedef struct _NDISI_PACKET_POOLPNDISI_PACKET_POOL
 

Functions

UINT CopyBufferToBufferChain (PNDIS_BUFFER DstBuffer, UINT DstOffset, PUCHAR SrcData, UINT Length)
 
UINT CopyBufferChainToBuffer (PUCHAR DstData, PNDIS_BUFFER SrcBuffer, UINT SrcOffset, UINT Length)
 
UINT CopyPacketToBuffer (PUCHAR DstData, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
 
UINT CopyPacketToBufferChain (PNDIS_BUFFER DstBuffer, UINT DstOffset, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
 

Typedef Documentation

◆ NDIS_BUFFER_POOL

◆ NDISI_PACKET_POOL

◆ NETWORK_HEADER

◆ PNDIS_BUFFER_POOL

◆ PNDISI_PACKET_POOL

◆ PNETWORK_HEADER

Function Documentation

◆ CopyBufferChainToBuffer()

UINT CopyBufferChainToBuffer ( PUCHAR  DstData,
PNDIS_BUFFER  SrcBuffer,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 111 of file buffer.c.

129 {
130  UINT BytesCopied, BytesToCopy, SrcSize;
131  PUCHAR SrcData;
132 
133  NDIS_DbgPrint(MAX_TRACE, ("DstData 0x%X SrcBuffer 0x%X SrcOffset 0x%X Length %d\n",DstData,SrcBuffer, SrcOffset, Length));
134 
135  /* Skip SrcOffset bytes in the source buffer chain */
136  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
137  return 0;
138 
139  /* Start copying the data */
140  BytesCopied = 0;
141  for (;;) {
142  BytesToCopy = MIN(SrcSize, Length);
143 
144  NDIS_DbgPrint(MAX_TRACE, ("Copying (%d) bytes from 0x%X to 0x%X\n", BytesToCopy, SrcData, DstData));
145 
146  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
148  DstData = (PUCHAR)((ULONG_PTR) DstData + BytesToCopy);
149 
150  Length -= BytesToCopy;
151  if (Length == 0)
152  break;
153 
154  SrcSize -= BytesToCopy;
155  if (SrcSize == 0) {
156  /* No more bytes in source buffer. Proceed to
157  the next buffer in the source buffer chain */
158  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
159  if (!SrcBuffer)
160  break;
161 
162  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
163  }
164  }
165 
166  return BytesCopied;
167 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
T MIN(T a, T b)
Definition: polytest.cpp:79
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953

Referenced by CopyPacketToBuffer(), and MiniIndicateReceivePacket().

◆ CopyBufferToBufferChain()

UINT CopyBufferToBufferChain ( PNDIS_BUFFER  DstBuffer,
UINT  DstOffset,
PUCHAR  SrcData,
UINT  Length 
)

Definition at line 54 of file buffer.c.

72 {
73  UINT BytesCopied, BytesToCopy, DstSize;
74  PUCHAR DstData;
75 
76  NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X) DstOffset (0x%X) SrcData (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcData, Length));
77 
78  /* Skip DstOffset bytes in the destination buffer chain */
79  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == 0xFFFFFFFF)
80  return 0;
81 
82  /* Start copying the data */
83  BytesCopied = 0;
84  for (;;) {
85  BytesToCopy = MIN(DstSize, Length);
86 
87  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
89  SrcData = (PUCHAR) ((ULONG_PTR) SrcData + BytesToCopy);
90 
92  if (Length == 0)
93  break;
94 
95  DstSize -= BytesToCopy;
96  if (DstSize == 0) {
97  /* No more bytes in destination buffer. Proceed to
98  the next buffer in the destination buffer chain */
99  NdisGetNextBuffer(DstBuffer, &DstBuffer);
100  if (!DstBuffer)
101  break;
102 
103  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
104  }
105  }
106 
107  return BytesCopied;
108 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
T MIN(T a, T b)
Definition: polytest.cpp:79
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953

Referenced by DispTdiQueryInformationExComplete(), InfoCopyOut(), and InfoTdiQueryListEntities().

◆ CopyPacketToBuffer()

UINT CopyPacketToBuffer ( PUCHAR  DstData,
PNDIS_PACKET  SrcPacket,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 170 of file buffer.c.

188 {
189  PNDIS_BUFFER FirstBuffer;
190  PVOID Address;
191  UINT FirstLength;
193 
194  NDIS_DbgPrint(MAX_TRACE, ("DstData (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstData, SrcPacket, SrcOffset, Length));
195 
197  &FirstBuffer,
198  &Address,
199  &FirstLength,
200  &TotalLength);
201 
202  return CopyBufferChainToBuffer(DstData, FirstBuffer, SrcOffset, Length);
203 }
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_In_ ULONG TotalLength
Definition: usbdlib.h:145
static WCHAR Address[46]
Definition: ping.c:68
VOID EXPORT NdisGetFirstBufferFromPacket(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
Definition: buffer.c:871
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
UINT CopyBufferChainToBuffer(PUCHAR DstData, PNDIS_BUFFER SrcBuffer, UINT SrcOffset, UINT Length)
Definition: buffer.c:111

Referenced by ARPReceive(), GetPacketTypeFromNdisPacket(), IPReceive(), IPv4Receive(), ProIndicatePacket(), and ReassembleDatagram().

◆ CopyPacketToBufferChain()

UINT CopyPacketToBufferChain ( PNDIS_BUFFER  DstBuffer,
UINT  DstOffset,
PNDIS_PACKET  SrcPacket,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 206 of file buffer.c.

226 {
227  PNDIS_BUFFER SrcBuffer;
228  PUCHAR DstData, SrcData;
229  UINT DstSize, SrcSize;
230  UINT Count, Total;
231 
232  NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X) DstOffset (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcPacket, SrcOffset, Length));
233 
234  /* Skip DstOffset bytes in the destination buffer chain */
235  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
236  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == 0xFFFFFFFF)
237  return 0;
238  /* Skip SrcOffset bytes in the source packet */
239  NdisGetFirstBufferFromPacket(SrcPacket, &SrcBuffer, (PVOID*)&SrcData, &SrcSize, &Total);
240  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
241  return 0;
242  /* Copy the data */
243  for (Total = 0;;) {
244  /* Find out how many bytes we can copy at one time */
245  if (Length < SrcSize)
246  Count = Length;
247  else
248  Count = SrcSize;
249  if (DstSize < Count)
250  Count = DstSize;
251 
252  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, Count);
253 
254  Total += Count;
255  Length -= Count;
256  if (Length == 0)
257  break;
258 
259  DstSize -= Count;
260  if (DstSize == 0) {
261  /* No more bytes in destination buffer. Proceed to
262  the next buffer in the destination buffer chain */
263  NdisGetNextBuffer(DstBuffer, &DstBuffer);
264  if (!DstBuffer)
265  break;
266 
267  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
268  }
269 
270  SrcSize -= Count;
271  if (SrcSize == 0) {
272  /* No more bytes in source buffer. Proceed to
273  the next buffer in the source buffer chain */
274  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
275  if (!SrcBuffer)
276  break;
277 
278  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
279  }
280  }
281 
282  return Total;
283 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
VOID EXPORT NdisGetFirstBufferFromPacket(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
Definition: buffer.c:871
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953