meh / rust-packet

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

Wrong data_offset in a tcp packet with a payload #7

Open fdubois1 opened 5 years ago

fdubois1 commented 5 years ago

With tcp::Builder, if you build a packet with a payload (calling payload() function on the builder), when you build the packet, the data offset will be wrong (byte 12).

We have this code: let length = self.buffer.length(); let offset = (length / 4) as u8; tcp[12] = offset << 4 | flags;

The length include the payload. But the data_offset should not be built with that length. If we don't have any option in the header, the header size is 20 bytes, so we should get 5 (20/4). But we will get a different value, depending on the payload size.

I'm not sure the best way to fix it. We could keep the payload size in the struct and calculate the length of the header itself.