diff options
Diffstat (limited to 'src/protocol/ppp.rs')
| -rw-r--r-- | src/protocol/ppp.rs | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/protocol/ppp.rs b/src/protocol/ppp.rs index e625cb6..558e9a6 100644 --- a/src/protocol/ppp.rs +++ b/src/protocol/ppp.rs @@ -8,7 +8,7 @@ use nom::IResult; // https://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum PppProtocol { +pub enum PPPProtocol { PAD, // Padding Protocol IPv4, // Internet Protocol version 4 (IPv4) IPv6, // Internet Protocol version 6 (IPv6) @@ -22,50 +22,50 @@ pub enum PppProtocol { // https://www.rfc-editor.org/rfc/rfc1661.html #[derive(Clone, Debug, PartialEq, Eq)] -pub struct PppHeader { +pub struct PPPHeader { pub address: u8, pub control: u8, - pub protocol: PppProtocol, + pub protocol: PPPProtocol, } /****************************************************************************** * API ******************************************************************************/ -impl From<u16> for PppProtocol { +impl From<u16> for PPPProtocol { fn from(raw: u16) -> Self { match raw { - 0x0001 => PppProtocol::PAD, - 0x0021 => PppProtocol::IPv4, - 0x0057 => PppProtocol::IPv6, - 0x8021 => PppProtocol::IPCP, - 0x80FD => PppProtocol::CCP, - 0xC021 => PppProtocol::LCP, - 0xC023 => PppProtocol::PAP, - 0xC223 => PppProtocol::CHAP, - other => PppProtocol::Other(other), + 0x0001 => PPPProtocol::PAD, + 0x0021 => PPPProtocol::IPv4, + 0x0057 => PPPProtocol::IPv6, + 0x8021 => PPPProtocol::IPCP, + 0x80FD => PPPProtocol::CCP, + 0xC021 => PPPProtocol::LCP, + 0xC023 => PPPProtocol::PAP, + 0xC223 => PPPProtocol::CHAP, + other => PPPProtocol::Other(other), } } } -impl Decode for PppProtocol { - type Iterm = PppProtocol; - fn decode(input: &[u8]) -> IResult<&[u8], PppProtocol> { +impl Decode for PPPProtocol { + type Iterm = PPPProtocol; + fn decode(input: &[u8]) -> IResult<&[u8], PPPProtocol> { let (input, protocol) = number::streaming::be_u16(input)?; Ok((input, protocol.into())) } } -impl Decode for PppHeader { - type Iterm = PppHeader; - fn decode(input: &[u8]) -> IResult<&[u8], PppHeader> { +impl Decode for PPPHeader { + type Iterm = PPPHeader; + fn decode(input: &[u8]) -> IResult<&[u8], PPPHeader> { let (input, address) = number::streaming::be_u8(input)?; let (input, control) = number::streaming::be_u8(input)?; - let (input, protocol) = PppProtocol::decode(input)?; + let (input, protocol) = PPPProtocol::decode(input)?; Ok(( input, - PppHeader { + PPPHeader { address, control, protocol, @@ -80,8 +80,8 @@ impl Decode for PppHeader { #[cfg(test)] mod tests { - use super::PppHeader; - use super::PppProtocol; + use super::PPPHeader; + use super::PPPProtocol; use crate::protocol::codec::Decode; const LAST_SLICE: &'static [u8] = &[0xff]; @@ -96,16 +96,16 @@ mod tests { let bytes = [0xff, 0x03, 0xc0, 0x21, 0xff /* Payload */]; - let expectation = PppHeader { + let expectation = PPPHeader { address: 0xff, control: 0x03, - protocol: PppProtocol::LCP, + protocol: PPPProtocol::LCP, }; - assert_eq!(PppHeader::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(PPPHeader::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = PppHeader::decode(&bytes); + let result = PPPHeader::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { |
