コード例 #1
0
 private void ParseAttribute(byte[] data, ref int offset)
 {
     AttributeType type = ((AttributeType)(data[offset++] << 8)) | ((AttributeType)data[offset++]);
     int count = (data[offset++] << 8) | data[offset++];
     if (type == AttributeType.MappedAddress)
     {
         this.m_pMappedAddress = this.ParseEndPoint(data, ref offset);
     }
     else if (type == AttributeType.ResponseAddress)
     {
         this.m_pResponseAddress = this.ParseEndPoint(data, ref offset);
     }
     else if (type == AttributeType.ChangeRequest)
     {
         offset += 3;
         this.m_pChangeRequest = new STUN_t_ChangeRequest((data[offset] & 4) != 0, (data[offset] & 2) != 0);
         offset++;
     }
     else if (type == AttributeType.SourceAddress)
     {
         this.m_pSourceAddress = this.ParseEndPoint(data, ref offset);
     }
     else if (type == AttributeType.ChangedAddress)
     {
         this.m_pChangedAddress = this.ParseEndPoint(data, ref offset);
     }
     else if (type == AttributeType.Username)
     {
         this.m_UserName = Encoding.Default.GetString(data, offset, count);
         offset += count;
     }
     else if (type == AttributeType.Password)
     {
         this.m_Password = Encoding.Default.GetString(data, offset, count);
         offset += count;
     }
     else if (type == AttributeType.MessageIntegrity)
     {
         offset += count;
     }
     else if (type == AttributeType.ErrorCode)
     {
         int code = ((data[offset + 2] & 7) * 100) + (data[offset + 3] & 0xff);
         this.m_pErrorCode = new STUN_t_ErrorCode(code, Encoding.Default.GetString(data, offset + 4, count - 4));
         offset += count;
     }
     else if (type == AttributeType.UnknownAttribute)
     {
         offset += count;
     }
     else if (type == AttributeType.ReflectedFrom)
     {
         this.m_pReflectedFrom = this.ParseEndPoint(data, ref offset);
     }
     else if (type == AttributeType.ServerName)
     {
         this.m_ServerName = Encoding.Default.GetString(data, offset, count);
         offset += count;
     }
     else
     {
         offset += count;
     }
 }
コード例 #2
0
ファイル: STUN_Message.cs プロジェクト: xiaoliukai/VMukti
        private void ParseAttribute(byte[] data, ref int offset)
        {
            AttributeType type  = ((AttributeType)(data[offset++] << 8)) | ((AttributeType)data[offset++]);
            int           count = (data[offset++] << 8) | data[offset++];

            if (type == AttributeType.MappedAddress)
            {
                this.m_pMappedAddress = this.ParseEndPoint(data, ref offset);
            }
            else if (type == AttributeType.ResponseAddress)
            {
                this.m_pResponseAddress = this.ParseEndPoint(data, ref offset);
            }
            else if (type == AttributeType.ChangeRequest)
            {
                offset += 3;
                this.m_pChangeRequest = new STUN_t_ChangeRequest((data[offset] & 4) != 0, (data[offset] & 2) != 0);
                offset++;
            }
            else if (type == AttributeType.SourceAddress)
            {
                this.m_pSourceAddress = this.ParseEndPoint(data, ref offset);
            }
            else if (type == AttributeType.ChangedAddress)
            {
                this.m_pChangedAddress = this.ParseEndPoint(data, ref offset);
            }
            else if (type == AttributeType.Username)
            {
                this.m_UserName = Encoding.Default.GetString(data, offset, count);
                offset         += count;
            }
            else if (type == AttributeType.Password)
            {
                this.m_Password = Encoding.Default.GetString(data, offset, count);
                offset         += count;
            }
            else if (type == AttributeType.MessageIntegrity)
            {
                offset += count;
            }
            else if (type == AttributeType.ErrorCode)
            {
                int code = ((data[offset + 2] & 7) * 100) + (data[offset + 3] & 0xff);
                this.m_pErrorCode = new STUN_t_ErrorCode(code, Encoding.Default.GetString(data, offset + 4, count - 4));
                offset           += count;
            }
            else if (type == AttributeType.UnknownAttribute)
            {
                offset += count;
            }
            else if (type == AttributeType.ReflectedFrom)
            {
                this.m_pReflectedFrom = this.ParseEndPoint(data, ref offset);
            }
            else if (type == AttributeType.ServerName)
            {
                this.m_ServerName = Encoding.Default.GetString(data, offset, count);
                offset           += count;
            }
            else
            {
                offset += count;
            }
        }