use byteorder::{BigEndian, ReadBytesExt};
use std::io::{Error, Read};
use std::net::{Ipv4Addr, Ipv6Addr};
use crate::Header;
use crate::AFI;
#[derive(Debug)]
pub struct RIP {
pub remote: Ipv4Addr,
pub local: Ipv4Addr,
pub message: Vec<u8>,
}
impl RIP {
pub fn parse(header: &Header, stream: &mut Read) -> Result<RIP, Error> {
let length = (header.length - 2 * AFI::IPV4.size()) as usize;
let mut record = RIP {
remote: Ipv4Addr::from(stream.read_u32::<BigEndian>()?),
local: Ipv4Addr::from(stream.read_u32::<BigEndian>()?),
message: vec![0; length as usize],
};
stream.read_exact(&mut record.message)?;
Ok(record)
}
}
#[derive(Debug)]
pub struct RIPNG {
pub remote: Ipv6Addr,
pub local: Ipv6Addr,
pub message: Vec<u8>,
}
impl RIPNG {
pub fn parse(header: &Header, stream: &mut Read) -> Result<RIPNG, Error> {
let length = (header.length - 2 * AFI::IPV6.size()) as usize;
let mut record = RIPNG {
remote: Ipv6Addr::from(stream.read_u128::<BigEndian>()?),
local: Ipv6Addr::from(stream.read_u128::<BigEndian>()?),
message: vec![0; length as usize],
};
stream.read_exact(&mut record.message)?;
Ok(record)
}
}