Moved checksum check sooner in the parsing for faster failures
@@ -93,6 +93,11 @@ impl Packet {
let destination_port = reader.get_u16();
let verification_tag = reader.get_u32();
let their_checksum = reader.get_u32_le();
+ let our_checksum = generate_packet_checksum(raw);
+
+ if their_checksum != our_checksum {
+ return Err(Error::ErrChecksumMismatch.into());
+ }
let mut chunks = vec![];
let mut offset = PACKET_HEADER_SIZE;
@@ -130,11 +135,6 @@ impl Packet {
chunks.push(c);
}
- let our_checksum = generate_packet_checksum(raw);
- if their_checksum != our_checksum {
- return Err(Error::ErrChecksumMismatch.into());
- }
-
Ok(Packet {
source_port,
destination_port,
