Beispiel #1
0
        /// <summary>
        /// Convert a StunMethodType to an host-byte ordered unsigned short
        /// </summary>
        /// <param name="mType">The StunMethodType to convert</param>
        /// <returns>
        /// The unsigned short (16bits) matching the StunMethodType
        /// Returns max UInt16 value if type parameter is StunMethodType.Unmanaged
        /// </returns>
        public static UInt16 MethodTypeToUInt16(StunMethodType mType)
        {
            foreach (FieldInfo field in typeof(StunMethodType).GetFields())
            {
                if (field.Name == mType.ToString())
                {
                    Object[] fieldAttributes = field.GetCustomAttributes(typeof(StunValueAttribute), false);

                    if (fieldAttributes.Length == 1)
                    {
                        StunValueAttribute stunValueAttribute = fieldAttributes.GetValue(0) as StunValueAttribute;

                        return(stunValueAttribute.Value);
                    }
                }
            }
            return(0xFFFF);
        }
Beispiel #2
0
        /// <summary>
        /// Convert a StunMethodType to an host-byte ordered unsigned short
        /// </summary>
        /// <param name="mType">The StunMethodType to convert</param>
        /// <returns>
        /// The unsigned short (16bits) matching the StunMethodType
        /// Returns max UInt16 value if type parameter is StunMethodType.Unmanaged
        /// </returns>
        public static UInt16 MethodTypeToUInt16(StunMethodType mType)
        {
            foreach (FieldInfo field in typeof(StunMethodType).GetFields())
            {
                if (field.Name == mType.ToString())
                {
                    Object[] fieldAttributes = field.GetCustomAttributes(typeof(StunValueAttribute), false);

                    if (fieldAttributes.Length == 1)
                    {
                        StunValueAttribute stunValueAttribute = fieldAttributes.GetValue(0) as StunValueAttribute;

                        return stunValueAttribute.Value;
                    }
                }
            }
            return 0xFFFF;
        }
Beispiel #3
0
 /// <summary>
 /// Construct a message with given type, class and transaction ID
 /// </summary>
 /// <param name="type">The type of the message</param>
 /// <param name="mclass">The class of the message</param>
 /// <param name="transactionId">The transaction ID of the message </param>
 public StunMessage(StunMethodType type, StunMethodClass mclass, byte[] transactionId)
 {
     this.MethodType    = type;
     this.MethodClass   = mclass;
     this.TransactionID = transactionId;
 }
Beispiel #4
0
 /// <summary>
 /// Construct a message with given type, class and transaction ID
 /// </summary>
 /// <param name="type">The type of the message</param>
 /// <param name="mclass">The class of the message</param>
 /// <param name="transactionId">The transaction ID of the message </param>
 public StunMessage(StunMethodType type, StunMethodClass mclass, byte[] transactionId)
 {
     this.MethodType = type;
     this.MethodClass = mclass;
     this.TransactionID = transactionId;
 }