Click here to Skip to main content
15,892,298 members
Articles / Desktop Programming / MFC

Developing Firewalls for Windows 2000/XP

Rate me:
Please Sign up or sign in to vote.
4.86/5 (158 votes)
3 Nov 2003CPOL9 min read 1.1M   26.4K   491  
An article about developing Firewalls for Windows 2000/XP
/*

  DrvFltIp.H

  Author: your name
  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;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Spain Spain
To summarize: learn, learn, learn... and then try to remember something I.... I don't Know what i have to remember...

http://www.olivacorner.com

Comments and Discussions