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

An Adventure: How to Implement a Firewall-Hook Driver?

Rate me:
Please Sign up or sign in to vote.
4.83/5 (65 votes)
28 Oct 20049 min read 672.1K   11K   194  
Firewall-Hook driver is a completely unknown method to develop simple packet filtering applications. With this article, I want to tell you how this driver works and what you need to do to use it in your applications.
/*

  FwHookDrv.H

  Author: Jes�s O.
  Last Updated : 12/09/03 
  
*/


//
// 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.
//
// Device type
#define FILE_DEVICE_FWHOOKDRV  0x00692322


#define FWHOOKDRV_IOCTL_INDEX  0x830


// IOCTLs
#define START_IP_HOOK CTL_CODE(FILE_DEVICE_FWHOOKDRV, FWHOOKDRV_IOCTL_INDEX,METHOD_BUFFERED, FILE_ANY_ACCESS)

#define STOP_IP_HOOK CTL_CODE(FILE_DEVICE_FWHOOKDRV, FWHOOKDRV_IOCTL_INDEX+1, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define ADD_FILTER CTL_CODE(FILE_DEVICE_FWHOOKDRV, FWHOOKDRV_IOCTL_INDEX+2, METHOD_BUFFERED, FILE_WRITE_ACCESS)

#define CLEAR_FILTER CTL_CODE(FILE_DEVICE_FWHOOKDRV, FWHOOKDRV_IOCTL_INDEX+3, METHOD_BUFFERED, FILE_ANY_ACCESS)



// Structure to define filter rules
typedef struct filter
{
	USHORT protocol;		// Protocol

	ULONG sourceIp;			// Source Ip
	ULONG destinationIp;	// Destination Ip

	ULONG sourceMask;		// Source Ip mask
	ULONG destinationMask;	// Destination Ip mask

	USHORT sourcePort;		// Source port
	USHORT destinationPort; // Destination port
	
	BOOLEAN drop;			// if TRUE, the packet will be dropped
}IPFilter, *PIPFilter;





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.


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