pub fn add(&mut self, indicator: &Indicator, buffer: &[u8]) -> Option<Fragmentation> {
        let ipv4 = match indicator.get_ipv4() {
            Some(ipv4) => ipv4,
            None => return None,
        };

        let key = (ipv4.get_src(), ipv4.get_dst(), ipv4.get_identification());

        let mut is_create = false;
        if self.frags.contains_key(&key) {
            if self.frags.get(&key).unwrap().is_expired() {
                // Expired
                is_create = true;
            }
        } else {
            is_create = true;
        }

        if is_create {
            let frag = match Fragmentation::new(indicator) {
                Some(frag) => frag,
                None => return None,
            };

            self.frags.insert(key, frag);
        }

        let frag = self.frags.get_mut(&key).unwrap();

        // Add fragmentation
        let header_size = indicator.get_ethernet().unwrap().get_size() + ipv4.get_size();
        frag.add(indicator, &buffer[header_size..]);
        if frag.is_completed() {
            self.frags.remove(&key)
        } else {
            None
        }
    }
/// Adds a fragmentation and returns the fragmentation if it is completed.
Adds a fragmentation and returns the fragmentation if it is completed.
Adds a fragmentation and returns the fragmentation if it is completed .
pub fn add(&mut self, indicator: &Indicator, buffer: &[u8]) -> Option<Fragmentation> {
        let ipv4 = match indicator.get_ipv4() {
            Some(ipv4) => ipv4,
            None => return None,
        };
        let key = (ipv4.get_src(), ipv4.get_dst(), ipv4.get_identification());
        let mut is_create = false;
        if self.frags.contains_key(&key) {
            if self.frags.get(&key).unwrap().is_expired() {
                // Expired
                is_create = true;
            }
        } else {
            is_create = true;
        }
        if is_create {
            let frag = match Fragmentation::new(indicator) {
                Some(frag) => frag,
                None => return None,
            };
            self.frags.insert(key, frag);
        }
        let frag = self.frags.get_mut(&key).unwrap();
        // Add fragmentation
        let header_size = indicator.get_ethernet().unwrap().get_size() + ipv4.get_size();
        frag.add(indicator, &buffer[header_size..]);
        if frag.is_completed() {
            self.frags.remove(&key)
        } else {
            None
        }
    }
pub fn add ( & mut self , indicator : & Indicator , buffer : & [ u8 ] ) -> Option < Fragmentation > { let ipv4 = match indicator . get_ipv4 ( ) { Some ( ipv4 ) => ipv4 , None => return None , } ; let key = ( ipv4 . get_src ( ) , ipv4 . get_dst ( ) , ipv4 . get_identification ( ) ) ; let mut is_create = false ; if self . frags . contains_key ( & key ) { if self . frags . get ( & key ) . unwrap ( ) . is_expired ( ) { // Expired is_create = true ; } } else { is_create = true ; } if is_create { let frag = match Fragmentation :: new ( indicator ) { Some ( frag ) => frag , None => return None , } ; self . frags . insert ( key , frag ) ; } let frag = self . frags . get_mut ( & key ) . unwrap ( ) ; // Add fragmentation let header_size = indicator . get_ethernet ( ) . unwrap ( ) . get_size ( ) + ipv4 . get_size ( ) ; frag . add ( indicator , & buffer [ header_size .. ] ) ; if frag . is_completed ( ) { self . frags . remove ( & key ) } else { None } }
Adds a fragmentation and returns the fragmentation if it is completed.
Adds a fragmentation and returns the fragmentation if it is completed .
&mut self
indicator
&Indicator
buffer
&[u8]