阅读:2259回复:3
DDK2000中的passthru例子:PtReceive和PtReceivePacket的问题
我在PtReceive和PtReceivePacket中分别用DbgPrint输出信息,然后我在用户层发送一个数据包,PtReceiv没有被调用,而PtReceivePacket被调用了,但是PtReceivePacket只带下面那两个参数
IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_PACKET Packet 怎么查看数据包的所有内容?包括以太头 |
|
沙发#
发布于:2010-03-08 14:53
先把基础打好了。再搞这些问题。
针对你现在的问题:数据明显就在PNDIS_PACKET里面,查询该数据包就可以。至于如何查询,那时基础问题,找资料就行。 |
|
|
板凳#
发布于:2010-03-08 23:13
楼上说得对,先吧基础打好了,呵呵
我用下面方法解决了 PNDIS_BUFFER PNdisBuf; PETHER_HEADER PEtherHeader; //自己定义的结构 PVOID Buffer; UINT BufLen; PNdisBuf = MyPacket->Private.Head; NdisQueryBufferSafe(PNdisBuf, &Buffer, &BufLen, 16); PEtherHeader = (PETHER_HEADER)Buffer; switch(ntohs(PEtherHeader->Type)) { case 0x0806: //ARP DbgPrint("ARP: "); break; case 0x0800: //IP DbgPrint("IP: "); break; } DbgPrint("Packet len: %d.\n", BufLen); DbgPrint("%02X-%02X-%02X-%02X-%02X-%02X -> %02X-%02X-%02X-%02X-%02X-%02X\n", PEtherHeader->SrcMAC[0], PEtherHeader->SrcMAC[1], PEtherHeader->SrcMAC[2], PEtherHeader->SrcMAC[3], PEtherHeader->SrcMAC[4], PEtherHeader->SrcMAC[5], PEtherHeader->DstMAC[0], PEtherHeader->DstMAC[1], PEtherHeader->DstMAC[2], PEtherHeader->DstMAC[3], PEtherHeader->DstMAC[4], PEtherHeader->DstMAC[5]); |
|
地板#
发布于:2010-03-14 01:21
VOID
Receive(IN PNDIS_PACKET Packet) { UINT PhysicalBufferCount; UINT BufferCount; PNDIS_BUFFER FirstBuffer, Buffer; UINT TotalPacketLength; WORD EthHeadType; INT HeaderLength; PETH_HEADER pEthHeader; PIP_HEADER pIpHeader; PTCP_HEADER pTcpHeader; PUDP_HEADER pUdpHeader; PICMP_HEADER pIcmpHeader; PVOID pBiosBuffer; PVOID VirtualAddress; INT Length = 0; TotalPacketLength = 0; NdisQueryPacket( Packet, &PhysicalBufferCount, &BufferCount, &FirstBuffer, &TotalPacketLength ); if(FirstBuffer == NULL) return; Buffer = FirstBuffer; ////////////////////////////////////////////////////////////////////////// // 1.Ethernet header NdisQueryBufferSafe(FirstBuffer, &VirtualAddress, &Length, HighPagePriority); pEthHeader = (PETH_HEADER)VirtualAddress; ////////////////////////////////////////////////////////////////////////// // 2.Analyze IP Packet // EthHeadType = ntohs(pEthHeader->HeadType); if (EthHeadType != ETHD_TYPE_IP) return; // --------------------------------------------------------------------------------- // A.Get the IP Header if((Length - ETHD_LENGTH) >= IP_HEADER_LENGTH) // 剩余的字节中包含 IP 头 { pIpHeader = (PIP_HEADER)((PCHAR)pEthHeader + ETHD_LENGTH); Length -= ETHD_LENGTH; } else { NdisGetNextBuffer(FirstBuffer, &Buffer); // 不包含 IP 头,GetNextBuffer if(Buffer == NULL) return; NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress == NULL || Length < IP_HEADER_LENGTH) // 不含IP头 return; pIpHeader = (PIP_HEADER)VirtualAddress; } HeaderLength = pIpHeader->Length * HEADER_LENGTH_MULTIPLE; // --------------------------------------------------------------------------------- // B.Analyze IP Header // switch(pIpHeader->Protocol) { case PROTOCOL_TCP: ////////////////////////////////////////////////////////////////////////// // Analyze TCP Header // #if 0 if((Length - HeaderLength) < TCP_HEADER_LENGTH) { NdisGetNextBuffer(Buffer, &Buffer); if(Buffer == NULL) return; NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress != NULL && Length >= TCP_HEADER_LENGTH) { pTcpHeader = (PTCP_HEADER)(VirtualAddress); } else { return; } } else { pTcpHeader = (PTCP_HEADER)((DWORD)pIpHeader + HeaderLength); } pBiosBuffer = NULL; if(Buffer != NULL) { NdisGetNextBuffer(Buffer, &Buffer); if(Buffer != NULL) { NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress != NULL && Length >= NETBIOS_MIN_PACKET_SIZE) pBiosBuffer = (void*)VirtualAddress; } } #endif ////////////////////////////////////////////////////////////////////////// break; case PROTOCOL_UDP: ////////////////////////////////////////////////////////////////////////// // 解析UDP Header // #if 0 if((Length - HeaderLength) < UDP_HEADER_LENGTH) { NdisGetNextBuffer(Buffer, &Buffer); if(Buffer == NULL) return; NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress != NULL && Length >= UDP_HEADER_LENGTH) { pUdpHeader = (PUDP_HEADER)(VirtualAddress); } else { return ; } } else { pUdpHeader = (PUDP_HEADER)((DWORD)pIpHeader + HeaderLength); } pBiosBuffer = NULL; if(Buffer != NULL) { NdisGetNextBuffer(Buffer, &Buffer); if(Buffer != NULL) { NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress != NULL && Length >= NETBIOS_MIN_PACKET_SIZE) pBiosBuffer = (void*)VirtualAddress; } } #endif ////////////////////////////////////////////////////////////////////////// break; case PROTOCOL_ICMP: ////////////////////////////////////////////////////////////////////////// // 解析 ICMP // #if 0 if((Length - HeaderLength) < ICMP_HEADER_LENGTH) { NdisGetNextBuffer(Buffer, &Buffer); if(Buffer == NULL) return; NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress != NULL && Length >= ICMP_HEADER_LENGTH) pIcmpHeader = (PICMP_HEADER)(VirtualAddress); else return; } else { pIcmpHeader = (PICMP_HEADER)((DWORD)pIpHeader + HeaderLength); } #endif ////////////////////////////////////////////////////////////////////////// break; case PROTOCOL_IGMP: break; default: break; } } |
|
|