public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }

            if (this.innerEthernetPacket != null)
            {
                yield return(this.innerEthernetPacket);
            }
            else if (this.vxlanNetworkIdentifier >= 0)
            {
                this.innerEthernetPacket = new Ethernet2Packet(base.ParentFrame, base.PacketStartIndex + 8, base.PacketEndIndex);
                yield return(this.innerEthernetPacket);

                foreach (AbstractPacket subPacket in this.innerEthernetPacket.GetSubPackets(false))
                {
                    yield return(subPacket);
                }
            }
            else
            {
                yield break;
            }
        }
Exemplo n.º 2
0
        internal static AbstractPacket GetPacketForType(ushort etherType, Frame parentFrame, int newPacketStartIndex, int newPacketEndIndex)
        {
            AbstractPacket packet;

            try {
                //if(this.ParentFrame.Data[PacketStartIndex+12]==0x08 && this.ParentFrame.Data[PacketStartIndex+13]==0x00) {
                if (etherType == (ushort)Ethernet2Packet.EtherTypes.IPv4 && IPv4Packet.TryParse(parentFrame, newPacketStartIndex, newPacketEndIndex, out packet))
                {
                    //IPv4 packet
                    //packet = new IPv4Packet(parentFrame, newPacketStartIndex, newPacketEndIndex);
                }
                else if (etherType == (ushort)Ethernet2Packet.EtherTypes.IPv6)
                {
                    //IPv6 packet
                    packet = new IPv6Packet(parentFrame, newPacketStartIndex, newPacketEndIndex);
                }
                //else if(this.ParentFrame.Data[PacketStartIndex+12]==0x08 && this.ParentFrame.Data[PacketStartIndex+13]==0x06) {
                else if (etherType == (ushort)Ethernet2Packet.EtherTypes.ARP)
                {
                    packet = new ArpPacket(parentFrame, newPacketStartIndex, newPacketEndIndex);
                    //ARP-packet
                }
                else if (etherType == (ushort)Ethernet2Packet.EtherTypes.IEEE802_1Q)
                {
                    //VLAN
                    packet = new IEEE_802_1Q_VlanPacket(parentFrame, newPacketStartIndex, newPacketEndIndex);
                }
                else if (etherType == (ushort)Ethernet2Packet.EtherTypes.MPLS)
                {
                    packet = new Mpls(parentFrame, newPacketStartIndex, newPacketEndIndex);
                }
                else if (etherType == (ushort)Ethernet2Packet.EtherTypes.PPPoE)
                {
                    packet = new PointToPointOverEthernetPacket(parentFrame, newPacketStartIndex, newPacketEndIndex);
                }
                else if (etherType == (ushort)Ethernet2Packet.EtherTypes.xHayesTunnel)
                {
                    packet = new Ethernet2Packet(parentFrame, newPacketStartIndex + 4, newPacketEndIndex);
                }
                //etherType might actually be a content length if it is an IEEE 802.3 packet
                else if (etherType < 0x0600)
                {
                    //the etherType showed to actually be a length value
                    packet = new LogicalLinkControlPacket(parentFrame, newPacketStartIndex, newPacketEndIndex);
                }

                else
                {
                    //something else
                    packet = new RawPacket(parentFrame, newPacketStartIndex, newPacketEndIndex);
                }
            }
            catch (Exception) {
                packet = new RawPacket(parentFrame, newPacketStartIndex, newPacketEndIndex);
            }
            return(packet);
        }
Exemplo n.º 3
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }
            AbstractPacket packet          = null;
            int            erfHeaderLength = 16;

            if (this.extensionHeadersPresent)
            {
                erfHeaderLength += 4;//correct?
            }
            if (PacketStartIndex + 16 < PacketEndIndex)
            {
                if (type == (byte)RecordTypes.ERF_TYPE_ETH || type == (byte)RecordTypes.ERF_TYPE_COLOR_ETH || type == (byte)RecordTypes.ERF_TYPE_DSM_COLOR_ETH)
                {
                    packet = new Ethernet2Packet(this.ParentFrame, this.PacketStartIndex + erfHeaderLength + 2, this.PacketEndIndex);
                }
                else if (type == (byte)RecordTypes.ERF_TYPE_IPV4)
                {
                    IPv4Packet.TryParse(this.ParentFrame, this.PacketStartIndex + erfHeaderLength, this.PacketEndIndex, out packet);
                    //packet = new IPv4Packet(this.ParentFrame, this.PacketStartIndex + erfHeaderLength, this.PacketEndIndex);
                }
                else if (type == (byte)RecordTypes.ERF_TYPE_IPV6)
                {
                    packet = new IPv6Packet(this.ParentFrame, this.PacketStartIndex + erfHeaderLength, this.PacketEndIndex);
                }
                else if (
                    type == (byte)RecordTypes.ERF_TYPE_HDLC_POS ||
                    type == (byte)RecordTypes.ERF_TYPE_COLOR_HDLC_POS ||
                    type == (byte)RecordTypes.ERF_TYPE_DSM_COLOR_HDLC_POS ||
                    type == (byte)RecordTypes.ERF_TYPE_COLOR_MC_HDLC_POS)
                {
                    int firstByte = this.ParentFrame.Data[this.PacketStartIndex];
                    if (firstByte == 0x0f || firstByte == 0x8f)
                    {
                        packet = new CiscoHdlcPacket(this.ParentFrame, this.PacketStartIndex + erfHeaderLength, this.PacketEndIndex);
                    }
                    else
                    {
                        packet = new PointToPointPacket(this.ParentFrame, this.PacketStartIndex + erfHeaderLength, this.PacketEndIndex);
                    }
                }

                if (packet != null)
                {
                    yield return(packet);

                    foreach (AbstractPacket subPacket in packet.GetSubPackets(false))
                    {
                        yield return(subPacket);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }
            AbstractPacket packet;



            if (this.bottomOfStack)
            {
                /**
                 * EoMPLS = Ethernet over MPLS
                 * http://www.faqs.org/rfcs/rfc4448.html
                 *   0                   1                   2                   3
                 *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                 *  |0 0 0 0|   Reserved            |       Sequence Number         |
                 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                 *
                 *  In the above diagram, the first 4 bits MUST be set to 0 to indicate
                 *  PW data.  The rest of the first 16 bits are reserved for future use.
                 *  They MUST be set to 0 when transmitting, and MUST be ignored upon
                 *  receipt.
                 **/

                if (ParentFrame.Data[PacketStartIndex + PAYLOAD_OFFSET] < 0x10)
                {
                    packet = new Ethernet2Packet(this.ParentFrame, PacketStartIndex + PAYLOAD_OFFSET + 4, PacketEndIndex);
                }
                else if (IPv4Packet.TryParse(this.ParentFrame, PacketStartIndex + PAYLOAD_OFFSET, PacketEndIndex, out packet))
                {
                    //packet = new IPv4Packet(this.ParentFrame, PacketStartIndex + PAYLOAD_OFFSET, PacketEndIndex);
                }
                else
                {
                    yield break;
                }
            }
            else
            {
                packet = new Mpls(this.ParentFrame, PacketStartIndex + PAYLOAD_OFFSET, PacketEndIndex);
            }
            yield return(packet);

            foreach (AbstractPacket subPacket in packet.GetSubPackets(false))
            {
                yield return(subPacket);
            }
        }
Exemplo n.º 5
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }
            AbstractPacket packet = Ethernet2Packet.GetPacketForType(this.etherType, this.ParentFrame, this.PacketStartIndex + PACKET_LENGTH, this.PacketEndIndex);

            yield return(packet);

            foreach (AbstractPacket subPacket in packet.GetSubPackets(false))
            {
                yield return(subPacket);
            }
        }
Exemplo n.º 6
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }
            if (this.nextPacketIndex > 0)
            {
                Ethernet2Packet packet = new Ethernet2Packet(this.ParentFrame, this.nextPacketIndex, this.PacketEndIndex);
                yield return(packet);

                foreach (AbstractPacket subPacket in packet.GetSubPackets(false))
                {
                    yield return(subPacket);
                }
            }
        }