Reading data out of an MDL in OnReceiveFrom event

Hi all,

Sorry for my ignorance and thanks for the help of everyone on these forums, but I am successfully getting OnReceiveFrom events and want to read the data stored in the provided PWSK_DATAGRAM_INDICATION which gives me a WSK_BUF which in turn has an PMDL.
Now I am uncertain how MDLs work and I’ve learnt I can’t just use MmGetMdlVirtualAddress() to get a pointer to the data (which is only 3 bytes).
What is the best way copy the 3 bytes out of the MDL into another buffer?

Thanks
Nik

Go read about NDIS_BUFFER structures. These are MDLs but the NDIS
documentation (the ‘legacy’ NDIS5 area) has good guidance on how to treat
chains of NDIS_BUFFERs (MDL Chains).

Then, you can forget all that and cheat by calling

TdiCopyBufferToMdl() and TdiCopyMdlToBuffer() :slight_smile:

But really, you ought to understand the underpinnings of the MDL, what it
describes, and how they are chained together in the network world.

NdisQueryBufferSafe() -> MmGetSystemAddressForMdlSafe()

That is pretty much what you need to do it yourself. Keep in mind that the
data may span multiple segments described by MDLs chained together. The
buffer is not necessarily contiguous. Clever parsers will only copy data
to a staging buffer when the data needs to be contiguous and is *not*
already contiguous in a single buffer (described by a single MDL somewhere
in the chain).

Good Luck,
Dave Cattley
Consulting Engineer
Systems Software Development

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@g2microsystems.com
Sent: Tuesday, April 07, 2009 9:39 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Reading data out of an MDL in OnReceiveFrom event

Hi all,

Sorry for my ignorance and thanks for the help of everyone on these forums,
but I am successfully getting OnReceiveFrom events and want to read the data
stored in the provided PWSK_DATAGRAM_INDICATION which gives me a WSK_BUF
which in turn has an PMDL.
Now I am uncertain how MDLs work and I’ve learnt I can’t just use
MmGetMdlVirtualAddress() to get a pointer to the data (which is only 3
bytes).
What is the best way copy the 3 bytes out of the MDL into another buffer?

Thanks
Nik


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I read from the WDK documentation that TDI will not be supported post Vista. So these TdiCopyBufferToMdl() and TdiCopyMdlToBuffer() functions will be obsolete after Vista? Do you know the alternative

Sure. Write your own.

And about TDI. I think that MSFT ‘over evangalized’ the death of TDI.
Sure, using TDI to access the TCP/IP stack might be on the chopping block
but what about the other transports that use TDI as a facility to expose
their services? Is the Bluetooth stack going to be rewritten to publish
its transports via some yet unnamed mechanism? Maybe so. But all of the
TDI clients and other drivers I have in current development that use TDI
services (I am excluding TDI filters) all seem to work just fine on Win7 and
of course they worked just fine on Vista/LH too. Maybe I am due a rude
awakening but not that I have seen yet.

So to MSFT:

So how about you [MSFT] tighten up the story on TDI a bit. Which is it?
The death of TDI or the death of TCP/IP as a TDI transport? Are you really
planning on killing AFD, WinSock Helpers, and TDI, etc? Or is that myth
just due to poor interpretation of some slides that got block-copy-&-pasted
to every section of MSDN where the acronym TDI is mentioned.

Good Luck,
Dave Cattley
Consulting Engineer
Systems Software Development

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, April 09, 2009 6:57 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Reading data out of an MDL in OnReceiveFrom event

I read from the WDK documentation that TDI will not be supported post Vista.
So these TdiCopyBufferToMdl() and TdiCopyMdlToBuffer() functions will be
obsolete after Vista? Do you know the alternative


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer