/// <summary>
 /// Creates a new instance of this class
 /// </summary>
 public OSPFCommonHeader()
 {
     bVersion        = 2;
     tType           = OSPFFrameType.Hello;
     iRouterID       = 0;
     iAreaID         = 0;
     oAuthType       = OSPFAuthenticationType.NoAuthentication;
     bAuthentication = new byte[8];
     bAttachedData   = new byte[0];
 }
        /// <summary>
        /// Creates a new instance of this class by parsing the given data.
        /// The corresponding sub-frames (Database description, Hello message etc.) will
        /// automatically instanced and placed into this frames encapsulated frame property.
        /// </summary>
        /// <param name="bData">The data to parse</param>
        public OSPFCommonHeader(byte[] bData)
        {
            bVersion = bData[0];
            tType    = (OSPFFrameType)bData[1];
            int iLen = ((int)bData[2] << 8) + bData[3];

            iRouterID = ((uint)bData[4] << 24) + ((uint)bData[5] << 16) + ((uint)bData[6] << 8) + bData[7];
            iAreaID   = ((uint)bData[8] << 24) + ((uint)bData[9] << 16) + ((uint)bData[10] << 8) + bData[11];
            // 2 byte checksum pad
            oAuthType       = (OSPFAuthenticationType)(((int)bData[14] << 8) + bData[15]);
            bAuthentication = new byte[8];
            for (int iC1 = 16; iC1 < 24; iC1++)
            {
                bAuthentication[iC1 - 16] = bData[iC1];
            }

            byte[] bEncFrameBytes = new byte[iLen - 24];

            for (int iC1 = 24; iC1 < iLen; iC1++)
            {
                bEncFrameBytes[iC1 - 24] = bData[iC1];
            }

            switch (tType)
            {
            case OSPFFrameType.DatabaseDescription: this.fEncapsulatedFrame = new OSPFDatabaseDescriptionMessage(bEncFrameBytes);
                break;

            case OSPFFrameType.Hello: this.fEncapsulatedFrame = new OSPFHelloMessage(bEncFrameBytes);
                break;

            case OSPFFrameType.LinkStateAcknowledgement: this.fEncapsulatedFrame = new OSPFLSAAcknowledgementMessage(bEncFrameBytes);
                break;

            case OSPFFrameType.LinkStateUpdate: this.fEncapsulatedFrame = new OSPFLSAUpdateMessage(bEncFrameBytes);
                break;

            case OSPFFrameType.LinkStateRequest: this.fEncapsulatedFrame = new OSPFLSARequestMessage(bEncFrameBytes);
                break;

            default: this.fEncapsulatedFrame = new RawDataFrame(bEncFrameBytes);
                break;
            }

            bAttachedData = new byte[bData.Length - iLen];
            for (int iC1 = iLen; iC1 < bData.Length; iC1++)
            {
                bAttachedData[iC1 - iLen] = bData[iC1];
            }
        }