📄 ippackagefilter.h
字号:
//
// 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.
//
#include "winioctl.h"
#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)
//内网定义
#define NETWORK_LIST 0
//访问外网
#define ACCESS_INTERNET 1
//白名单
#define WHITE_LIST 2
//全部数据包
#define ALL_FILTER 3
//本机端口过滤
#define LOCAL_PORT_FILTER 4
//IP黑名单
#define BLACK_LIST 5
//网络过滤
#define NET_FILTER 6
//struct to define filter rules
typedef struct filter
{
USHORT filter_type; //0:本机端口过滤 1:IP黑名单; 2:网段管理
USHORT direction; //0: 发送;1:接收;
ULONG myIp; //本机IP地址(客户段填写,数据库中不需要保存) ,用来判断数据包是接收还是发送的。
USHORT protocol; //协议号
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;
typedef struct net_mask
{
ULONG network; //网段
ULONG mask; //掩码
}network;
//struct to build a linked list
struct filterList
{
IPFilter ipf;
struct filterList *next;
};
struct networkList
{
network net;
struct networkList *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 + -