diff options
Diffstat (limited to 'src/protocol/icmp.rs')
| -rw-r--r-- | src/protocol/icmp.rs | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/src/protocol/icmp.rs b/src/protocol/icmp.rs index 314c3d7..fee8749 100644 --- a/src/protocol/icmp.rs +++ b/src/protocol/icmp.rs @@ -7,7 +7,7 @@ use nom::IResult; ******************************************************************************/ #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum IcmpType { +pub enum ICMPType { EchoReply, DestinationUnreachable, SourceQuench, @@ -28,8 +28,8 @@ pub enum IcmpType { } #[derive(Clone, Debug, PartialEq, Eq)] -pub struct IcmpHeader { - pub icmp_type: IcmpType, +pub struct ICMPHeader { + pub icmp_type: ICMPType, pub icmp_code: u8, pub icmp_checksum: u16, pub icmp_extended: Vec<u8>, @@ -39,33 +39,33 @@ pub struct IcmpHeader { * API ******************************************************************************/ -impl From<u8> for IcmpType { +impl From<u8> for ICMPType { fn from(raw: u8) -> Self { match raw { - 0 => IcmpType::EchoReply, - 3 => IcmpType::DestinationUnreachable, - 4 => IcmpType::SourceQuench, - 5 => IcmpType::Redirect, - 8 => IcmpType::EchoRequest, - 9 => IcmpType::RouterAdvertisement, - 10 => IcmpType::RouterSolicitation, - 11 => IcmpType::TimeExceeded, - 12 => IcmpType::ParameterProblem, - 13 => IcmpType::Timestamp, - 14 => IcmpType::TimestampReply, - 15 => IcmpType::InformationRequest, - 16 => IcmpType::InformationReply, - 17 => IcmpType::AddressMaskRequest, - 18 => IcmpType::AddressMaskReply, - 30 => IcmpType::Traceroute, - other => IcmpType::Other(other), + 0 => ICMPType::EchoReply, + 3 => ICMPType::DestinationUnreachable, + 4 => ICMPType::SourceQuench, + 5 => ICMPType::Redirect, + 8 => ICMPType::EchoRequest, + 9 => ICMPType::RouterAdvertisement, + 10 => ICMPType::RouterSolicitation, + 11 => ICMPType::TimeExceeded, + 12 => ICMPType::ParameterProblem, + 13 => ICMPType::Timestamp, + 14 => ICMPType::TimestampReply, + 15 => ICMPType::InformationRequest, + 16 => ICMPType::InformationReply, + 17 => ICMPType::AddressMaskRequest, + 18 => ICMPType::AddressMaskReply, + 30 => ICMPType::Traceroute, + other => ICMPType::Other(other), } } } -impl Decode for IcmpHeader { - type Iterm = IcmpHeader; - fn decode(input: &[u8]) -> IResult<&[u8], IcmpHeader> { +impl Decode for ICMPHeader { + type Iterm = ICMPHeader; + fn decode(input: &[u8]) -> IResult<&[u8], ICMPHeader> { let (input, icmp_type) = number::streaming::be_u8(input)?; let (input, icmp_code) = number::streaming::be_u8(input)?; let (input, icmp_checksum) = number::streaming::be_u16(input)?; @@ -73,7 +73,7 @@ impl Decode for IcmpHeader { Ok(( input, - IcmpHeader { + ICMPHeader { icmp_type: icmp_type.into(), icmp_code, icmp_checksum, @@ -89,8 +89,8 @@ impl Decode for IcmpHeader { #[cfg(test)] mod tests { - use super::IcmpHeader; - use crate::protocol::{codec::Decode, icmp::IcmpType}; + use super::ICMPHeader; + use crate::protocol::{codec::Decode, icmp::ICMPType}; const LAST_SLICE: &'static [u8] = &[ 0x96, 0xb5, 0xe9, 0x5e, 0x00, 0x00, 0x00, 0x00, 0xac, 0xe6, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, @@ -125,17 +125,17 @@ mod tests { 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, ]; - let expectation = IcmpHeader { - icmp_type: IcmpType::EchoRequest, + let expectation = ICMPHeader { + icmp_type: ICMPType::EchoRequest, icmp_code: 0, icmp_checksum: 0xab05, icmp_extended: vec![0x5f, 0x2b, 0x00, 0x01], }; - assert_eq!(IcmpHeader::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(ICMPHeader::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = IcmpHeader::decode(&bytes); + let result = ICMPHeader::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { |
