wiresock / ndisapi

Windows Packet Filter library for network packet interception and manipulation, suitable for custom firewall, VPN and traffic analysis applications.
https://www.ntkernel.com/windows-packet-filter/
MIT License
289 stars 78 forks source link

Any example to build RawPacket based on PacketDotNet.Packet? #3

Closed frankzha closed 5 years ago

frankzha commented 5 years ago

In the example "TestDotNet.csproj", you demoed to get PacketDotNet.Packet from RawPacket by calling:

Packet p = Packet.ParsePacket(LinkLayers.Ethernet, packet.Data);

My scenario is that after I get the RawPacket, i need to modify its content. I would like to use PacketDotNet.Packet to modify the content because PacketDotNet provides definition of various packets, such as TCPPacket, UdpPacket, etc.

So after I have PacketDotNet.Packet instance object ready, how can I construct RawPacket based on PacketDotNet.Packet (TCP, UDP, etc) so that i can send RawPacket to below?

ndisapi.SendPacketToMstcp(adapterList[index - 1].Handle, packet); or ndisapi.SendPacketToAdapter(adapterList[index - 1].Handle, packet);

wiresock commented 5 years ago

NdisApi.RawPacket has a property named Data (array of bytes) and PacketDotNet.Packet has a read only property named Bytes (array of bytes). It is enough to assign one to another. Note to set checksum flags if packet was modified but checksums were not recalculated.