internal InterfaceDescriptionBlock()

in Source/Tx.Network/Pcap/PcapNg.cs [414:459]


        internal InterfaceDescriptionBlock(BlockType type, UInt32 length, BinaryReader reader)
            : base(type, length)
        {
            LinkType = (LinkType)reader.ReadUInt16();
            var reserved = reader.ReadUInt16();
            SnapLen = reader.ReadUInt32();
            uint optionsLen = Length - 5 * 4;
            //byte[] options = reader.ReadBytes((int)optionsLen);

            TimeMultiplier = 10; // default value of 10^-6 if the option if_tsresol is not present
            int optionCode;

            while(true) // Options can occur in any order, so we have too loop
            {
                optionCode = reader.ReadInt16();
                int optionLength = reader.ReadInt16();
                if (optionCode == 0)
                    break;

                switch (optionCode)
                {
                    case 2:
                        Name = ReadAsciiOption(reader, optionLength);
                        continue;

                    case 3:
                        Description = ReadAsciiOption(reader, optionLength);
                        continue;

                    case 9:
                        byte[] buffer = ReadBytesOption(reader, 1);
                        byte b = buffer[0];
                        if ((b & 0x80) == 0)
                            TimeMultiplier = (long)(10E6 / Math.Pow(10, b));
                        else
                            TimeMultiplier = (long)(10E6 / Math.Pow(2, b));
                        continue;

                    default: // This is some unsupported option, but we still havo to read to skip it
                        ReadBytesOption(reader, optionLength);
                        continue;
                }
            } 

           ReadEndOfPacket(reader);
        }