示例#1
0
        public void ReadFromBitStream(ReadOnlyBitStream bitStream)
        {
            bool isBigEndian = bitStream.IsBigEndian();

            bitStream.SetBigEndian(true);

            version        = bitStream.ReadNibble();
            headerLength   = bitStream.ReadNibble();
            headerLength  *= 4;
            dsf            = bitStream.ReadByte();
            totalLength    = bitStream.ReadUInt16();
            identifier     = bitStream.ReadUInt16();
            flags          = bitStream.ReadUInt16();
            ttl            = bitStream.ReadByte();
            protocol       = bitStream.ReadByte();
            headerChecksum = bitStream.ReadUInt16();
            source         = bitStream.ReadBytes(4);
            destination    = bitStream.ReadBytes(4);

            bitStream.SetBigEndian(isBigEndian);

            if (protocol == 17)
            {
                datagram = new Datagram();
                datagram.ReadFromBitStream(bitStream);
            }
            else
            {
                bitStream.ReadBytes(totalLength - headerLength); // Skip if not UDP.
            }
        }