Ejemplo n.º 1
0
        public static SectionHeader Parse(BinaryReader binaryReader)
        {
            bool reverseByteOrder = false;
            long positionInStream = binaryReader.BaseStream.Position;
            uint tempMagicNumber  = binaryReader.ReadUInt32();

            if (!Enum.IsDefined(typeof(MagicNumbers), tempMagicNumber))
            {
                throw new ArgumentException(string.Format("[SectionHeader.Parse] Unrecognized pcap magic number: {0}", tempMagicNumber.ToString("x")));
            }

            MagicNumbers magicNumber = (MagicNumbers)tempMagicNumber;

            if (magicNumber == MagicNumbers.nanosecondIdentical || magicNumber == MagicNumbers.microsecondIdentical)
            {
                reverseByteOrder = false;
            }
            else
            {
                reverseByteOrder = true;
            }


            ushort major    = binaryReader.ReadUInt16().ReverseByteOrder(reverseByteOrder);
            ushort minor    = binaryReader.ReadUInt16().ReverseByteOrder(reverseByteOrder);
            int    thiszone = binaryReader.ReadInt32().ReverseByteOrder(reverseByteOrder);
            uint   sigfigs  = binaryReader.ReadUInt32().ReverseByteOrder(reverseByteOrder);
            uint   snaplen  = binaryReader.ReadUInt32().ReverseByteOrder(reverseByteOrder);
            uint   linktype = binaryReader.ReadUInt32().ReverseByteOrder(reverseByteOrder);

            if (!Enum.IsDefined(typeof(LinkTypes), (ushort)linktype))
            {
                throw new ArgumentException(string.Format("[SectionHeader.Parse] Invalid LinkTypes: {0}, block begin on position {1} ", linktype, positionInStream));
            }
            LinkTypes     LinkType = (LinkTypes)linktype;
            SectionHeader header   = new SectionHeader(magicNumber, major, minor, thiszone, sigfigs, snaplen, LinkType);

            return(header);
        }
Ejemplo n.º 2
0
 public PcapWriter(Stream stream, SectionHeader header)
 {
     Initialize(stream, header);
 }