Exemplo n.º 1
0
        public void Read(byte[] buf, ref int offset)
        {
            Type = (AttributeType)NetBinaryUtil.ReadUShort(buf, ref offset);
            var size = NetBinaryUtil.ReadUShort(buf, ref offset);

            ReadBody(buf, offset, size);
            offset += size + GetPadOffset(size);
        }
Exemplo n.º 2
0
        protected override void ReadBody(byte[] buf, int offset, int size)
        {
            offset++;
            var family = buf[offset++];
            var port   = (int)(NetBinaryUtil.ReadUShort(buf, ref offset) ^ (ushort)(StunMessage.MagicCookie >> 16));

            byte[] address = NetBinaryUtil.ReadBytes(buf, family == 1 ? 4 : 16, ref offset);
            for (int i = 0; i < address.Length; i++)
            {
                address[i] = (byte)(address[i] ^ buf[i + 4]);
            }
            EndPoint = new IPEndPoint(new IPAddress(address), port);
        }
Exemplo n.º 3
0
        StunAttribute GetAttribute(byte[] buf, ref int offset)
        {
            int tmp  = offset;
            var type = (AttributeType)NetBinaryUtil.ReadUShort(buf, ref tmp);

            switch (type)
            {
            case AttributeType.MappedAddress:
            case AttributeType.SourceAddress:
            case AttributeType.ChangedAddress:
            case AttributeType.ReflectedFrom:
            case AttributeType.ResponseAddress:
            {
                var attr = new AddressAttribute(type);
                attr.Read(buf, ref offset);
                return(attr);
            }

            case AttributeType.XorMappedAddress:
            {
                var attr = new XorAddressAttribute(type);
                attr.Read(buf, ref offset);
                return(attr);
            }

            case AttributeType.ErrorCode:
            {
                var attr = new ErrorCodeAttribute(type);
                attr.Read(buf, ref offset);
                return(attr);
            }

            case AttributeType.ServerName:
            case AttributeType.Username:
            case AttributeType.Password:
            {
                var attr = new ErrorCodeAttribute(type);
                attr.Read(buf, ref offset);
                return(attr);
            }
            }
            var len = NetBinaryUtil.ReadUShort(buf, ref tmp);

            offset += len + StunAttribute.GetPadOffset(len);
            return(null);
        }