示例#1
0
        public void ReadAttribute(out byte[] rcvData)
        {
            while (serializer.bytePos < serializer.byteLength && serializer.bytePos < methodLength)
            {
                STUNAddress   address;
                STUNAttribute attrType = (STUNAttribute)serializer.ReadUShort();
                attributeTypes.Add(attrType);
                switch (attrType)
                {
                case STUNAttribute.MappedAddress:
                case STUNAttribute.SourceAddress:
                case STUNAttribute.ChangedAddress:
                    address = ReadMappedAddress();
                    response.Add(attrType, address);
                    break;

                case STUNAttribute.XorPeerAddress:
                case STUNAttribute.XorMappedAddress:
                case STUNAttribute.XorRelayedAddress:
                    address = ReadXorMappedAddress();
                    response.Add(attrType, address);
                    break;

                case STUNAttribute.ErrorCode:
                    response.Add(attrType, ReadErrorCode());
                    break;

                case STUNAttribute.UnknownAttribute:
                    response.Add(attrType, ReadUnknownAttributes());
                    break;

                case STUNAttribute.ServerName:
                    response.Add(attrType, ReadString());
                    break;

                case STUNAttribute.Realm:
                    response.Add(attrType, ReadString());
                    break;

                case STUNAttribute.Username:
                    response.Add(attrType, ReadString());
                    break;

                default:
                    ushort attrLen = serializer.ReadUShort();
                    byte[] bytes   = serializer.ReadBytes(attrLen);
                    response.Add(attrType, bytes);
                    while (((attrLen++) % 4) != 0)
                    {
                        serializer.ReadByte();
                    }
                    break;
                }
            }
            rcvData = (byte[])Get(STUNAttribute.Data);
        }
示例#2
0
        public bool FromBuffer(byte[] buffer, long offset, long size)
        {
            serializer.SetBuffer(buffer, offset, size);

            if (buffer[offset] != 0x38)
            {
                IsMessage    = false;
                connectionID = serializer.ReadInt();
                data         = new byte[size - 4];
                Buffer.BlockCopy(buffer, (int)offset + 4, data, 0, (int)size - 4);
                //data = serializer.ReadBytes((int)size-4);
                return(false);
            }
            serializer.ReadByte(); // read heard 00111000
            methodType = (NATPMethod)serializer.ReadByte();
            if (!Enum.IsDefined(typeof(NATPMethod), methodType))
            {
                IsMessage          = false;
                serializer.bytePos = (int)offset;
                connectionID       = serializer.ReadInt();
                data = new byte[size - 4];
                Buffer.BlockCopy(buffer, (int)offset + 4, data, 0, (int)size - 4);
                //data = serializer.ReadBytes((int)size - 4);
                return(false);
            }
            IsMessage = true;
            ReadAttribute();
            data = null;
            return(true);
        }
示例#3
0
 public bool FromBuffer(byte[] buffer, long offset, long size)
 {
     if (buffer[offset] != 0x38)
     {
         IsMessage = false;  return(false);
     }
     serializer.SetBuffer(buffer, offset, size);
     serializer.ReadByte(); // read heard 00111000
     methodType = (SignalingMethod)serializer.ReadByte();
     if (!Enum.IsDefined(typeof(SignalingMethod), methodType))
     {
         IsMessage = false; return(false);
     }
     IsMessage = true;
     ReadAttribute();
     return(true);
 }
示例#4
0
 public bool FromBuffer(byte[] buffer, long offset, long size)
 {
     if (buffer[offset] != 0x38)
     {
         return(false);
     }
     serializer.SetBuffer(buffer, offset, size);
     serializer.ReadByte(); // read heard 00111000
     methodType = (SignalingMethod)serializer.ReadByte();
     if (!Enum.IsDefined(typeof(SignalingMethod), methodType))
     {
         return(false);
     }
     //Console.WriteLine("SignalingMethod: {0}", Enum.GetName(typeof(SignalingMethod), methodType));
     ReadAttribute();
     IsMessage = true;
     return(true);
 }