0

我是驱动程序编程的新手,我找不到一个可能很简单的问题的解决方案。我正在编辑 wdk 示例中的 ndis_prot 示例驱动程序。目前,数据包作为 Irp 到达驱动程序并存储到 pNdisBuffer 中。我需要将该缓冲区分成两部分 - pNdisBuffer1 和 pNdisBuffer2 - 首先填充标头,然后填充数据并将它们都链接到 pNdisPacket。关于这方面的文章很少,但我找不到这方面的例子。应该是可能的,就像这里描述的那样

http://blogs.msdn.com/b/ntdebugging/archive/2008/09/19/ndis-part-1.aspx

但我想看看 wdk (代码)中的例子。

PS:请不要问我为什么需要这样做,也不要尝试将其更改为不同的东西。它只需要那样做。你能帮我吗?

4

1 回答 1

1

伪代码(错误处理和一些声明被省略等)

// initial code
PNDIS_PACKET sourcePack;
...
PNDIS_PACKET packet1, packet2, current;
NdisAllocatePacket(&status, &packet1, handle);
NdisAllocatePacket(&status, &packet2, handle);
current = packet1;
PNDIS_BUFFER sourceBuf, newBuf;
NdisGetFirstBufferFromPacket(sourcePack,&sourceBuf,&va,&len,&totalLen);
while(sourceBuf != NULL)
{
  NdisQueryBuffer(sourceBuf,&va,&len);
  if( .. (PUCHAR)va+x is a split point ..)
  {
    if(x != 0)
    {
      newBuf = NewBuf(va, x);
      NdisCahinBufferAtBack(current,newBuf);
    }
    current = packet2;
    newBuf = NewBuf(va+x, len-x);
  }
  else
  {
    newBuf = NewBuf(va,len);
  }
  NdisChainBufferAtBack(current,newBuf);
  NdisGetNextBuffer(sourceBuf,&sourceBuf);
}
...
PNDIS_BUFFER NewBuf(PVOID va, ULONG len)
{
  PNDIS_BUFFER newBuffer;
  NdisAllocateBuffer(&Status, &newBuffer, handle, va, len);
  return newBuffer;
}

// response to comment
newBuf = NewBuf(va, x);
NdisCahinBufferAtBack(current,newBuf);
newBuf = NewBuf(va+x, len-x);
NdisCahinBufferAtBack(current,newBuf);
于 2012-05-02T00:00:50.907 回答