public Packet(byte[] data, PacketDirection direction) : base(data) { this.PacketDirection = direction; ArrivalTime = DateTime.Now; EthernetHeader ethernetHeader = new EthernetHeader(data); IpHeader ipHeader = new IpHeader(this, ethernetHeader); this.SourceIpAddress = ipHeader.SourceIpAddress; this.DestinationIpAddress = ipHeader.DestinationIpAddress; this.Protocol = ipHeader.Protocol; this.Data = null; }
/// <summary> /// Parses the data of the raw packet /// </summary> /// <param name="rawPacket">The raw packet (binary data)</param> /// <param name="macHeader">Lower-level information about the packet</param> public IpHeader(RawPacket rawPacket, EthernetHeader macHeader) { int pos = macHeader.Length; Version = (IpVersion)(rawPacket.Data[pos++] >> 4); int protocolOffset = pos + 8; Protocol = (IpProtocol)rawPacket.Data[protocolOffset++]; int sourceOffset = protocolOffset + 2; ipSource = RawPacket.ReadUInt32(rawPacket.Data, sourceOffset); int destinationOffset = sourceOffset + 4; ipDestination = RawPacket.ReadUInt32(rawPacket.Data, destinationOffset); }