Example #1
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);
        }
Example #2
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            //same as for Ethernet2Packet.cs

            if (includeSelfReference)
            {
                yield return(this);
            }
            if (PacketStartIndex + 16 < PacketEndIndex)
            {
                AbstractPacket packet;
                if (this.protocol == (ushort)Ethernet2Packet.EtherTypes.IPv4 && IPv4Packet.TryParse(this.ParentFrame, PacketStartIndex + 16, PacketEndIndex, out packet))
                {
                    //IPv4 packet
                    //packet=new IPv4Packet(this.ParentFrame, PacketStartIndex+16, PacketEndIndex);
                }
                else if (this.protocol == (ushort)Ethernet2Packet.EtherTypes.IPv6)
                {
                    //IPv6 packet
                    packet = new IPv6Packet(this.ParentFrame, PacketStartIndex + 16, PacketEndIndex);
                }
                //else if(this.ParentFrame.Data[PacketStartIndex+12]==0x08 && this.ParentFrame.Data[PacketStartIndex+13]==0x06) {
                else if (this.protocol == (ushort)Ethernet2Packet.EtherTypes.ARP)
                {
                    packet = new ArpPacket(this.ParentFrame, PacketStartIndex + 16, PacketEndIndex);
                    //ARP-packet
                }
                else if (this.protocol == (ushort)Ethernet2Packet.EtherTypes.IEEE802_1Q)
                {
                    //VLAN
                    packet = new IEEE_802_1Q_VlanPacket(this.ParentFrame, PacketStartIndex + 16, PacketEndIndex);
                }
                else if (this.protocol == (ushort)Ethernet2Packet.EtherTypes.PPPoE)
                {
                    packet = new PointToPointOverEthernetPacket(this.ParentFrame, PacketStartIndex + 16, PacketEndIndex);
                }
                //etherType might actually be a content length if it is an IEEE 802.3 packet
                else if (this.protocol < 0x0600)
                {
                    //the etherType showed to actually be a length value
                    packet = new LogicalLinkControlPacket(this.ParentFrame, PacketStartIndex + 16, PacketEndIndex);
                }
                else
                {
                    //something else
                    packet = new RawPacket(this.ParentFrame, PacketStartIndex + 16, PacketEndIndex);
                }
                yield return(packet);

                foreach (AbstractPacket subPacket in packet.GetSubPackets(false))
                {
                    yield return(subPacket);
                }
            }
        }
Example #3
0
        public override IEnumerable <AbstractPacket> GetSubPackets(bool includeSelfReference)
        {
            if (includeSelfReference)
            {
                yield return(this);
            }

            //int crcLength=4;
            int crcLength = 0;

            //The CRC is often not in the sniffed frame/packet

            if (PacketStartIndex + dataOffsetByteCount < PacketEndIndex - crcLength)
            {
                //so how do I know what's inside this 802.11 packet?
                AbstractPacket packet;

                try {
                    //Logical-Link Control (LLC) maybe?
                    if (frameControl.Type == 2)//Data Frame
                    {
                        packet = new LogicalLinkControlPacket(ParentFrame, PacketStartIndex + dataOffsetByteCount, PacketEndIndex - crcLength);
                        //packet=new RawPacket(ParentFrame, PacketStartIndex+dataOffsetByteCount, PacketEndIndex);
                    }

                    //Or IEEE 802.11 wireless LAN management frame?
                    else if (frameControl.Type == 0)
                    {
                        //todo: add parser for IEEE 802.11 wireless LAN management frame
                        packet = new RawPacket(ParentFrame, PacketStartIndex + dataOffsetByteCount, PacketEndIndex - crcLength);
                    }

                    //Or something else?
                    else
                    {
                        packet = new RawPacket(ParentFrame, PacketStartIndex + dataOffsetByteCount, PacketEndIndex - crcLength);
                    }
                }
                catch (Exception e) {
                    SharedUtils.Logger.Log("Exception when parsing inner packet of 802.11: " + e.Message, SharedUtils.Logger.EventLogEntryType.Error);
                    packet = new RawPacket(ParentFrame, PacketStartIndex + dataOffsetByteCount, PacketEndIndex - crcLength);
                }
                yield return(packet);

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

            //throw new Exception("The method or operation is not implemented.");
        }