コード例 #1
0
ファイル: STUN_Message.cs プロジェクト: xiaoliukai/VMukti
        public void Parse(byte[] data)
        {
            if (data.Length < 20)
            {
                throw new ArgumentException("Invalid STUN message value !");
            }
            int sourceIndex = 0;
            int num2        = (data[sourceIndex++] << 8) | data[sourceIndex++];

            if (num2 == 0x111)
            {
                this.m_Type = STUN_MessageType.BindingErrorResponse;
            }
            else if (num2 == 1)
            {
                this.m_Type = STUN_MessageType.BindingRequest;
            }
            else if (num2 == 0x101)
            {
                this.m_Type = STUN_MessageType.BindingResponse;
            }
            else if (num2 == 0x112)
            {
                this.m_Type = STUN_MessageType.SharedSecretErrorResponse;
            }
            else if (num2 == 2)
            {
                this.m_Type = STUN_MessageType.SharedSecretRequest;
            }
            else
            {
                if (num2 != 0x102)
                {
                    throw new ArgumentException("Invalid STUN message type value !");
                }
                this.m_Type = STUN_MessageType.SharedSecretResponse;
            }
            int num3 = (data[sourceIndex++] << 8) | data[sourceIndex++];

            byte[] destinationArray = new byte[0x10];
            Array.Copy(data, sourceIndex, destinationArray, 0, 0x10);
            this.m_pTransactionID = new Guid(destinationArray);
            sourceIndex          += 0x10;
            while ((sourceIndex - 20) < num3)
            {
                this.ParseAttribute(data, ref sourceIndex);
            }
        }
コード例 #2
0
 public void Parse(byte[] data)
 {
     if (data.Length < 20)
     {
         throw new ArgumentException("Invalid STUN message value !");
     }
     int sourceIndex = 0;
     int num2 = (data[sourceIndex++] << 8) | data[sourceIndex++];
     if (num2 == 0x111)
     {
         this.m_Type = STUN_MessageType.BindingErrorResponse;
     }
     else if (num2 == 1)
     {
         this.m_Type = STUN_MessageType.BindingRequest;
     }
     else if (num2 == 0x101)
     {
         this.m_Type = STUN_MessageType.BindingResponse;
     }
     else if (num2 == 0x112)
     {
         this.m_Type = STUN_MessageType.SharedSecretErrorResponse;
     }
     else if (num2 == 2)
     {
         this.m_Type = STUN_MessageType.SharedSecretRequest;
     }
     else
     {
         if (num2 != 0x102)
         {
             throw new ArgumentException("Invalid STUN message type value !");
         }
         this.m_Type = STUN_MessageType.SharedSecretResponse;
     }
     int num3 = (data[sourceIndex++] << 8) | data[sourceIndex++];
     byte[] destinationArray = new byte[0x10];
     Array.Copy(data, sourceIndex, destinationArray, 0, 0x10);
     this.m_pTransactionID = new Guid(destinationArray);
     sourceIndex += 0x10;
     while ((sourceIndex - 20) < num3)
     {
         this.ParseAttribute(data, ref sourceIndex);
     }
 }
コード例 #3
0
ファイル: STUN_Message.cs プロジェクト: Nicholi/LumiSoft.Net
        /// <summary>
        /// Parses STUN message from raw data packet.
        /// </summary>
        /// <param name="data">Raw STUN message.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
        public void Parse(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            /* RFC 5389 6.
             *  All STUN messages MUST start with a 20-byte header followed by zero
             *  or more Attributes.  The STUN header contains a STUN message type,
             *  magic cookie, transaction ID, and message length.
             *
             *   0                   1                   2                   3
             *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |0 0|     STUN Message Type     |         Message Length        |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |                         Magic Cookie                          |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |                                                               |
             |                     Transaction ID (96 bits)                  |
             |                                                               |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |
             | The message length is the count, in bytes, of the size of the
             | message, not including the 20 byte header.
             */

            if (data.Length < 20)
            {
                throw new ArgumentException("Invalid STUN message value !");
            }

            int offset = 0;

            //--- message header --------------------------------------------------

            // STUN Message Type
            int messageType = (data[offset++] << 8 | data[offset++]);

            if (messageType == (int)STUN_MessageType.BindingErrorResponse)
            {
                m_Type = STUN_MessageType.BindingErrorResponse;
            }
            else if (messageType == (int)STUN_MessageType.BindingRequest)
            {
                m_Type = STUN_MessageType.BindingRequest;
            }
            else if (messageType == (int)STUN_MessageType.BindingResponse)
            {
                m_Type = STUN_MessageType.BindingResponse;
            }
            else if (messageType == (int)STUN_MessageType.SharedSecretErrorResponse)
            {
                m_Type = STUN_MessageType.SharedSecretErrorResponse;
            }
            else if (messageType == (int)STUN_MessageType.SharedSecretRequest)
            {
                m_Type = STUN_MessageType.SharedSecretRequest;
            }
            else if (messageType == (int)STUN_MessageType.SharedSecretResponse)
            {
                m_Type = STUN_MessageType.SharedSecretResponse;
            }
            else
            {
                throw new ArgumentException("Invalid STUN message type value !");
            }

            // Message Length
            int messageLength = (data[offset++] << 8 | data[offset++]);

            // Magic Cookie
            m_MagicCookie = (data[offset++] << 24 | data[offset++] << 16 | data[offset++] << 8 | data[offset++]);

            // Transaction ID
            m_pTransactionID = new byte[12];
            Array.Copy(data, offset, m_pTransactionID, 0, 12);
            offset += 12;

            //--- Message attributes ---------------------------------------------
            while ((offset - 20) < messageLength)
            {
                ParseAttribute(data, ref offset);
            }
        }
コード例 #4
0
        /// <summary>
        /// Parses STUN message from raw data packet.
        /// </summary>
        /// <param name="data">Raw STUN message.</param>
        public void Parse(byte[] data)
        {
            /* RFC 3489 11.1.
             *  All STUN messages consist of a 20 byte header:
             *
             *  0                   1                   2                   3
             *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |      STUN Message Type        |         Message Length        |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |                          Transaction ID
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |
             | The message length is the count, in bytes, of the size of the
             | message, not including the 20 byte header.
             */

            if (data.Length < 20)
            {
                throw new ArgumentException("Invalid STUN message value !");
            }

            int offset = 0;

            //--- message header --------------------------------------------------

            // STUN Message Type
            int messageType = (data[offset++] << 8 | data[offset++]);

            if (messageType == (int)STUN_MessageType.BindingErrorResponse)
            {
                m_Type = STUN_MessageType.BindingErrorResponse;
            }
            else if (messageType == (int)STUN_MessageType.BindingRequest)
            {
                m_Type = STUN_MessageType.BindingRequest;
            }
            else if (messageType == (int)STUN_MessageType.BindingResponse)
            {
                m_Type = STUN_MessageType.BindingResponse;
            }
            else if (messageType == (int)STUN_MessageType.SharedSecretErrorResponse)
            {
                m_Type = STUN_MessageType.SharedSecretErrorResponse;
            }
            else if (messageType == (int)STUN_MessageType.SharedSecretRequest)
            {
                m_Type = STUN_MessageType.SharedSecretRequest;
            }
            else if (messageType == (int)STUN_MessageType.SharedSecretResponse)
            {
                m_Type = STUN_MessageType.SharedSecretResponse;
            }
            else
            {
                throw new ArgumentException("Invalid STUN message type value !");
            }

            // Message Length
            int messageLength = (data[offset++] << 8 | data[offset++]);

            // Transaction ID
            byte[] guid = new byte[16];
            Array.Copy(data, offset, guid, 0, 16);
            m_pTransactionID = new Guid(guid);
            offset          += 16;

            //--- Message attributes ---------------------------------------------
            while ((offset - 20) < messageLength)
            {
                ParseAttribute(data, ref offset);
            }
        }
コード例 #5
0
        /// <summary>
        /// Parses STUN message from raw data packet.
        /// </summary>
        /// <param name="data">Raw STUN message.</param>
        public void Parse(byte[] data)
        {
            /* RFC 3489 11.1.
                All STUN messages consist of a 20 byte header:

                0                   1                   2                   3
                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
               |      STUN Message Type        |         Message Length        |
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
               |
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                        Transaction ID
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                                                               |
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

               The message length is the count, in bytes, of the size of the
               message, not including the 20 byte header.
            */

            if(data.Length < 20){
                throw new ArgumentException("Invalid STUN message value !");
            }

            int offset = 0;

            //--- message header --------------------------------------------------

            // STUN Message Type
            int messageType = (data[offset++] << 8 | data[offset++]);
            if(messageType == (int)STUN_MessageType.BindingErrorResponse){
                m_Type = STUN_MessageType.BindingErrorResponse;
            }
            else if(messageType == (int)STUN_MessageType.BindingRequest){
                m_Type = STUN_MessageType.BindingRequest;
            }
            else if(messageType == (int)STUN_MessageType.BindingResponse){
                m_Type = STUN_MessageType.BindingResponse;
            }
            else if(messageType == (int)STUN_MessageType.SharedSecretErrorResponse){
                m_Type = STUN_MessageType.SharedSecretErrorResponse;
            }
            else if(messageType == (int)STUN_MessageType.SharedSecretRequest){
                m_Type = STUN_MessageType.SharedSecretRequest;
            }
            else if(messageType == (int)STUN_MessageType.SharedSecretResponse){
                m_Type = STUN_MessageType.SharedSecretResponse;
            }
            else{
                throw new ArgumentException("Invalid STUN message type value !");
            }

            // Message Length
            int messageLength = (data[offset++] << 8 | data[offset++]);

            // Transaction ID
            byte[] guid = new byte[16];
            Array.Copy(data,offset,guid,0,16);
            m_pTransactionID = new Guid(guid);
            offset += 16;

            //--- Message attributes ---------------------------------------------
            while((offset - 20) < messageLength){
                ParseAttribute(data,ref offset);
            }
        }
コード例 #6
0
ファイル: STUN_Message.cs プロジェクト: dioptre/nkd
        /// <summary>
        /// Parses STUN message from raw data packet.
        /// </summary>
        /// <param name="data">Raw STUN message.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
        public void Parse(byte[] data)
        {
            if(data == null){
                throw new ArgumentNullException("data");
            }

            /* RFC 5389 6.             
                All STUN messages MUST start with a 20-byte header followed by zero
                or more Attributes.  The STUN header contains a STUN message type,
                magic cookie, transaction ID, and message length.

                 0                   1                   2                   3
                 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                 |0 0|     STUN Message Type     |         Message Length        |
                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                 |                         Magic Cookie                          |
                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                 |                                                               |
                 |                     Transaction ID (96 bits)                  |
                 |                                                               |
                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
              
               The message length is the count, in bytes, of the size of the
               message, not including the 20 byte header.
            */

            if(data.Length < 20){
                throw new ArgumentException("Invalid STUN message value !");
            }

            int offset = 0;

            //--- message header --------------------------------------------------

            // STUN Message Type
            int messageType = (data[offset++] << 8 | data[offset++]);
            if(messageType == (int)STUN_MessageType.BindingErrorResponse){
                m_Type = STUN_MessageType.BindingErrorResponse;
            }
            else if(messageType == (int)STUN_MessageType.BindingRequest){
                m_Type = STUN_MessageType.BindingRequest;
            }
            else if(messageType == (int)STUN_MessageType.BindingResponse){
                m_Type = STUN_MessageType.BindingResponse;
            }
            else if(messageType == (int)STUN_MessageType.SharedSecretErrorResponse){
                m_Type = STUN_MessageType.SharedSecretErrorResponse;
            }
            else if(messageType == (int)STUN_MessageType.SharedSecretRequest){
                m_Type = STUN_MessageType.SharedSecretRequest;
            }
            else if(messageType == (int)STUN_MessageType.SharedSecretResponse){
                m_Type = STUN_MessageType.SharedSecretResponse;
            }
            else{
                throw new ArgumentException("Invalid STUN message type value !");
            }

            // Message Length
            int messageLength = (data[offset++] << 8 | data[offset++]);

            // Magic Cookie
            m_MagicCookie = (data[offset++] << 24 | data[offset++] << 16 | data[offset++] << 8 | data[offset++]);

            // Transaction ID
            m_pTransactionID = new byte[12];
            Array.Copy(data,offset,m_pTransactionID,0,12);
            offset += 12;

            //--- Message attributes ---------------------------------------------
            while((offset - 20) < messageLength){
                ParseAttribute(data,ref offset);
            }
        }