Tech Support > Microsoft Windows > Drivers > Getting all NDIS packet Data
Getting all NDIS packet Data
Posted by Farooque Khan on August 16th, 2003


Hi,

In my NDIS driver for Windows 9x/ME, I am doing
something like the following to extract all the data from
a given NDIS_PACKET. I am mainly interested in the
headers only, and not the payload.
Can anybody point any problems with this code? since every
now and then, the driver crashes and I doubt this function.
Can this be modifying the packet in any way? Do I need to
make a copy of the packet? Do I need to lock any buffers?


Thanks in advance,
-Farooque

============= CODE ================

#define MAX_BUFFER_SIZE 8192
UCHAR GlobalBuffer[MAX_BUFFER_SIZE];

UINT GetData( IN PNDIS_PACKET Packet )
{
UINT Offset = 0;
PVOID VirtualAddress = 0;
PNDIS_BUFFER FirstBuffer, NextBuffer;
UINT TotalLength = 0;
PUCHAR Buffer = GlobalBuffer; // Some global Variable -- long enough to
hold an etheret packet...

NdisQueryPacket(Packet, NULL, NULL, &FirstBuffer, &TotalLength);
Buffer = NULL;

if (0 == TotalLength)
{
return 0;
}

while( FirstBuffer != NULL)
{
ULONG Length = 0 ;
NdisQueryBuffer(FirstBuffer, &VirtualAddress, &Length );

if( Length )
{
if ( (Offset+ Length) > MAX_BUFFER_SIZE )
{
DbgPrint("\nError:The buffer length exceeded.");
return 0; //file://should be success or resources
}
dprintf("Moving memory\n");
NdisMoveMemory((PVOID)((PUCHAR)Buffer+Offset), VirtualAddress, Length);
}

NdisGetNextBuffer(FirstBuffer, &NextBuffer);
FirstBuffer = NextBuffer;
Offset += Length;
}

return TotalLength;
// return NDIS_STATUS_SUCCESS;
}





Posted by Alireza Dabagh [MS] on August 16th, 2003


You seem to be initializing the variable Buffer correctly and then setting
it to NULL right away?
Or I missed something?


NdisQueryPacket(Packet, NULL, NULL, &FirstBuffer, &TotalLength);
-ali


--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Farooque Khan" <farooquekNOSPAM@concretioindiaNOSPAM.com> wrote in message
news:%23ZPFd78YDHA.3436@tk2msftngp13.phx.gbl...


Posted by Stephan Wolf on August 16th, 2003


Bingo. Shame on me I didn't realize that...

Stephan
---
On Sat, 16 Aug 2003 12:47:58 -0700, "Alireza Dabagh [MS]"
<alid@online.microsoft.com> wrote:

Posted by Alireza Dabagh [MS] on August 17th, 2003


The first thing to check is to see if this function manages to copy
anything -more- than mac header or only 14 bytes.
The second thing to check is to make sure the EthType (a.k.a. ProtocolType,
the two bytes after Destination and Source mac addresses in the MAC header)
is a valid IP or ARP EthType before trying to parse the packets.

By the way, I am assuming you either define BINARY_COMPATIBLE = 1 or you
leave it undefined. Correct?

This function also assumes that there can only be one send thread going at
any given time. For NT this is definitely a wrong assumption. For Win9x, I
am not sure. It's probably a wrong assumption there as well.

-ali

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Farooque Khan" <farooquekNOSPAM@concretioindiaNOSPAM.com> wrote in message
news:u8vrW6JZDHA.2032@TK2MSFTNGP10.phx.gbl...


Posted by Thomas F. Divine on August 17th, 2003


If you don't have a clear understanding of what a NDIS_PACKET looks like,
take a look this article on ndis.com:

http://www.ndis.com/papers/ndispacket/ndispacket1.htm

Good luck,

Thomas F. Divine


"Farooque Khan" <farooquekNOSPAM@concretioindiaNOSPAM.com> wrote in message
news:u8vrW6JZDHA.2032@TK2MSFTNGP10.phx.gbl...


Posted by Farooque Khan on August 19th, 2003


Thanks all for the replies,

-Farooque

"Farooque Khan" <farooquekNOSPAM@concretioindiaNOSPAM.com> wrote in message
news:u8vrW6JZDHA.2032@TK2MSFTNGP10.phx.gbl...



Similar Posts