阅读:2939回复:4
关于在passthru中的数据包转发的问题!!
我在passthru里编了一个数据包的转发,如下代码加在ptreceive()内:
PUCHAR pPacketContent; UINT PacketLen; UINT FLAGS; CHAR ExchangeContent; INT iExchange; Status=NdisAllocateMemory(&pPacketContent,2000,0,HighestAcceptableMax); if (Status!=NDIS_STATUS_SUCCESS) { DbgPrint(\"ptreceive: ndisallocatememory failed\\n\"); return NDIS_STATUS_NOT_ACCEPTED; } if (pPacketContent==NULL) { DbgPrint(\"ptreceive: pPacketContent==NULL\\n\"); return NDIS_STATUS_NOT_ACCEPTED; } DbgPrint(\"ptreceive: I LIKE PASSTHRU!\\n\"); RtlZeroMemory(pPacketContent,2000); RtlCopyMemory(pPacketContent,HeaderBuffer,HeaderBufferSize); RtlCopyMemory(pPacketContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize); PacketLen=HeaderBufferSize+LookAheadBufferSize; DbgPrint(\"PacketLen:%u\\n\",PacketLen); if (((CHAR *)pPacketContent)[12]==8&& ((CHAR *)pPacketContent)[13]==0&& ((CHAR *)pPacketContent)[23]==17) { DbgPrint(\"UDP包被成功拦截!!\\n\"); pAdapt = pAdapt->pSecondaryAdapt; //交换MAC地址 for (iExchange=0;iExchange<=5;iExchange++) { ExchangeContent = ((CHAR *)pPacketContent)[iExchange]; ((CHAR *)pPacketContent)[iExchange] = ((CHAR *)pPacketContent)[iExchange+6]; ((CHAR *)pPacketContent)[iExchange+6] = ExchangeContent; } //交换IP地址 for (iExchange=26;iExchange<=29;iExchange++) { ExchangeContent = ((CHAR *)pPacketContent)[iExchange]; ((CHAR *)pPacketContent)[iExchange] = ((CHAR *)pPacketContent)[iExchange+4]; ((CHAR *)pPacketContent)[iExchange+4] = ExchangeContent; } //交换端口号 for (iExchange=34;iExchange<=35;iExchange++) { ExchangeContent = ((CHAR *)pPacketContent)[iExchange]; ((CHAR *)pPacketContent)[iExchange] = ((CHAR *)pPacketContent)[iExchange+2]; ((CHAR *)pPacketContent)[iExchange+2] = ExchangeContent; } MyPacket=(PNDIS_PACKET)pPacketContent; FLAGS = NdisGetPacketFlags(MyPacket); Status=MPSend(pAdapt,MyPacket,FLAGS); if (Status!=NDIS_STATUS_SUCCESS) { DbgPrint(\"UDP数据包转发不成功!\"); return NDIS_STATUS_NOT_ACCEPTED; } DbgPrint(\"UDP数据包转发成功!\"); NdisFreeMemory(pPacketContent,2000,0); NdisDprFreePacket(MyPacket); return NDIS_STATUS_NOT_ACCEPTED; } 我安装完后就蓝屏了,希望大虾给我指点迷津,使那个地方出错了 我现在只会用DDK里的free build environment检查编程的错误,又没有别的方法检测程序的非与发行错误。 |
|
最新喜欢:xiaoji... |
沙发#
发布于:2003-10-29 10:37
Status=MPSend(pAdapt,MyPacket,FLAGS);
if (Status!=NDIS_STATUS_SUCCESS) { DbgPrint(\"UDP数据包转发不成功!\"); return NDIS_STATUS_NOT_ACCEPTED; } 老大, 你好像是自己拷贝了一个完全的包。 那你在发送的时候, 为什么还去 调用 MPSEND ,不是NDISSEND 呢 ? 你调用了 MPSEND 后, Status==NDIS_STATUS_SUCCESS 的时候, 你资源马上放掉了。 当然有问题。 因为在 MPSEND 中, 调用 NDISSEND 的时候, 还有一次 资源释放的过程。 你这样搞, 相当与 释放了 两次, 当然 错啦。 |
|
板凳#
发布于:2003-10-29 16:07
ndissend发送的数据包要不要把mac帧的14个字节的首部放在上面?
|
|
地板#
发布于:2003-10-29 17:24
呵呵, NDISSEND 当然是完整的 包呀。
给分 呀。 |
|
地下室#
发布于:2011-06-30 21:06
HighestAcceptableMax显示有错误!
|
|
|