阅读:1817回复:0
NDIS驱动数据包转发,求教小弟我刚接触NDIS驱动这一块,有些数据包转发的问题想请教各位,我在网上找到一段代码,说能修改数据包的IP头,然后重新组包在发送。有一段代码我始终不能理解明白,主要的还是改IP头,和修改数据,在转发出去的那些代码。哪位能具体解释一下每行代码的用途吗 代码片段如下面: NdisZeroMemory (pPacketContent, 2000); NdisQueryBuffer(Packet->Private.Head, &pBuf, &BufLength); NdisMoveMemory(pPacketContent, pBuf, BufLength); i = BufLength; pNext = Packet->Private.Head; for(;;) { if(pNext == Packet->Private.Tail) break; pNext = pNext->Next; if(pNext == NULL) break; NdisQueryBufferSafe(pNext,&pBuf,&BufLength,32); NdisMoveMemory(pPacketContent+i,pBuf,BufLength); i+=BufLength; } DBGPRINT("############################# IP Packet #########################\n"); DbgPrint("Header\n"); DbgPrint("Sou IP \n"); DbgPrint("%u",pPacketContent[26]); DbgPrint("%u",pPacketContent[27]); DbgPrint("%u",pPacketContent[28]); DbgPrint("%u",pPacketContent[29]); DbgPrint("\n"); DbgPrint("Sou MAC \n"); DbgPrint("%x",pPacketContent[6]); DbgPrint("%x",pPacketContent[7]); DbgPrint("%x",pPacketContent[8]); DbgPrint("%x",pPacketContent[9]); DbgPrint("%x",pPacketContent[10]); DbgPrint("%x",pPacketContent[11]); pAdapt = pAdapt->pSecondaryAdapt; if(pPacketContent[26] == 192 && pPacketContent[27] == 168 &&pPacketContent[28] == 1 && pPacketContent[29] == 1) { pPacketContent[0]=0; pPacketContent[1]=25; pPacketContent[2]=224; pPacketContent[3]=124; pPacketContent[4]=39; pPacketContent[5]=92; pPacketContent[6]=0; pPacketContent[7]=25; pPacketContent[8]=224; pPacketContent[9]=125; pPacketContent[10]=71; pPacketContent[11]=52; pPacketContent[26]=192; pPacketContent[27]=168; pPacketContent[28]=1; pPacketContent[29]=2; pPacketContent[30]=192; pPacketContent[31]=168; pPacketContent[32]=1; pPacketContent[33]=1; NdisAllocateBuffer(&Status3,&MyBuffer,pAdapt->SendPacketPoolHandle,pPacketContent,i); if (Status3==NDIS_STATUS_SUCCESS ) { NdisChainBufferAtFront(MyPacket, MyBuffer); Resvd =(PRSVD)(MyPacket->ProtocolReserved); Resvd->OriginalPkt = MyPacket; NdisSetPacketFlags(MyPacket, NDIS_FLAGS_DONT_LOOPBACK); NdisReturnPackets(&Packet, 1); MyPacket->Private.Head->Next=NULL; MyPacket->Private.Tail=NULL; Resvd->IsPrivate = 1; Resvd->pMyBuffer=&MyBuffer; Resvd-> pMyContent=&pPacketContent; NdisSend(&Status4,pAdapt->BindingHandle,MyPacket); if(Status4!=NDIS_STATUS_PENDING) { NdisUnchainBufferAtFront(MyPacket,&MyBuffer); NdisQueryBufferSafe(MyBuffer,&pPacketContent,&BufLength,32); if(pPacketContent != NULL) NdisFreeMemory(pPacketContent,BufLength,0); NdisFreeBuffer(MyBuffer); NdisDprFreePacket(MyPacket); } return 0; } } |
|