fn parse_attrs(&self, raw: &[u8], len: usize, packet: &mut StunPkt) {
        let rattrs: &[u8] = &raw[(DATA_OFFSET as usize)..];
        let mut i = 0;
        while i < len {
            let attr_typ:u16 = BigEndian::read_u16(&rattrs[i..i+2]);
            let mut attr_len:u16 = BigEndian::read_u16(&rattrs[i+2..i+4]);
            println!("Attr type {} len {} msg_len {}", attr_typ, attr_len, len);
            //let attr_val = raw[(DATA_OFFSET as usize)+i+4..(DATA_OFFSET as usize)+i+1+(attr_len as usize)].to_vec();
            let attr = self.parse_attr(raw, (DATA_OFFSET as usize)+i+4, attr_len as usize, attr_typ);
            // TODO(tlam): Deal with error
            let attr = match attr {
                Ok(val)  => Some(val),
                Err(_err) => None,
            };

            if attr.is_some() {
                packet.attrs.insert(attr_typ, attr.unwrap());
            }

            /* attr_val might not be aligned */
            if attr_len%4 != 0 {
                println!("Added {} of padding", (4-attr_len%4));
                attr_len = attr_len + (4-attr_len%4);
            }
            i += (attr_len as usize) + 4;
            println!("Next i {}", i);
        }
    }
/// Parse the attributes present in 'raw', injecting them into the packet
Parse the attributes present in 'raw', injecting them into the packet
Parse the attributes present in ' raw ' injecting them into the packet
fn parse_attrs(&self, raw: &[u8], len: usize, packet: &mut StunPkt) {
        let rattrs: &[u8] = &raw[(DATA_OFFSET as usize)..];
        let mut i = 0;
        while i < len {
            let attr_typ:u16 = BigEndian::read_u16(&rattrs[i..i+2]);
            let mut attr_len:u16 = BigEndian::read_u16(&rattrs[i+2..i+4]);
            println!("Attr type {} len {} msg_len {}", attr_typ, attr_len, len);
            //let attr_val = raw[(DATA_OFFSET as usize)+i+4..(DATA_OFFSET as usize)+i+1+(attr_len as usize)].to_vec();
            let attr = self.parse_attr(raw, (DATA_OFFSET as usize)+i+4, attr_len as usize, attr_typ);
            // TODO(tlam): Deal with error
            let attr = match attr {
                Ok(val)  => Some(val),
                Err(_err) => None,
            };
            if attr.is_some() {
                packet.attrs.insert(attr_typ, attr.unwrap());
            }
            /* attr_val might not be aligned */
            if attr_len%4 != 0 {
                println!("Added {} of padding", (4-attr_len%4));
                attr_len = attr_len + (4-attr_len%4);
            }
            i += (attr_len as usize) + 4;
            println!("Next i {}", i);
        }
    }
fn parse_attrs ( & self , raw : & [ u8 ] , len : usize , packet : & mut StunPkt ) { let rattrs : & [ u8 ] = & raw [ ( DATA_OFFSET as usize ) .. ] ; let mut i = 0 ; while i < len { let attr_typ : u16 = BigEndian :: read_u16 ( & rattrs [ i .. i + 2 ] ) ; let mut attr_len : u16 = BigEndian :: read_u16 ( & rattrs [ i + 2 .. i + 4 ] ) ; println ! ( " " attr_typ attr_len len ) ; //let attr_val = raw[(DATA_OFFSET as usize)+i+4..(DATA_OFFSET as usize)+i+1+(attr_len as usize)].to_vec(); let attr = self . parse_attr ( raw , ( DATA_OFFSET as usize ) + i + 4 , attr_len as usize , attr_typ ) ; // TODO(tlam): Deal with error let attr = match attr { Ok ( val ) => Some ( val ) , Err ( _err ) => None , } ; if attr . is_some ( ) { packet . attrs . insert ( attr_typ , attr . unwrap ( ) ) ; } /* attr_val might not be aligned */ if attr_len % 4 != 0 { println ! ( " " ( 4 attr_len 4 ) ) ; attr_len = attr_len + ( 4 - attr_len % 4 ) ; } i += ( attr_len as usize ) + 4 ; println ! ( " " i ) ; } }
Parse the attributes present in 'raw', injecting them into the packet
Parse the attributes present in ' raw ' injecting them into the packet
&self
raw
&[u8]
len
usize
packet
&mut StunPkt
&self
raw
&[u8]
len
usize
packet
&mut StunPkt