pub fn parse_stun(&self, raw: &[u8]) -> Option<StunPkt> {
        let zeros:u8 = raw[0] & 0xC0;
        /* If not zero, this can't be a STUN message */
        if zeros != 0 {
            return None
        }

        let msg_typ:u16 = BigEndian::read_u16(&raw[0..2]) & 0x3FFF;
        let msg_mt = MsgMethod::from_raw(msg_typ);
        let msg_cl = MsgClass::from_raw(msg_typ);
        let msg_len:u16 = BigEndian::read_u16(&raw[2..4]);
        let magic:u32 = BigEndian::read_u32(&raw[4..8]);

        /* Magic cookie must be present in any valid STUN message */
        if magic != MAGIC_COOKIE {
            return None
        }

        /* Check the message length is sensible (last two bits must be zero) */
        if (msg_len & SENSIBLE_LEN) != 0 {
            return None
        }

        /* Verify message class and method are not "Unknown" */
        if msg_mt == MsgMethod::Unknown {
            return None
        }
        if msg_cl == MsgClass::Unknown {
            return None
        }

        /* At this stage, initial and preliminary validation has passed */

        let rtid = &raw[8..20];
        let mut a:[u32;3] = [0; 3];
        a[2] = BigEndian::read_u32(&rtid[0..4]);
        a[1] = BigEndian::read_u32(&rtid[4..8]);
        a[0] = BigEndian::read_u32(&rtid[8..12]);
        let trans_id:U96 = U96(a);

        /* Fill packet with parsed data */

        let mut pkt = StunPkt {
            msg_mt: msg_mt,
            msg_cl: msg_cl,
            msg_len: msg_len,
            trans_id: trans_id,
            attrs: HashMap::new(),
        };

        /* Header is always 20 bytes, rest of packet are attributes */
        self.parse_attrs(&raw, msg_len as usize, &mut pkt);

        Some(pkt)
    }
/// Parse the 'raw' payload into a StunPkt
Parse the 'raw' payload into a StunPkt
Parse the ' raw ' payload into a StunPkt
pub fn parse_stun(&self, raw: &[u8]) -> Option<StunPkt> {
        let zeros:u8 = raw[0] & 0xC0;
        /* If not zero, this can't be a STUN message */
        if zeros != 0 {
            return None
        }
        let msg_typ:u16 = BigEndian::read_u16(&raw[0..2]) & 0x3FFF;
        let msg_mt = MsgMethod::from_raw(msg_typ);
        let msg_cl = MsgClass::from_raw(msg_typ);
        let msg_len:u16 = BigEndian::read_u16(&raw[2..4]);
        let magic:u32 = BigEndian::read_u32(&raw[4..8]);
        /* Magic cookie must be present in any valid STUN message */
        if magic != MAGIC_COOKIE {
            return None
        }
        /* Check the message length is sensible (last two bits must be zero) */
        if (msg_len & SENSIBLE_LEN) != 0 {
            return None
        }
        /* Verify message class and method are not "Unknown" */
        if msg_mt == MsgMethod::Unknown {
            return None
        }
        if msg_cl == MsgClass::Unknown {
            return None
        }
        /* At this stage, initial and preliminary validation has passed */
        let rtid = &raw[8..20];
        let mut a:[u32;3] = [0; 3];
        a[2] = BigEndian::read_u32(&rtid[0..4]);
        a[1] = BigEndian::read_u32(&rtid[4..8]);
        a[0] = BigEndian::read_u32(&rtid[8..12]);
        let trans_id:U96 = U96(a);
        /* Fill packet with parsed data */
        let mut pkt = StunPkt {
            msg_mt: msg_mt,
            msg_cl: msg_cl,
            msg_len: msg_len,
            trans_id: trans_id,
            attrs: HashMap::new(),
        };
        /* Header is always 20 bytes, rest of packet are attributes */
        self.parse_attrs(&raw, msg_len as usize, &mut pkt);
        Some(pkt)
    }
pub fn parse_stun ( & self , raw : & [ u8 ] ) -> Option < StunPkt > { let zeros : u8 = raw [ 0 ] & 0xC0 ; /* If not zero, this can't be a STUN message */ if zeros != 0 { return None } let msg_typ : u16 = BigEndian :: read_u16 ( & raw [ 0 .. 2 ] ) & 0x3FFF ; let msg_mt = MsgMethod :: from_raw ( msg_typ ) ; let msg_cl = MsgClass :: from_raw ( msg_typ ) ; let msg_len : u16 = BigEndian :: read_u16 ( & raw [ 2 .. 4 ] ) ; let magic : u32 = BigEndian :: read_u32 ( & raw [ 4 .. 8 ] ) ; /* Magic cookie must be present in any valid STUN message */ if magic != MAGIC_COOKIE { return None } /* Check the message length is sensible (last two bits must be zero) */ if ( msg_len & SENSIBLE_LEN ) != 0 { return None } /* Verify message class and method are not "Unknown" */ if msg_mt == MsgMethod :: Unknown { return None } if msg_cl == MsgClass :: Unknown { return None } /* At this stage, initial and preliminary validation has passed */ let rtid = & raw [ 8 .. 20 ] ; let mut a : [ u32 ; 3 ] = [ 0 ; 3 ] ; a [ 2 ] = BigEndian :: read_u32 ( & rtid [ 0 .. 4 ] ) ; a [ 1 ] = BigEndian :: read_u32 ( & rtid [ 4 .. 8 ] ) ; a [ 0 ] = BigEndian :: read_u32 ( & rtid [ 8 .. 12 ] ) ; let trans_id : U96 = U96 ( a ) ; /* Fill packet with parsed data */ let mut pkt = StunPkt { msg_mt : msg_mt , msg_cl : msg_cl , msg_len : msg_len , trans_id : trans_id , attrs : HashMap :: new ( ) , } ; /* Header is always 20 bytes, rest of packet are attributes */ self . parse_attrs ( & raw , msg_len as usize , & mut pkt ) ; Some ( pkt ) }
Parse the 'raw' payload into a StunPkt
Parse the ' raw ' payload into a StunPkt
&self
raw
&[u8]
&self
raw
&[u8]