/// <summary> /// Injects a packet into the network stack. The injected packet may be one received from /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" />, /// or a modified version, or a completely new packet. Injected packets can be captured and /// diverted again by other WinDivert handles with lower priorities. /// </summary> /// <param name="handle"> /// A valid WinDivert handle created by <seealso cref="WinDivertOpen(string, WinDivertLayer, short, WinDivertOpenFlags)" />. /// </param> /// <param name="packet"> /// A buffer containing the packet to be injected. /// </param> /// <param name="packetLength"> /// A buffer containing the packet to be injected. /// </param> /// <param name="flags"> /// Reserved, set to zero. /// </param> /// <param name="address"> /// The <seealso cref="WinDivertAddress" /> for the injected packet. /// </param> /// <returns> /// TRUE if a packet was successfully injected, or FALSE otherwise. Use /// <seealso cref="Marshal.GetLastWin32Error" /> to get the reason. The error code /// ERROR_IO_PENDING indicates that the overlapped operation has been successfully initiated /// and that completion will be indicated at a later time. All other codes indicate an error. /// </returns> public static bool WinDivertSendEx(IntPtr handle, WinDivertBuffer packet, uint packetLength, ulong flags, ref WinDivertAddress address) { fixed (WinDivertAddress* pAddress = &address) { var result = WinDivertNative.WinDivertSendEx(handle, packet.BufferPointer, packetLength, flags, ref address, IntPtr.Zero, IntPtr.Zero); return result; } }
/// <summary> /// Injects a packet into the network stack. The injected packet may be one received from /// <seealso cref="WinDivertRecv(IntPtr, WinDivertBuffer, ref WinDivertAddress, ref uint)" />, /// or a modified version, or a completely new packet. Injected packets can be captured and /// diverted again by other WinDivert handles with lower priorities. /// </summary> /// <param name="handle"> /// A valid WinDivert handle created by <seealso cref="WinDivertOpen(string, WinDivertLayer, short, WinDivertOpenFlags)" />. /// </param> /// <param name="packet"> /// A buffer containing the packet to be injected. /// </param> /// <param name="packetLength"> /// A buffer containing the packet to be injected. /// </param> /// <param name="flags"> /// Reserved, set to zero. /// </param> /// <param name="address"> /// The <seealso cref="WinDivertAddress" /> for the injected packet. /// </param> /// <param name="sendLen"> /// The total number of bytes injected. /// </param> /// <param name="lpOverlapped"> /// An optional <seealso cref="NativeOverlapped" /> instance. /// </param> /// <returns> /// TRUE if a packet was successfully injected, or FALSE otherwise. Use /// <seealso cref="Marshal.GetLastWin32Error" /> to get the reason. The error code /// ERROR_IO_PENDING indicates that the overlapped operation has been successfully initiated /// and that completion will be indicated at a later time. All other codes indicate an error. /// </returns> public static bool WinDivertSendEx(IntPtr handle, WinDivertBuffer packet, uint packetLength, ulong flags, ref WinDivertAddress address, ref uint sendLen, ref NativeOverlapped lpOverlapped) { fixed (WinDivertAddress* pAddress = &address) { fixed (uint* pWriteLen = &sendLen) { var result = WinDivertNative.WinDivertSendEx(handle, packet.BufferPointer, (uint)packetLength, flags, ref address, ref sendLen, ref lpOverlapped); return result; } } }