僞代碼(錯誤處理&一些聲明中省略等)
// 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);
謝謝您的答覆。但現在我有2個數據包,每個數據包都有1個緩衝區?它可能只有1個數據包和2個緩衝區嗎? NDIS_BUFFER結構中有一個稱爲Next的變量,如pNdisBuffer1-> Next = pNdisBuffer2; pNdisBuffer2-> Next = NULL; NdisChainBufferAtFront(pNdisPacket,pNdisBuffer1);我理解對嗎?可能嗎? – Miroslav
您可能是對的,但MS不建議直接觸摸NDIS_BUFFER字段。請參閱代碼末尾的「回覆評論」。 – glagolig
其實我已經解決了我的問題,這要歸功於你的帖子。我已經用NdisCopyBuffer創建了2個新的緩衝區,我已經設置了偏移量和長度。但後來我有鏈接問題。問題實際上是 - >下一個變量。沒有必要設置它,只需設置兩個緩衝區旁邊的NULL,然後將它們鏈接到數據包併發送它。我在你的文章中看到它,它工作。謝謝 :) – Miroslav