-
-
[求助]有搞过NDIS数据包发送的大侠吗,指点一下
-
发表于: 2013-6-5 14:18 3276
-
我这里有一个发包的函数,不知是否正确?
NDIS_STATUS
CD_SendPacket (
PADAPT pAdapt,
PVOID pBuffer,
ULONG dwBufferLength
)
{
NDIS_STATUS nRet = NDIS_STATUS_FAILURE;
PNDIS_PACKET ndisPacket = NULL;
PNDIS_BUFFER ndisBuffer = NULL;
PUCHAR sendBuffer = NULL;
PSEND_RSVD sendRsvd = NULL;
NDIS_PHYSICAL_ADDRESS highestAcceptableAddress;
highestAcceptableAddress.QuadPart = -1;
do
{
if(pBuffer == NULL) break;
if(dwBufferLength < ETH_MIN_PACKET_SIZE || dwBufferLength > ETH_MAX_PACKET_SIZE) break;
nRet = NdisAllocateMemory(&sendBuffer, dwBufferLength, 0, highestAcceptableAddress);
//status = NdisAllocateMemoryWithTag (&sendBuffer, dwBufferLength, TAG);
if (nRet != NDIS_STATUS_SUCCESS) break;
RtlZeroMemory(sendBuffer, dwBufferLength);
RtlMoveMemory(sendBuffer, pBuffer, dwBufferLength);
NdisAllocatePacket(&nRet, &ndisPacket, pAdapt->SendPacketPoolHandle);
if (nRet != NDIS_STATUS_SUCCESS)
{
NdisFreeMemory(sendBuffer, dwBufferLength, 0);
break;
}
NdisAllocateBuffer(&nRet, &ndisBuffer, pAdapt->SendPacketPoolHandle, sendBuffer, dwBufferLength);
DBGPRINT(("SendRawData -> Allocate return: 0x%x, %d\n", sendBuffer, dwBufferLength));
if (nRet != NDIS_STATUS_SUCCESS)
{
NdisFreeMemory(sendBuffer, dwBufferLength, 0);
NdisFreePacket(ndisPacket);
break;
}
NdisChainBufferAtFront(ndisPacket, ndisBuffer);
sendRsvd = (PSEND_RSVD)(ndisPacket->ProtocolReserved);
sendRsvd->OriginalPkt = (PNDIS_PACKET)1; //标记自己
ndisPacket->Private.Head->Next = NULL;
ndisPacket->Private.Tail = NULL;
NdisSetPacketFlags(ndisPacket, NDIS_FLAGS_DONT_LOOPBACK);
DBGPRINT(("SendRawData -> Now send!\n"));
NdisSend(&nRet, pAdapt->BindingHandle, ndisPacket);
if (nRet != STATUS_PENDING)
{
NdisUnchainBufferAtFront(ndisPacket, &ndisBuffer);
NdisQueryBufferSafe(ndisBuffer, &sendBuffer, &dwBufferLength, NormalPagePriority);
NdisFreeBuffer(ndisBuffer);
NdisFreeMemory(sendBuffer, dwBufferLength, 0);
NdisFreePacket(ndisPacket);
DBGPRINT(("SendRawData -> Released!\n"));
}
} while (0);
return nRet;
}
NDIS_STATUS
CD_SendPacket (
PADAPT pAdapt,
PVOID pBuffer,
ULONG dwBufferLength
)
{
NDIS_STATUS nRet = NDIS_STATUS_FAILURE;
PNDIS_PACKET ndisPacket = NULL;
PNDIS_BUFFER ndisBuffer = NULL;
PUCHAR sendBuffer = NULL;
PSEND_RSVD sendRsvd = NULL;
NDIS_PHYSICAL_ADDRESS highestAcceptableAddress;
highestAcceptableAddress.QuadPart = -1;
do
{
if(pBuffer == NULL) break;
if(dwBufferLength < ETH_MIN_PACKET_SIZE || dwBufferLength > ETH_MAX_PACKET_SIZE) break;
nRet = NdisAllocateMemory(&sendBuffer, dwBufferLength, 0, highestAcceptableAddress);
//status = NdisAllocateMemoryWithTag (&sendBuffer, dwBufferLength, TAG);
if (nRet != NDIS_STATUS_SUCCESS) break;
RtlZeroMemory(sendBuffer, dwBufferLength);
RtlMoveMemory(sendBuffer, pBuffer, dwBufferLength);
NdisAllocatePacket(&nRet, &ndisPacket, pAdapt->SendPacketPoolHandle);
if (nRet != NDIS_STATUS_SUCCESS)
{
NdisFreeMemory(sendBuffer, dwBufferLength, 0);
break;
}
NdisAllocateBuffer(&nRet, &ndisBuffer, pAdapt->SendPacketPoolHandle, sendBuffer, dwBufferLength);
DBGPRINT(("SendRawData -> Allocate return: 0x%x, %d\n", sendBuffer, dwBufferLength));
if (nRet != NDIS_STATUS_SUCCESS)
{
NdisFreeMemory(sendBuffer, dwBufferLength, 0);
NdisFreePacket(ndisPacket);
break;
}
NdisChainBufferAtFront(ndisPacket, ndisBuffer);
sendRsvd = (PSEND_RSVD)(ndisPacket->ProtocolReserved);
sendRsvd->OriginalPkt = (PNDIS_PACKET)1; //标记自己
ndisPacket->Private.Head->Next = NULL;
ndisPacket->Private.Tail = NULL;
NdisSetPacketFlags(ndisPacket, NDIS_FLAGS_DONT_LOOPBACK);
DBGPRINT(("SendRawData -> Now send!\n"));
NdisSend(&nRet, pAdapt->BindingHandle, ndisPacket);
if (nRet != STATUS_PENDING)
{
NdisUnchainBufferAtFront(ndisPacket, &ndisBuffer);
NdisQueryBufferSafe(ndisBuffer, &sendBuffer, &dwBufferLength, NormalPagePriority);
NdisFreeBuffer(ndisBuffer);
NdisFreeMemory(sendBuffer, dwBufferLength, 0);
NdisFreePacket(ndisPacket);
DBGPRINT(("SendRawData -> Released!\n"));
}
} while (0);
return nRet;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
赞赏
他的文章
- [求助]请问这是什么工具,感觉挺牛叉的 2244
- 2767
- [求助]下面的汇编,如何翻译为c++ 2836
- [求助]帮忙看看,这段字符是什么加密的? 4228
- [求助]这段汇编代码是啥意思? 4388
看原图
赞赏
雪币:
留言: