summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2025-07-01 23:06:02 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2025-07-01 23:43:08 +0530
commit0c7dd54139470b2c458da5fed40c3aa7d19d87e8 (patch)
tree7b89ad216acc4f36863d95da0f52d950be8e2813
parent70ebc010453db7fb0b3d557339363bf1b756e5fc (diff)
Use constants.
-rw-r--r--src/vrrpv2.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/vrrpv2.rs b/src/vrrpv2.rs
index fa41696..bcb2315 100644
--- a/src/vrrpv2.rs
+++ b/src/vrrpv2.rs
@@ -25,6 +25,11 @@ use std::net::Ipv4Addr;
/// | Authentication Data (2) |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// ```
+
+const VERSION: u8 = 2;
+const TYPE: u8 = 1;
+const VERSION_TYPE: u8 = (VERSION << 4) | TYPE; // 0x21
+
#[derive(Debug, PartialEq)]
pub struct VRRPv2 {
pub virtual_router_id: u8,
@@ -106,7 +111,7 @@ impl VRRPv2 {
let mut wr = Cursor::new(bytes);
wr.write_all(
[
- 0x21,
+ VERSION_TYPE,
self.virtual_router_id,
self.priority,
self.ip_addrs.len() as u8,
@@ -132,8 +137,8 @@ impl VRRPv2 {
fn parse(bytes: &[u8]) -> Result<VRRPv2, VRRPv2Error> {
let mut rdr = Cursor::new(bytes);
match rdr.read_u8()? {
- i if (i & 0xF) != 1 => return Err(VRRPv2Error::InvalidType),
- i if (i >> 4) != 2 => return Err(VRRPv2Error::InvalidVersion),
+ i if (i & 0xF) != TYPE => return Err(VRRPv2Error::InvalidType),
+ i if (i >> 4) != VERSION => return Err(VRRPv2Error::InvalidVersion),
_ => {}
};
let virtual_router_id = rdr.read_u8()?;