请教NDIS中转发收到的包的问题

China_Wys 2010-10-13 12:13:09
现在在学习DDK的passthru例子,想实现一个功能就是:PtReceive中的收到的包调用NdisSend发送出去,并且不通知上层。

请问这个过程要做哪些处理?

我自己的理解:
1. 从PtReceive收到的NDIS_Packet中把数据取出来
2. 修改取出数据的IP头信息
3. 用修改后的数据再组一个包
4. 把新包用NdisSend发出去。

有代码或例子参考最好,谢谢!
...全文
107 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jw212 2010-10-21
转发的过程应该不修改数据吧,只对包头做处理
回复
China_Wys 2010-10-14

从PtReceive中取出的数据,判断是否为IP报文后发出,调用NdisSend时机器重启,期待高手指点,谢谢!

NDIS_STATUS
PtBmwSendRawData(
PADAPT adapt,
PVOID buffer,
ULONG length
)
{
NDIS_STATUS status = NDIS_STATUS_SUCCESS;
PNDIS_PACKET ndisPacket = NULL;
PNDIS_BUFFER ndisBuffer = NULL;
PUCHAR sendBuffer = NULL;

PSEND_RSVD sendRsvd = NULL;
NDIS_PHYSICAL_ADDRESS highestAcceptableAddress;
highestAcceptableAddress.QuadPart = -1;

ASSERT(buffer != NULL);
//ASSERT(length >= ETH_MIN_PACKET_SIZE && length <= ETH_MAX_PACKET_SIZE);



status = PtBmwMakeRawData(buffer, length);
if (status != NDIS_STATUS_SUCCESS)
{
return status;
}

DBGPRINT(("==> Protocol PtBmwSendRawData IP\n"));

status = NdisAllocateMemory(&sendBuffer, length, 0, highestAcceptableAddress);
//status = NdisAllocateMemoryWithTag (&sendBuffer, length, TAG);
if (status != NDIS_STATUS_SUCCESS)
{
return status;
}

RtlZeroMemory(sendBuffer, length);
RtlMoveMemory(sendBuffer, buffer, length);

NdisAllocatePacket(&status, &ndisPacket, adapt->SendPacketPoolHandle);
if (status != NDIS_STATUS_SUCCESS)
{
NdisFreeMemory(sendBuffer, length, 0);
return status;
}

NdisAllocateBuffer(&status, &ndisBuffer, adapt->SendPacketPoolHandle, sendBuffer, length);

if (status != NDIS_STATUS_SUCCESS)
{
NdisFreeMemory(sendBuffer, length, 0);
NdisFreePacket(ndisPacket);
return status;
}

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(&status, adapt->BindingHandle, ndisPacket);


DBGPRINT(("SendRawData -> Now send Complete!\n"));
if (status != STATUS_PENDING)
{
NdisUnchainBufferAtFront(ndisPacket, &ndisBuffer);
NdisQueryBufferSafe(ndisBuffer, &sendBuffer, &length, NormalPagePriority);
NdisFreeBuffer(ndisBuffer);
NdisFreeMemory(sendBuffer, length, 0);
NdisFreePacket(ndisPacket);
}

return status;
}
回复
相关推荐
发帖
驱动开发/核心开发
创建于2007-09-28

2.1w+

社区成员

硬件/嵌入开发 驱动开发/核心开发
申请成为版主
帖子事件
创建了帖子
2010-10-13 12:13
社区公告
暂无公告