1 use crate::*; 2 3 /// Payload of an IP packet. 4 #[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] 5 pub struct IpPayloadSlice<'a> { 6 /// Identifying content of the payload. 7 pub ip_number: IpNumber, 8 9 /// True if the payload is not complete and has been fragmented. 10 /// 11 /// This can occur if the IPv4 incdicates that the payload 12 /// has been fragmented or if there is an IPv6 fragmentation 13 /// header indicating that the payload has been fragmented. 14 pub fragmented: bool, 15 16 /// Length field that was used to determine the length 17 /// of the payload (e.g. IPv6 "payload_length" field). 18 pub len_source: LenSource, 19 20 /// Payload 21 pub payload: &'a [u8], 22 } 23 24 #[cfg(test)] 25 mod test { 26 use super::*; 27 use alloc::format; 28 29 #[test] debug()30 fn debug() { 31 let s = IpPayloadSlice { 32 ip_number: IpNumber::UDP, 33 fragmented: true, 34 len_source: LenSource::Slice, 35 payload: &[], 36 }; 37 assert_eq!( 38 format!( 39 "IpPayloadSlice {{ ip_number: {:?}, fragmented: {:?}, len_source: {:?}, payload: {:?} }}", 40 s.ip_number, 41 s.fragmented, 42 s.len_source, 43 s.payload 44 ), 45 format!("{:?}", s) 46 ); 47 } 48 49 #[test] clone_eq_hash_ord()50 fn clone_eq_hash_ord() { 51 let s = IpPayloadSlice { 52 ip_number: IpNumber::UDP, 53 fragmented: true, 54 len_source: LenSource::Slice, 55 payload: &[], 56 }; 57 assert_eq!(s.clone(), s); 58 59 use std::collections::hash_map::DefaultHasher; 60 use std::hash::{Hash, Hasher}; 61 62 let a_hash = { 63 let mut hasher = DefaultHasher::new(); 64 s.hash(&mut hasher); 65 hasher.finish() 66 }; 67 let b_hash = { 68 let mut hasher = DefaultHasher::new(); 69 s.clone().hash(&mut hasher); 70 hasher.finish() 71 }; 72 assert_eq!(a_hash, b_hash); 73 74 use std::cmp::Ordering; 75 assert_eq!(s.clone().cmp(&s), Ordering::Equal); 76 assert_eq!(s.clone().partial_cmp(&s), Some(Ordering::Equal)); 77 } 78 } 79