阅读:2707回复:3
急救:请问如何在 ddk2k 的 Passthru 例子中过滤 ICMP 包???
各位大虾,请问如何在 ddk2k 的 Passthru 例子中过滤 ICMP 包?
现在我不能得到IP包(听说可以直接从HeadBuffer中的13,14字节识别,但我这样却把所有的包全部过滤了). 我是在 PTReceive 例程中过滤的. 请最好给出示例代码! 谢谢! |
|
最新喜欢:xiaoji...
|
沙发#
发布于:2001-08-01 12:09
PTReceive 例程中有这样一个函数,当你得到一个包的描述符指针Packet,就可利用此函数
NdisGetFirstBufferFromPacket( IN PNDIS_PACKET Packet, OUT PNDIS_BUFFER *FirstBuffer, OUT PVOID *FirstBufferVA, OUT PUINT FirstBufferLength, OUT PUINT TotalBufferLength ); 从FirstBufferVA开始 第13和14 个Byte就是以太网物理帧Frame头,格式为: 目的物理地址 源物理地址 帧格式 6 Bytes 6 Bytes 2 Bytes 其中,帧格式若是08 00(16进制),说明是IP数据包;若是08 06(16进制),说明是ARP数据包;若是80 35(16 进制),说明是RARP数据包 。 好像是ARP对应的是ICMP吧(我记不清了,你查一下),当你发现一包的13th、14th bytes 若是08 06,这就是ICMP包,你就可以对此处理了,它的生杀大权就在你手了。 相应的,你若要过滤某种协议,只要查一下对应的TCP协议和标记即可。但对IPX协议,好像也可以。 if (AnswerReturn == 满意 ) 记得给分!!; |
|
板凳#
发布于:2001-08-01 13:11
谢谢,我从 http://www.pcausa.com Copy 一个非常好的例程,能够识别以太帧类型.
///////////////////////////////////////////////////////////////////////////// //// UTILReadOnPacket // // Purpose // Logical read on the packet data in a NDIS_PACKET. // // Parameters // // Return Value // // Remarks // The purpose of this function is to provide a convenient mechanism to // read packet data from an NDIS_PACKET that may have multiple chained // NDIS_BUFFERs. // VOID UTILReadOnPacket( PNDIS_PACKET Packet, PUCHAR lpBuffer, ULONG nNumberOfBytesToRead, ULONG nOffset, // Byte Offset, Starting With MAC Header PULONG lpNumberOfBytesRead ) { PNDIS_BUFFER CurrentBuffer; UINT nBufferCount, TotalPacketLength; PUCHAR VirtualAddress; UINT CurrentLength, CurrentOffset; UINT AmountToMove; *lpNumberOfBytesRead = 0; if (!nNumberOfBytesToRead) return; // // Query Packet // NdisQueryPacket( (PNDIS_PACKET )Packet, (PUINT )NULL, // Physical Buffer Count (PUINT )&nBufferCount, // Buffer Count &CurrentBuffer, // First Buffer &TotalPacketLength // TotalPacketLength ); // // Query The First Buffer // NdisQueryBuffer( CurrentBuffer, &VirtualAddress, &CurrentLength ); CurrentOffset = 0; while( nOffset || nNumberOfBytesToRead ) { while( !CurrentLength ) { NdisGetNextBuffer( CurrentBuffer, &CurrentBuffer ); // If we've reached the end of the packet. We return with what // we've done so far (which must be shorter than requested). if (!CurrentBuffer) return; NdisQueryBuffer( CurrentBuffer, &VirtualAddress, &CurrentLength ); CurrentOffset = 0; } if( nOffset ) { // Compute how much data to move from this fragment if( CurrentLength > nOffset ) CurrentOffset = nOffset; else CurrentOffset = CurrentLength; nOffset -= CurrentOffset; CurrentLength -= CurrentOffset; } if( nOffset ) { CurrentLength = 0; continue; } if( !CurrentLength ) { continue; } // Compute how much data to move from this fragment if (CurrentLength > nNumberOfBytesToRead) AmountToMove = nNumberOfBytesToRead; else AmountToMove = CurrentLength; // Copy the data. NdisMoveMemory( lpBuffer, &VirtualAddress[ CurrentOffset ], AmountToMove ); // Update destination pointer lpBuffer += AmountToMove; // Update counters *lpNumberOfBytesRead +=AmountToMove; nNumberOfBytesToRead -=AmountToMove; CurrentLength = 0; } } |
|
|
地板#
发布于:2001-08-01 13:17
稍后给分!
|
|
|