伪代码(错误处理和一些声明被省略等)
// 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);