internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header, PPPProtocol Protocol) { // slice off the payload var payload = Header.EncapsulatedBytes(); log.DebugFormat("payload: {0}", payload); var payloadPacketOrData = new PacketOrByteArraySegment(); switch (Protocol) { case PPPProtocol.IPv4: payloadPacketOrData.ThePacket = new IPv4Packet(payload); break; case PPPProtocol.IPv6: payloadPacketOrData.ThePacket = new IPv6Packet(payload); break; default: throw new System.NotImplementedException("Protocol of " + Protocol + " is not implemented"); } return(payloadPacketOrData); }
/// <summary> /// Constructor /// </summary> /// <param name="bas"> /// A <see cref="ByteArraySegment"/> /// </param> public IGMPv2Packet(ByteArraySegment bas) { // set the header field, header field values are retrieved from this byte array header = new ByteArraySegment(bas); header.Length = UdpFields.HeaderLength; // store the payload bytes payloadPacketOrData = new PacketOrByteArraySegment(); payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes(); }
/// <summary> /// Constructor /// </summary> /// <param name="bas"> /// A <see cref="ByteArraySegment"/> /// </param> public ICMPv4Packet(ByteArraySegment bas) { log.Debug(""); header = new ByteArraySegment(bas); header.Length = ICMPv4Fields.HeaderLength; // store the payload bytes payloadPacketOrData = new PacketOrByteArraySegment(); payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes(); }
/// <summary> /// Constructor /// </summary> /// <param name="bas"> /// A <see cref="ByteArraySegment"/> /// </param> public UdpPacket(ByteArraySegment bas) { log.DebugFormat("bas {0}", bas.ToString()); // set the header field, header field values are retrieved from this byte array header = new ByteArraySegment(bas); header.Length = UdpFields.HeaderLength; // store the payload bytes payloadPacketOrData = new PacketOrByteArraySegment(); payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes(); }
internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header) { // slice off the payload var payload = Header.EncapsulatedBytes(); log.DebugFormat("payload {0}", payload.ToString()); var payloadPacketOrData = new PacketOrByteArraySegment(); // we assume that we have a PPPPacket as the payload payloadPacketOrData.ThePacket = new PPPPacket(payload); return(payloadPacketOrData); }
/// <summary> /// Constructor /// </summary> /// <param name="bas"> /// A <see cref="ByteArraySegment"/> /// </param> public TcpPacket(ByteArraySegment bas) { log.Debug(""); // set the header field, header field values are retrieved from this byte array header = new ByteArraySegment(bas); // NOTE: we update the Length field AFTER the header field because // we need the header to be valid to retrieve the value of DataOffset header.Length = DataOffset * 4; // store the payload bytes payloadPacketOrData = new PacketOrByteArraySegment(); payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes(); }
/// <summary> /// Called by IPv4 and IPv6 packets to parse their packet payload /// </summary> /// <param name="payload"> /// A <see cref="ByteArraySegment"/> /// </param> /// <param name="ProtocolType"> /// A <see cref="IPProtocolType"/> /// </param> /// <param name="ParentPacket"> /// A <see cref="Packet"/> /// </param> /// <returns> /// A <see cref="PacketOrByteArraySegment"/> /// </returns> internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment payload, IPProtocolType ProtocolType, Packet ParentPacket) { log.DebugFormat("payload: {0}, ParentPacket.GetType() {1}", payload, ParentPacket.GetType()); var payloadPacketOrData = new PacketOrByteArraySegment(); switch (ProtocolType) { case IPProtocolType.TCP: payloadPacketOrData.ThePacket = new TcpPacket(payload, ParentPacket); break; case IPProtocolType.UDP: payloadPacketOrData.ThePacket = new UdpPacket(payload, ParentPacket); break; case IPProtocolType.ICMP: payloadPacketOrData.ThePacket = new ICMPv4Packet(payload, ParentPacket); break; case IPProtocolType.ICMPV6: payloadPacketOrData.ThePacket = new ICMPv6Packet(payload, ParentPacket); break; case IPProtocolType.IGMP: payloadPacketOrData.ThePacket = new IGMPv2Packet(payload, ParentPacket); break; // NOTE: new payload parsing entries go here default: payloadPacketOrData.TheByteArraySegment = payload; break; } return(payloadPacketOrData); }
/// <summary> /// Used by the EthernetPacket constructor. Located here because the LinuxSLL constructor /// also needs to perform the same operations as it contains an ethernet type /// </summary> /// <param name="Header"> /// A <see cref="ByteArraySegment"/> /// </param> /// <param name="Type"> /// A <see cref="EthernetPacketType"/> /// </param> /// <returns> /// A <see cref="PacketOrByteArraySegment"/> /// </returns> internal static PacketOrByteArraySegment ParseEncapsulatedBytes(ByteArraySegment Header, EthernetPacketType Type) { // slice off the payload var payload = Header.EncapsulatedBytes(); log.DebugFormat("payload {0}", payload.ToString()); var payloadPacketOrData = new PacketOrByteArraySegment(); // parse the encapsulated bytes switch (Type) { case EthernetPacketType.IpV4: payloadPacketOrData.ThePacket = new IPv4Packet(payload); break; case EthernetPacketType.IpV6: payloadPacketOrData.ThePacket = new IPv6Packet(payload); break; case EthernetPacketType.Arp: payloadPacketOrData.ThePacket = new ARPPacket(payload); break; case EthernetPacketType.LLDP: payloadPacketOrData.ThePacket = new LLDPPacket(payload); break; case EthernetPacketType.PointToPointProtocolOverEthernetSessionStage: payloadPacketOrData.ThePacket = new PPPoEPacket(payload); break; default: // consider the sub-packet to be a byte array payloadPacketOrData.TheByteArraySegment = payload; break; } return(payloadPacketOrData); }