meh / rust-packet

Network packet handling for Rust.
90 stars 27 forks source link

Setting flag on ipv4 header gives invalid result #14

Open trinity-1686a opened 3 years ago

trinity-1686a commented 3 years ago

When trying to set the Don't Fragment flag on an Ipv4 packet, using .flags(Flags::DONT_FRAGMENT), the resulting packet is incorrect

| 45 | 00 | 00 28 | 00 00 | 00 02 | 40 | 06 | F7 14 | C0 A8 01 36 | C0 A8 01 33 |
                            ^^^^^

I underlined the flag+fragment offset fields. It should be 0x4000 (0b0100_0000_0000_0000).

It seems when modifying flags, the full 2 bytes are overwritten, without any bitshift https://github.com/meh/rust-packet/blob/7496656c097aa96678745e6628fe4b616209e1af/src/ip/v4/packet.rs#L307-L312