public Socket(string filter) { this.filter = filter; this.handle = IntPtr.Zero; this.started = false; this.readbuffer = Marshal.AllocHGlobal((int)buffersize); // clean these up this.writebuffer = Marshal.AllocHGlobal((int)buffersize); this.addr = default(WINDIVERT_ADDRESS); this.onread = data => this.Write(data); this.onerror = error => { }; this.handle = WinDivert.WinDivertOpen(this.filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0); if (handle == new IntPtr(-1)) { var exception = new Win32Exception(Marshal.GetLastWin32Error()); throw exception; } this.started = true; this.thread = new Thread(this.Runtime); this.thread.Start(); }
internal static extern bool WinDivertSend([In] System.IntPtr handle, [In] System.IntPtr pPacket, [In] System.UInt32 packetLen, [In] ref WINDIVERT_ADDRESS pAddr, [Out] out System.UInt32 sendLen);
internal static extern bool WinDivertRecv([In] System.IntPtr handle, [Out] System.IntPtr pPacket, [In] System.UInt32 packetLen, [Out] out WINDIVERT_ADDRESS pAddr, [Out] out System.UInt32 recvLen);