summaryrefslogtreecommitdiff
path: root/src/vrrpv2.rs
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2024-11-25 17:56:14 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2024-11-25 18:12:36 +0530
commit8d2b197f70657d1c5b6ef6910cef18caadf80358 (patch)
tree6b35f54f4464e9e0bd6510e777a2eda44da6456d /src/vrrpv2.rs
parent5206a097b8ec26265c54fdba3a259e226019db10 (diff)
Calculate checksum in to_bytes.
Diffstat (limited to 'src/vrrpv2.rs')
-rw-r--r--src/vrrpv2.rs9
1 files changed, 7 insertions, 2 deletions
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)
}
}