阅读:1395回复:0
斑竹再问问你..
VOID
MPSendPackets( IN NDIS_HANDLE MiniportAdapterContext, IN PPNDIS_PACKET PacketArray, IN UINT NumberOfPackets ) { PADAPT pAdapt = (PADAPT)MiniportAdapterContext; NDIS_STATUS Status; UINT i; PVOID MediaSpecificInfo = NULL; UINT MediaSpecificInfoSize = 0; for (i = 0; i < NumberOfPackets; i++) { PNDIS_PACKET Packet, MyPacket; Packet = PacketArray; NdisAllocatePacket(&Status, &MyPacket, pAdapt->SendPacketPoolHandle); if (Status == NDIS_STATUS_SUCCESS) { PSEND_RSVD SendRsvd; PIPHeader pIPHeader; UCHAR buffer[2000]={0}; PNDIS_BUFFER MyBuffer= NULL; ULONG nReadBytes; USHORT iphdrlen; BOOLEAN bPass = TRUE; FltReadPacketData(Packet, buffer, 2000, &nReadBytes); //我将数据读到了一个buffer里面 DBGPRINT(("<== receive packets %d",nReadBytes )); bPass = FltCheckFilterRules(buffer, nReadBytes, TRUE);// 这个是一个过滤规则而已 if (!bPass) { pIPHeader = (PIPHeader)(buffer+14); //point to IP Packet header iphdrlen = (pIPHeader->iphVerLen & 0x0f) * sizeof(ULONG); //修改dscp字段 pIPHeader->ipTOS=0x12; pIPHeader->ipChecksum=0x00; // 计算ip首部校验和 pIPHeader->ipChecksum = checksum((USHORT *)pIPHeader,iphdrlen); //把数据copy给mybuffer //问题是从这里开始的,帮忙看看, NdisAllocateBuffer(&Status,&MyBuffer,pAdapt->SendPacketPoolHandle,buffer,nReadBytes); NdisChainBufferAtFront(MyPacket, MyBuffer); //把MyBuffer关联到MyPacket SendRsvd = (PSEND_RSVD)(MyPacket->ProtocolReserved); SendRsvd->OriginalPkt = NULL; MyPacket->Private.Head->Next = NULL; MyPacket->Private.Tail = NULL; NdisSetPacketFlags(MyPacket, NDIS_FLAGS_DONT_LOOPBACK); NdisSend(&Status,pAdapt->BindingHandle,MyPacket); if(Status != NDIS_STATUS_PENDING) { NdisUnchainBufferAtFront(MyPacket ,&MyBuffer); //从MyPacket中解除buffer NdisQueryBufferSafe(MyBuffer,(PVOID *)&buffer, &nReadBytes,NormalPagePriority ); NdisFreeMemory(buffer,2000, 0); NdisFreeBuffer(MyBuffer); NdisDprFreePacket(MyPacket); } } } 这是我的代码 我想用他来修改数据包 但是我一装上我的电脑就蓝了 我通过windbg调试发现应该是我写数据的时候,以及最后内存释放的问题 但是我不知道到底怎么解决 请斑竹帮忙看看 帮我找找解决方法 谢谢斑竹 |
|