/// <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="address"> /// The <seealso cref="WinDivertAddress" /> for the injected packet. /// </param> /// <returns> /// TRUE if a packet was successfully injected, or FALSE if an error occurred. Use /// <seealso cref="Marshal.GetLastWin32Error" /> to get the reason for the error. /// </returns> public static bool WinDivertSend(IntPtr handle, WinDivertBuffer packet, uint packetLength, ref WinDivertAddress address) { fixed(WinDivertAddress *pAddress = &address) { uint sendLen = 0; var result = WinDivertNative.WinDivertSend(handle, packet.BufferPointer, packetLength, ref address, ref sendLen); 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="address"> /// The <seealso cref="WinDivertAddress" /> for the injected packet. /// </param> /// <param name="sendLen"> /// The total number of bytes injected. /// </param> /// <returns> /// TRUE if a packet was successfully injected, or FALSE if an error occurred. Use /// <seealso cref="Marshal.GetLastWin32Error" /> to get the reason for the error. /// </returns> public static bool WinDivertSend(IntPtr handle, WinDivertBuffer packet, uint packetLength, ref WinDivertAddress address, ref uint sendLen) { return WinDivertNative.WinDivertSend(handle, packet.BufferPointer, packetLength, ref address, ref sendLen); }