阅读:1357回复:1
如何HOOK NDIS只让udp某端口的数据流入流出,其余数据包全部丢弃?
我已实现所有数据包不被转发到系统调用函数中。
很奇怪的是,我的UDP数据包好象始终不被转发。 下面是我的程序: NdisQueryBufferSafe(FirstBuffer, &VirtualAddress, &Length, HighPagePriority); pEthernetFrame = (PETHERNET_FRAME)VirtualAddress; EthernetFrameType = ntohs(pEthernetFrame->FrameType); if(EthernetFrameType != ETHERNET_FRAME_TYPE_TCPIP) return 0; // // 解析Ip Header // if((Length - ETHERNET_FRAME_LENGTH) >= IP_HEADER_LENGTH) { pIpHeader = (PIP_HEADER)((char*)pEthernetFrame + ETHERNET_FRAME_LENGTH); Length = Length - ETHERNET_FRAME_LENGTH; } else { NdisGetNextBuffer(FirstBuffer, &Buffer); if(Buffer == NULL) return 0; NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress == NULL || Length < IP_HEADER_LENGTH) return 0; pIpHeader = (PIP_HEADER)VirtualAddress; } HeaderLength = pIpHeader->HeaderLength * HEADER_LENGTH_MULTIPLE; //dprintf((\"HeaderLength: %u\\n\", HeaderLength)); PrintIp(pIpHeader, Length); if (pIpHeader->Protocol == PROTOCOL_UDP) { // // 解析UDP Header // if((Length - HeaderLength) < UDP_HEADER_LENGTH) { NdisGetNextBuffer(Buffer, &Buffer); if(Buffer == NULL) return 0; NdisQueryBufferSafe(Buffer, &VirtualAddress, &Length, HighPagePriority); if(VirtualAddress != NULL && Length >= UDP_HEADER_LENGTH) { pUdpHeader = (PUDP_HEADER)(VirtualAddress); } else { return 0; } } else { pUdpHeader = (PUDP_HEADER)((DWORD)pIpHeader + HeaderLength); } PrintUdp(pUdpHeader); if (((ntohs(pUdpHeader->SourcePort) == 6665) || (ntohs(pUdpHeader->SourcePort) == 6666)) && ((ntohs(pUdpHeader->DestinationPort) == 6665) || (ntohs(pUdpHeader->DestinationPort) == 6666))) { return 1; } } return 0; 返回 为 1则转发系统函数,为0则不转发。 我现在的问题是所有的数据包为什么都被丢弃了? |
|
沙发#
发布于:2003-11-26 15:35
if (((ntohs(pUdpHeader->SourcePort) == 6665)
|| (ntohs(pUdpHeader->SourcePort) == 6666)) && ((ntohs(pUdpHeader->DestinationPort) == 6665) || (ntohs(pUdpHeader->DestinationPort) == 6666))) { return 1; } 改为 if (((ntohs(pUdpHeader->SourcePort) == 6665) || (ntohs(pUdpHeader->SourcePort) == 6666)) || ((ntohs(pUdpHeader->DestinationPort) == 6665) || (ntohs(pUdpHeader->DestinationPort) == 6666))) { return 1; } 试试看 |
|
|