/// <summary> /// Constructs a MappedAddress based on an existing StunAttribute /// </summary> /// <param name="attribute">Base StunAttribute used to construct this specialized attribute</param> public ErrorCode(StunAttribute attribute) : base(StunAttributeType.ErrorCode, attribute.Value) { if (attribute.Type != StunAttributeType.ErrorCode) { throw new ArgumentException("is not a valid ERROR-CODE attribute", "attribute"); } }
public static bool TryParse(StunAttribute attribute, out StunMappedAddressAttribute result) { result = new StunMappedAddressAttribute(); if (attribute.Type != StunAttributeType.MappedAddress) { return(false); } if (!StunIPEndPoint.TryParse(attribute.Content, out var stunEndPoint)) { return(false); } result = new StunMappedAddressAttribute(stunEndPoint); return(true); }
public void InitializeAttributeList() { var firstAttribute = new StunAttribute(StunAttributeType.ChangedAddress, new byte[] { 1, 2, 3 }); var secondAttribute = new StunAttribute(StunAttributeType.MappedAddress, new byte[] { 4, 5, 6 }); var message = new StunBuilderStep().AddAttributes(new StunAttribute[] { firstAttribute, secondAttribute }) .Build(); var result = StunMessage.TryParse(message, out var parsedMessage); var parsedAttributes = parsedMessage.Attributes.GetEnumerator(); Assert.True(result); Assert.True(parsedAttributes.MoveNext()); Assert.Equal(firstAttribute.Type, parsedAttributes.Current.Type); Assert.True(firstAttribute.Content.Span.SequenceEqual(parsedAttributes.Current.Content.Span)); Assert.True(parsedAttributes.MoveNext()); Assert.Equal(secondAttribute.Type, parsedAttributes.Current.Type); Assert.True(secondAttribute.Content.Span.SequenceEqual(parsedAttributes.Current.Content.Span)); }
/// <summary> /// Constructs a UnknownAttributes based on an existing StunAttribute /// </summary> /// <param name="attribute">The StunAttribute base for this UnknownAttributes</param> public UnknownAttributes(StunAttribute attribute) : base(StunAttributeType.UnknownAttributes, attribute.Value) { if (attribute.Type != StunAttributeType.UnknownAttributes) throw new ArgumentException("is not a valid UNKNOWN-ATTRIBUTES attribute", "attribute"); Int32 offset = 0; while (offset < this.ValueLength) { byte[] unknownAttrBytes = StunUtilities.SubArray(this.Value, offset, 2); UInt16 unknownAttrValue = StunUtilities.ReverseBytes(BitConverter.ToUInt16(unknownAttrBytes, 0)); this.attributes.Add(unknownAttrValue); offset += 2; } }
/// <summary> /// Constructs a UnknownAttributes based on an existing StunAttribute /// </summary> /// <param name="attribute">The StunAttribute base for this UnknownAttributes</param> public UnknownAttributes(StunAttribute attribute) : base(StunAttributeType.UnknownAttributes, attribute.Value) { if (attribute.Type != StunAttributeType.UnknownAttributes) { throw new ArgumentException("is not a valid UNKNOWN-ATTRIBUTES attribute", "attribute"); } Int32 offset = 0; while (offset < this.ValueLength) { byte[] unknownAttrBytes = StunUtilities.SubArray(this.Value, offset, 2); UInt16 unknownAttrValue = StunUtilities.ReverseBytes(BitConverter.ToUInt16(unknownAttrBytes, 0)); this.attributes.Add(unknownAttrValue); offset += 2; } }
/// <summary> /// Constructs an HexAttribute based on an existing StunAttribute /// </summary> /// <param name="attribute">The StunAttribute base for this HexAttribute</param> public HexAttribute(StunAttributeType type, StunAttribute attribute) : base(type, attribute.Value) { }
/// <summary> /// Constructs a MappedAddress based on an existing StunAttribute /// </summary> /// <param name="attribute">Base StunAttribute used to construct this specialized attribute</param> public ErrorCode(StunAttribute attribute) : base(StunAttributeType.ErrorCode, attribute.Value) { if (attribute.Type != StunAttributeType.ErrorCode) throw new ArgumentException("is not a valid ERROR-CODE attribute", "attribute"); }
/// <summary> /// Constructs a XorMappedAddress based on an existing StunAttribute /// </summary> /// <param name="type">The StunAttributeType associated with the attribute parameter</param> /// <param name="attribute">The StunAttribute base for this XorMappedAddress</param> /// <param name="transactionID"> /// The transaction ID of the message from where the attribute parameter originates /// It may be used by this XorMappedAddress to decode an IPV6 address /// </param> public XorMappedAddress(StunAttributeType type, StunAttribute attribute, byte[] transactionID) : base(type, attribute) { this.TransactionID = transactionID; }
/// <summary> /// Constructs a MappedAddress based on an existing StunAttribute /// </summary> /// <param name="type">The StunAttributeType associated with the attribute parameter</param> /// <param name="attribute">The StunAttribute base for this MappedAddress</param> public MappedAddress(StunAttributeType type, StunAttribute attribute) : base(type, attribute.Value) { }
/// <summary> /// Constructs an HexAttribute based on an existing StunAttribute /// </summary> /// <param name="attribute">The StunAttribute base for this HexAttribute</param> public HexAttribute(StunAttributeType type, StunAttribute attribute) : base(type, attribute.Value) { }
/// <summary> /// Constructs a XorMappedAddress based on an existing StunAttribute /// </summary> /// <param name="type">The StunAttributeType associated with the attribute parameter</param> /// <param name="attribute">The StunAttribute base for this XorMappedAddress</param> /// <param name="transactionID"> /// The transaction ID of the message from where the attribute parameter originates /// It may be used by this XorMappedAddress to decode an IPV6 address /// </param> public XorMappedAddress(StunAttributeType type, StunAttribute attribute, byte[] transactionID) : base(type, attribute) { this.TransactionID = transactionID; }
/// <summary> /// Constructs a MappedAddress based on an existing StunAttribute /// </summary> /// <param name="type">The StunAttributeType associated with the attribute parameter</param> /// <param name="attribute">The StunAttribute base for this MappedAddress</param> public MappedAddress(StunAttributeType type, StunAttribute attribute) : base(type, attribute.Value) { }