Originally posted by suityou01
View Post

[MarshalAs (UnmanagedType.ByValArray, SizeConst = 16)] byte[] sourceIP; [MarshalAs (UnmanagedType.ByValArray, SizeConst = 16)] byte[] destIP;

[MarshalAs (UnmanagedType.ByValArray, SizeConst = 16)] byte[] sourceIP; [MarshalAs (UnmanagedType.ByValArray, SizeConst = 16)] byte[] destIP;


ptrOutput = Marshal.AllocHGlobal(Marshal.SizeOf(fm));
typedef struct FIREWALL_MESSAGE_
{
LIST_ENTRY listEntry;
int srcport;
int destport;
char sourceIp[16];
char destIp[16];
int protocol;
long packetRef;
FWP_DIRECTION direction; //FWP_DIRECTION Defined in Inspect.h
int type;
} FIREWALL_MESSAGE;
public struct LIST_ENTRY
{
/// _LIST_ENTRY*
public System.IntPtr Flink;
/// _LIST_ENTRY*
public System.IntPtr Blink;
}
public struct FIREWALL_MESSAGE
{
public LIST_ENTRY listEntry;
public uint srcport;
public uint destport;
public char[] sourceIp;
public char[] destIp;
public uint protocol;
public uint packetRef;
public EFWPDIRECTION direction; //FWP_DIRECTION Defined in Inspect.h
public uint type;
}
typedef struct FIREWALL_STATUS_
{
int upTime; //Length of time the firewall has been running in time_t format
int packetsProcessed;
int packetsDropped;
int connectionAttemptsProcessed;
int connectionAttemptsRefused;
} FIREWALL_STATUS, *PFIREWALL_STATUS;
public struct FIREWALL_STATUS
{
uint upTime;
uint packetsProcessed;
uint packetsDropped;
uint connectionAttemptsProcessed;
uint connectionAttemptsRefused;
}
private bool sendIOControl(uint ioctlCode, object inputBuffer, ref FIREWALL_STATUS fs)
{
uint bytesReturned = 0;
uint inputBufferSize = 0;
uint outputBufferSize = 0;
IntPtr ptrOutput = IntPtr.Zero;
IntPtr ptrInput = IntPtr.Zero;
bool retVal = false;
ptrOutput = Marshal.AllocHGlobal(Marshal.SizeOf(fs));
if (inputBuffer != null)
{
inputBufferSize = (uint)Marshal.SizeOf(inputBuffer);
}
outputBufferSize = (uint)Marshal.SizeOf(fs);
retVal = DeviceIoControl(hDriver, ioctlCode, ptrInput, inputBufferSize, ptrOutput, outputBufferSize, ref bytesReturned, IntPtr.Zero);
return retVal;
}

Leave a comment: