⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drvfltip.h

📁 基于内核驱动的IP包过滤程序示例代码(一). 该代码是个测试程序,调用驱动实现包过滤. 驱动源码将在下期上载.
💻 H
字号:
/*

  DrvFltIp.H

  Author: ming.zhu
  Last Updated: 2001-01-01/0101

  This framework is generated by QuickSYS.

*/


//
// Define the various device type values.  Note that values used by Microsoft
// Corporation are in the range 0-32767, and 32768-65535 are reserved for use
// by customers.
//

#define FILE_DEVICE_DRVFLTIP  0x00654322



//
// Macro definition for defining IOCTL and FSCTL function control codes.  Note
// that function codes 0-2047 are reserved for Microsoft Corporation, and
// 2048-4095 are reserved for customers.
//

#define DRVFLTIP_IOCTL_INDEX  0x830



//
// The MONO device driver IOCTLs
//
#define START_IP_HOOK CTL_CODE(FILE_DEVICE_DRVFLTIP, DRVFLTIP_IOCTL_INDEX,METHOD_BUFFERED, FILE_ANY_ACCESS)

#define STOP_IP_HOOK CTL_CODE(FILE_DEVICE_DRVFLTIP, DRVFLTIP_IOCTL_INDEX+1, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define ADD_FILTER CTL_CODE(FILE_DEVICE_DRVFLTIP, DRVFLTIP_IOCTL_INDEX+2, METHOD_BUFFERED, FILE_WRITE_ACCESS)

#define CLEAR_FILTER CTL_CODE(FILE_DEVICE_DRVFLTIP, DRVFLTIP_IOCTL_INDEX+3, METHOD_BUFFERED, FILE_ANY_ACCESS)



//struct to define filter rules
typedef struct filter
{
	USHORT protocol;		//protocol used

	ULONG sourceIp;			//source ip address
	ULONG destinationIp;	//destination ip address

	ULONG sourceMask;		//source mask
	ULONG destinationMask;	//destination mask

	USHORT sourcePort;		//source port
	USHORT destinationPort; //destination port
	
	BOOLEAN drop;			//if true, the packet will be drop, otherwise the packet pass
}IPFilter;



//struct to build a linked list 
struct filterList
{
	IPFilter ipf;

	struct filterList *next;
};


//Ip Header
typedef struct IPHeader 
{
    UCHAR     iphVerLen;      // Version and length 
    UCHAR     ipTOS;          // Type of service 
    USHORT    ipLength;       // Total datagram length 
    USHORT    ipID;		      // Identification 
    USHORT    ipFlags;	      // Flags
    UCHAR     ipTTL;	      // Time to live 
    UCHAR     ipProtocol;	  // Protocol 
    USHORT    ipChecksum;     // Header checksum 
    ULONG     ipSource;       // Source address 
    ULONG     ipDestination;  // Destination address 
} IPPacket; 


//TCP Header
typedef struct _TCPHeader
{
	USHORT			sourcePort;			// Source Port
	USHORT			destinationPort;	// Destination Port
	ULONG			sequenceNumber;		// Number of Sequence
	ULONG			acknowledgeNumber;	// Number of aknowledge
	UCHAR			dataoffset;			// Pointer to data
	UCHAR			flags;				// Flags
	USHORT			windows;			// Size of window
	USHORT			checksum;			// Total checksum
	USHORT			urgentPointer;		// Urgent pointer
} TCPHeader;


//UDP Header
typedef struct _UDPHeader
{
	USHORT			sourcePort;			// Source Port
	USHORT			destinationPort;	// Destination Port
	USHORT			len;				// Total length
	USHORT			checksum;			// Total checksum
} UDPHeader;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -