Esempio n. 1
0
        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);
        }
Esempio n. 2
0
		/// <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();
		}
Esempio n. 3
0
        /// <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();
        }
Esempio n. 4
0
        /// <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();
        }
Esempio n. 5
0
        /// <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();
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        /// <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();
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        /// <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);
        }
Esempio n. 10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="bas">
        /// A <see cref="ByteArraySegment"/>
        /// </param>
        public Ieee80211MacFrame(ByteArraySegment bas)
        {
            log.Debug("");

            // slice off the header portion as our header
            header = new ByteArraySegment(bas);
            const int defaultLength = 4;

            header.Length = defaultLength;

            FrameControl = new Ieee80211FrameControlField(FrameControlBytes);

            // determine what kind of frame this is based on the type
            if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlRTS)
            {
                InnerFrame = new RTSFrame(this, bas);
            }
            else if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlCTS)
            {
                InnerFrame = new CTSOrACKFrame(this, bas);
            }
            else if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlACK)
            {
                InnerFrame = new CTSOrACKFrame(this, bas);
            }
            else
            {
                throw new System.NotImplementedException("FrameControl.Types of " + FrameControl.Types + " not handled");
            }

            header.Length = InnerFrame.FrameSize;

            // store the payload, less the frame check sequence at the end
            payloadPacketOrData = new PacketOrByteArraySegment();
            payloadPacketOrData.TheByteArraySegment         = header.EncapsulatedBytes();
            payloadPacketOrData.TheByteArraySegment.Length -= Ieee80211MacFields.FrameCheckSequenceLength;
        }