diff options
| author | luwenpeng <[email protected]> | 2023-09-12 16:11:32 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2023-09-13 19:20:06 +0800 |
| commit | 8f9e0f719055487e4a352f5da74cae063bbcdbcc (patch) | |
| tree | a7d44661b4b2d79202abd2a79f3eeda1f791b98b /src/protocol/ipv4.rs | |
| parent | 8755e95f068da56c099e9c51dc4a89b55960e48d (diff) | |
[feature] Support GTPv1-U Decode
Diffstat (limited to 'src/protocol/ipv4.rs')
| -rw-r--r-- | src/protocol/ipv4.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/protocol/ipv4.rs b/src/protocol/ipv4.rs index 61dce29..a869031 100644 --- a/src/protocol/ipv4.rs +++ b/src/protocol/ipv4.rs @@ -32,7 +32,7 @@ use std::net::Ipv4Addr; */ #[derive(Clone, Debug, PartialEq, Eq)] -pub struct IPv4Header { +pub struct Ipv4Header { pub version: u8, // 4 bit pub ihl: u8, // 4 bit pub tos: u8, @@ -71,9 +71,9 @@ fn address_v4_decode(input: &[u8]) -> IResult<&[u8], Ipv4Addr> { Ok((input, Ipv4Addr::from(<[u8; 4]>::try_from(ipv4).unwrap()))) } -impl Decode for IPv4Header { - type Iterm = IPv4Header; - fn decode(input: &[u8]) -> IResult<&[u8], IPv4Header> { +impl Decode for Ipv4Header { + type Iterm = Ipv4Header; + fn decode(input: &[u8]) -> IResult<&[u8], Ipv4Header> { let (input, verihl) = version_hlen_decode(input)?; let (input, tos) = number::streaming::be_u8(input)?; let (input, length) = number::streaming::be_u16(input)?; @@ -89,7 +89,7 @@ impl Decode for IPv4Header { Ok(( input, - IPv4Header { + Ipv4Header { version: verihl.0, ihl: verihl.1 * 4, // verihl.1 * 32 / 8 tos, @@ -113,7 +113,7 @@ impl Decode for IPv4Header { #[cfg(test)] mod tests { - use super::IPv4Header; + use super::Ipv4Header; use crate::protocol::codec::Decode; use crate::protocol::ip::IPProtocol; use std::net::Ipv4Addr; @@ -160,7 +160,7 @@ mod tests { 0xff, /* Payload */ ]; - let expectation = IPv4Header { + let expectation = Ipv4Header { version: 4, ihl: 20, tos: 0, @@ -175,10 +175,10 @@ mod tests { dest_address: Ipv4Addr::new(121, 14, 154, 93), }; - assert_eq!(IPv4Header::decode(&bytes), Ok((LAST_SLICE, expectation))); + assert_eq!(Ipv4Header::decode(&bytes), Ok((LAST_SLICE, expectation))); // example - let result = IPv4Header::decode(&bytes); + let result = Ipv4Header::decode(&bytes); if let Ok((payload, header)) = result { println!("return: {:?}, payload: {}", header, payload.len()); } else { |
