/// <summary> /// Receives a diverted packet that matched the filter passed to /// <seealso cref="WinDivertOpen(string, WinDivertLayer, short, WinDivertOpenFlags)" />. The /// received packet is guaranteed to match the filter. /// </summary> /// <param name="handle"> /// A valid WinDivert handle created by <seealso cref="WinDivertOpen(string, WinDivertLayer, short, WinDivertOpenFlags)" /> /// </param> /// <param name="packet"> /// A buffer for the captured packet. /// </param> /// <param name="address"> /// The <seealso cref="WinDivertAddress" /> of the captured packet. /// </param> /// <returns> /// TRUE if a packet was successfully received, or FALSE if an error occurred. Use /// <seealso cref="Marshal.GetLastWin32Error" /> to get the reason for the error. /// </returns> /// <remarks> /// The contents of the captured packet are written to packet. If the captured packet is /// larger than the packet buffer length, then the packet will be truncated. If recvLen is /// non-NULL, then the total number of bytes written to packet is placed there. If non-NULL, /// the address of the captured packet is written to pAddr. /// /// An application should call /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" /> /// as soon as possible after a successful call to WinDivertOpen(). When a WinDivert handle /// is open, any packet that matches the filter will be captured and queued until handled by /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" />. /// Packets are not queued indefinitely, and if not handled in a timely manner, any captured /// packet may be dropped. The amount of time a packet is queued can be controlled with the /// <seealso cref="WinDivertSetParam(IntPtr, WinDivertParam, ulong)" /> function. /// /// Captured packets are guaranteed to have correct checksums, or pseudo checksums, as /// indicated by the Pseudo*Checksum flags from the WINDIVERT_ADDRESS. /// /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" /> /// should not be used on any WinDivert handle created with the /// <seealso cref="WinDivertOpenFlags.Drop" /> set. /// </remarks> public static bool WinDivertRecv(IntPtr handle, WinDivertBuffer packet, ref WinDivertAddress address) { fixed(WinDivertAddress *pAddress = &address) { uint readLen = 0; var result = WinDivertNative.WinDivertRecv(handle, packet.BufferPointer, (uint)packet.Length, ref address, ref readLen); return(result); } }
/// <summary> /// Receives a diverted packet that matched the filter passed to /// <seealso cref="WinDivertOpen(string, WinDivertLayer, short, WinDivertOpenFlags)" />. The /// received packet is guaranteed to match the filter. /// </summary> /// <param name="handle"> /// A valid WinDivert handle created by <seealso cref="WinDivertOpen(string, WinDivertLayer, short, WinDivertOpenFlags)" /> /// </param> /// <param name="packet"> /// A buffer for the captured packet. /// </param> /// <param name="address"> /// The <seealso cref="WinDivertAddress" /> of the captured packet. /// </param> /// <param name="readLen"> /// The total number of bytes written to packet. /// </param> /// <returns> /// TRUE if a packet was successfully received, or FALSE if an error occurred. Use /// <seealso cref="Marshal.GetLastWin32Error" /> to get the reason for the error. /// </returns> /// <remarks> /// The contents of the captured packet are written to packet. If the captured packet is /// larger than the packet buffer length, then the packet will be truncated. If recvLen is /// non-NULL, then the total number of bytes written to packet is placed there. If non-NULL, /// the address of the captured packet is written to pAddr. /// /// An application should call /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" /> /// as soon as possible after a successful call to WinDivertOpen(). When a WinDivert handle /// is open, any packet that matches the filter will be captured and queued until handled by /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" />. /// Packets are not queued indefinitely, and if not handled in a timely manner, any captured /// packet may be dropped. The amount of time a packet is queued can be controlled with the /// <seealso cref="WinDivertSetParam(IntPtr, WinDivertParam, ulong)" /> function. /// /// Captured packets are guaranteed to have correct checksums, or pseudo checksums, as /// indicated by the Pseudo*Checksum flags from the WINDIVERT_ADDRESS. /// /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" /> /// should not be used on any WinDivert handle created with the /// <seealso cref="WinDivertOpenFlags.Drop" /> set. /// </remarks> public static bool WinDivertRecv(IntPtr handle, ref WinDivertBuffer packet, ref WinDivertAddress address) { return WinDivertNative.WinDivertRecv(handle, packet.BufferPointer, packet.Length, ref address, ref packet.Length); }