From 8d2b197f70657d1c5b6ef6910cef18caadf80358 Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Mon, 25 Nov 2024 17:56:14 +0530 Subject: Calculate checksum in to_bytes. --- src/vrrpv2.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/vrrpv2.rs') diff --git a/src/vrrpv2.rs b/src/vrrpv2.rs index c830899..a6321ea 100644 --- a/src/vrrpv2.rs +++ b/src/vrrpv2.rs @@ -110,15 +110,20 @@ impl VRRPv2 { self.count_ip_addrs, self.auth_type as u8, self.advertisement_interval, + 0x0, // checksum bits + 0x0, // checksum bits ] .as_ref(), )?; - wr.write_all(self.checksum.to_be_bytes().as_ref())?; for ip in self.ip_addrs.iter() { wr.write_all(&ip.to_bits().to_be_bytes())?; } wr.write_all([0; 8].as_ref())?; // Authentication Data - Ok(wr.into_inner()) + let mut bytes = wr.into_inner(); + // Calculate the checksum and set the respective bits + let sum = checksum(&bytes); + [bytes[6], bytes[7]] = sum.to_be_bytes(); + Ok(bytes) } } -- cgit v1.2.3