libpnet / libpnet

Cross-platform, low level networking using the Rust programming language.
Apache License 2.0
2.23k stars 304 forks source link

Modify out-going packet? #573

Open konstare opened 2 years ago

konstare commented 2 years ago

Hi, Is it possible with pnet to modify out-going IPv4 packets. So for example, i can catch a packet sent to "destination". Something like this:

while let Ok(ethernet_packet) = channel.next() {
if let Some(ethernet) = EthernetPacket::new(ethernet_packet) {
if let Some(ip4) = Ipv4Packet::new(ethernet.payload()) {
if ip4.get_destination() == destination{
// Here I can analyze ip4.
}}}}

What i want is to modify the ip4 packet(changing flags) and send to the destination this modified packet without the captured one. In other words, can i intercept a packet with pnet?

Paul-weqe commented 2 months ago

Pretty late here. Not sure if you solved this but here goes.

EthernetPacket is only used for incoming packets and is immutable. If you would like to create your own packet (probably one that is outgoing), you will use the MutableEthernetPacket.

You can find more information on how this is handled here