diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -32,6 +32,8 @@ pub use types::*; mod tests { use super::{de::Deserialize, ser::Serialize, *}; + use std::net::Ipv4Addr; + use ppproperly_macros::{Deserialize, Serialize}; #[test] @@ -1269,4 +1271,56 @@ mod tests { ); Ok(()) } + + #[test] + fn test_serialize_ipcp_configure_request() -> Result<()> { + let configure_request = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipcp(IpcpPkt::new_configure_request( + 0x41, + vec![IpcpOpt::IpAddr(Ipv4Addr::new(198, 51, 100, 1).into()).into()], + )), + ); + + let mut buf = Vec::new(); + configure_request.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x80, 0x21, 0x01, 0x41, 0x00, 0x0a, 0x03, 0x06, + 0xc6, 0x33, 0x64, 0x01 + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_ipcp_configure_request() -> Result<()> { + let mut configure_request = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x80, 0x21, 0x01, 0x41, 0x00, 0x0a, 0x03, 0x06, + 0xc6, 0x33, 0x64, 0x01, + ]; + configure_request.deserialize(&mut buf.as_ref())?; + + assert_eq!( + configure_request, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + 1, + PppPkt::new_ipcp(IpcpPkt::new_configure_request( + 0x41, + vec![IpcpOpt::IpAddr(Ipv4Addr::new(198, 51, 100, 1).into()).into()] + )) + ) + ); + Ok(()) + } } |