public static InterfaceDescriptionBlock Parse(BaseBlock baseBlock, Action <Exception> ActionOnException) { Contract.Requires <ArgumentNullException>(baseBlock != null, "BaseBlock cannot be null"); Contract.Requires <ArgumentNullException>(baseBlock.Body != null, "BaseBlock.Body cannot be null"); Contract.Requires <ArgumentException>(baseBlock.BlockType == BaseBlock.Types.InterfaceDescription, "Invalid packet type"); long positionInStream = baseBlock.PositionInStream; using (Stream stream = new MemoryStream(baseBlock.Body)) { using (BinaryReader binaryReader = new BinaryReader(stream)) { UInt16 linktype = binaryReader.ReadUInt16().ReverseByteOrder(baseBlock.ReverseByteOrder); if (!Enum.IsDefined(typeof(LinkTypes), linktype)) { throw new ArgumentException(string.Format("[InterfaceDescriptionBlock.ctor] invalid LinkTypes: {0}, block begin on position {1} ", linktype, positionInStream)); } LinkTypes linkType = (LinkTypes)linktype; binaryReader.ReadUInt16(); // Reserved field. int snapLength = binaryReader.ReadInt32().ReverseByteOrder(baseBlock.ReverseByteOrder); InterfaceDescriptionOption Options = InterfaceDescriptionOption.Parse(binaryReader, baseBlock.ReverseByteOrder, ActionOnException); InterfaceDescriptionBlock interfaceBlock = new InterfaceDescriptionBlock(linkType, snapLength, Options, positionInStream); return(interfaceBlock); } } }
/// <summary> /// The Interface Description Block is mandatory. This block is needed to specify the characteristics of the network interface /// on which the capture has been made. In order to properly associate the captured data to the corresponding interface, the Interface /// Description Block must be defined before any other block that uses it; therefore, this block is usually placed immediately after /// the Section Header Block. /// </summary> public InterfaceDescriptionBlock(LinkTypes LinkType, int SnapLength, InterfaceDescriptionOption Options, long PositionInStream = 0) { Contract.Requires <ArgumentNullException>(Options != null, "Options cannot be null"); this.LinkType = LinkType; this.SnapLength = SnapLength; this.options = Options; this.PositionInStream = PositionInStream; }
public static InterfaceDescriptionBlock GetEmptyInterfaceDescription(bool reverseBytesOrder) { InterfaceDescriptionOption Options = new InterfaceDescriptionOption(); return(new InterfaceDescriptionBlock(LinkTypes.Ethernet, 65535, Options)); }