原则",这些过滤原则会被低层的TCPIP实现用来过滤包。这种过滤工主要是对IP原地址、目标地址、端口号(或者端口号范围)进行pass或者drop操作。 Windows Developer's Journal 《用iphlpapi.dll进行包过滤》作者:Ton plooy,October,2000,Volume 11, Number 10。 WIN2000提供了一个较好对TCPIP的可编程控制,其中包括包过滤。不幸的是,有关这个新
//首先获得一个设备指针。 //first of all, we have to get a pointer to IpFilterDriver Device RtlInitUnicodeString(&filterName, DD_IPFLTRDRVR_DEVICE_NAME); status = IoGetDeviceObjectPointer(&filterName,STANDARD_RIGHTS_ALL,
&ipFileObject, &ipDeviceObject); if(NT_SUCCESS(status)) { //一些初始化工作,填充filterData。 //initialize the struct with functions parameters filterData.ExtensionPointer = filterFunction;
//we need initialize the event used later by the IpFilterDriver to
signal us //when it finished its work KeInitializeEvent(&event, NotificationEvent, FALSE);
//这个就是最重要的注册回调函数过程。DDK中具体讲述是这样的 //IOCTL_PF_SET_EXTENSION_POINTER registers filter-hook callback functions to
the IP filter driver //to inform the IP filter driver to call those filter hook callbacks for every IP packet //that is received or transmitted. Also, IOCTL_PF_SET_EXTENSION_POINTER
clears filter-hook //callback functions from the IP filter driver. (看到了吧,最后一句话,注册新的回调函
数,就将原先的清除掉了, //所以说系统中只存在一个这样的驱动有用。) //we build the irp needed to establish fitler function这个地方仅
/* Set number of ARP Request packets to send */ if(PacketSetNumWrites(lpAdapter, 1) == FALSE) { msgStatus = "Warning : unable to send more than one packet in a single write.."; SHOWSTAT(msgStatus); } /* Set hardware filter to directed mode */ if(PacketSetHwFilter(lpAdapter, NDIS_PACKET_TYPE_DIRECTED) == FALSE) { msgStatus ="Warning: unable to set directed mode.."; SHOWSTAT(msgStatus); } /* Set a 512K buffer in the driver */ if(PacketSetBuff(lpAdapter, 512000) == FALSE) { msgStatus = "Error: unable to set the kernel buffer.."; SHOWSTAT(msgStatus); PacketFreePacket(lpPacketRequest); return(EXIT_FAILURE); } /* Set a 1 second read timeout */ if(PacketSetReadTimeout(lpAdapter, -1) == FALSE) { msgStatus = "Warning: unable to set the read tiemout.."; SHOWSTAT(msgStatus); }
/* Allocate PACKET structure for ARP Reply packet */ if((lpPacketReply = PacketAllocatePacket()) == NULL) { msgStatus = "Error: failed to allocate the LPPACKET structure.."; SHOWSTAT(msgStatus); PacketFreePacket(lpPacketRequest); return(EXIT_FAILURE); } /* Init ARP Reply packet */ PacketInitPacket(lpPacketReply, (char*)buffer, 256000); /* Allocate memory for remote MAC address */ timestamp = GetTickCount();